[cineoob] fillobj almost handled

This commit is contained in:
Julien Veyssier 2013-03-06 17:59:47 +01:00
commit 3f4aa98fff
4 changed files with 81 additions and 20 deletions

View file

@ -65,3 +65,22 @@ class ImdbBackend(BaseBackend, ICapCinema):
def get_person_biography(self,id):
return self.browser.get_person_biography(id)
def fill_person(self, person, fields):
if 'real_name' in fields or 'birth_place' in fields\
or 'death_date' in fields or 'nationality' in fields\
or 'short_biography' in fields or 'roles' in fields\
or 'birth_date' in fields\
or 'gender' in fields or fields == None:
return self.get_person(person.id)
else:
return person
def fill_movie(self, movie, fields):
if 'other_titles' in fields or 'release_date' in fields\
or 'duration' in fields or 'description' in fields\
or 'country' in fields or 'roles' in fields\
or 'note' in fields or fields == None:
return self.get_movie(movie.id)
else:
return movie

View file

@ -19,8 +19,8 @@
from weboob.tools.browser import BaseBrowser
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.cinema import Movie
from weboob.capabilities.base import NotAvailable, NotLoaded
from weboob.capabilities.cinema import Movie, Person
from weboob.tools.json import json
from .pages import MoviePage, PersonPage, MovieCrewPage, BiographyPage, FilmographyPage
@ -49,9 +49,16 @@ class ImdbBrowser(BaseBrowser):
for cat in ['title_popular','title_exact','title_approx']:
if jres.has_key(cat):
for m in jres[cat]:
movie = self.get_movie(m['id'])
if movie != None:
yield movie
#movie = self.get_movie(m['id'])
movie = Movie(m['id'],unicode(m['title']))
movie.other_titles = NotLoaded
movie.release_date = NotLoaded
movie.duration = NotLoaded
movie.description = NotLoaded
movie.country = NotLoaded
movie.note = NotLoaded
movie.roles = NotLoaded
yield movie
def iter_persons(self, pattern):
res = self.readurl('http://www.imdb.com/xml/find?json=1&nr=1&nm=on&q=%s' % pattern.encode('utf-8'))
@ -59,7 +66,17 @@ class ImdbBrowser(BaseBrowser):
for cat in ['name_popular','name_exact','name_approx']:
if jres.has_key(cat):
for p in jres[cat]:
yield self.get_person(p['id'])
#person = self.get_person(p['id'])
person = Person(p['id'],p['name'])
person.real_name = NotLoaded
person.birth_place = NotLoaded
person.birth_date = NotLoaded
person.death_date = NotLoaded
person.gender = NotLoaded
person.nationality = NotLoaded
person.short_biography= NotLoaded
person.roles = NotLoaded
yield person
def get_movie(self, id):
res = self.readurl('http://imdbapi.org/?id=%s&type=json&plot=simple&episode=1&lang=en-US&aka=full&release=simple&business=0&tech=0' % id )

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.capabilities.cinema import Person
from weboob.capabilities.cinema import Person, Movie
from weboob.capabilities.base import NotAvailable
from weboob.tools.browser import BasePage
@ -70,7 +70,10 @@ class MovieCrewPage(BasePage):
tds = self.parser.select(table,'td.nm')
for td in tds:
id = td.find('a').attrib.get('href','').strip('/').split('/')[-1]
yield self.browser.get_person(id)
name = td.find('a').text
#yield self.browser.get_person(id)
person = Person(id,name)
yield person
for gloss_link in self.parser.select(self.document.getroot(),'table[cellspacing=1] h5 a'):
role = gloss_link.attrib.get('name','').rstrip('s')
@ -81,7 +84,10 @@ class MovieCrewPage(BasePage):
href = a.attrib.get('href','')
if '/name/nm' in href:
id = href.strip('/').split('/')[-1]
yield self.browser.get_person(id)
name = a.text
person = Person(id,name)
yield person
#yield self.browser.get_person(id)
def iter_persons_ids(self):
tables = self.parser.select(self.document.getroot(),'table.cast')
@ -190,6 +196,7 @@ class FilmographyPage(BasePage):
for a in self.parser.select(role_div,'ol > li > a'):
id = a.attrib.get('href','').strip('/').split('/')[-1]
if id.startswith('tt'):
movie = self.browser.get_movie(id)
if movie != None:
yield movie
title = a.text
#movie = self.browser.get_movie(id)
movie = Movie(id,title)
yield movie

View file

@ -23,7 +23,7 @@ import sys
from datetime import datetime
from weboob.capabilities.cinema import ICapCinema
from weboob.capabilities.base import NotAvailable
from weboob.capabilities.base import NotAvailable, NotLoaded
from weboob.tools.application.repl import ReplApplication
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
@ -67,13 +67,13 @@ class MovieListFormatter(PrettyFormatter):
def get_description(self, obj):
date_str = ''
if obj.release_date != NotAvailable:
if obj.release_date != NotAvailable and obj.release_date != NotLoaded:
date_str = 'released: %s, '%obj.release_date.strftime('%Y-%m-%d')
duration = ''
if obj.duration != NotAvailable:
if obj.duration != NotAvailable and obj.duration != NotLoaded:
duration = 'duration: %smin, '%obj.duration
note = ''
if obj.note != NotAvailable:
if obj.note != NotAvailable and obj.note != NotLoaded:
note = 'note: %s, '%obj.note
return ('%s %s %s' % (date_str, note, duration)).strip(', ')
@ -263,12 +263,21 @@ class Cineoob(ReplApplication):
Get information about a movie.
"""
# TODO verify if path = search movie or filmo
movie = self.get_object(id, 'get_movie')
# TODO correct core to call fillobj when get_object is called
#movie = self.get_object(id, 'get_movie',['duration'])
movie = None
_id, backend = self.parse_id(id)
for _backend, result in self.do('get_movie', _id, backends=backend):
if result:
backend = _backend
movie = result
if not movie:
print >>sys.stderr, 'Movie not found: %s' % id
return 3
backend.fillobj(movie, ('description','duration'))
self.start_format()
self.format(movie)
self.flush()
@ -279,12 +288,21 @@ class Cineoob(ReplApplication):
Get information about a person.
"""
# TODO verify if path = search person or casting
person = self.get_object(id, 'get_person')
# TODO correct core to call fillobj when get_object is called
#person = self.get_object(id, 'get_person')
person = None
_id, backend = self.parse_id(id)
for _backend, result in self.do('get_person', _id, backends=backend):
if result:
backend = _backend
person = result
if not person:
print >>sys.stderr, 'Person not found: %s' % id
return 3
backend.fillobj(person, ('birth_date','short_biography'))
self.start_format()
self.format(person)
self.flush()