[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): def get_person_biography(self,id):
return self.browser.get_person_biography(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.tools.browser import BaseBrowser
from weboob.capabilities.base import NotAvailable from weboob.capabilities.base import NotAvailable, NotLoaded
from weboob.capabilities.cinema import Movie from weboob.capabilities.cinema import Movie, Person
from weboob.tools.json import json from weboob.tools.json import json
from .pages import MoviePage, PersonPage, MovieCrewPage, BiographyPage, FilmographyPage from .pages import MoviePage, PersonPage, MovieCrewPage, BiographyPage, FilmographyPage
@ -49,8 +49,15 @@ class ImdbBrowser(BaseBrowser):
for cat in ['title_popular','title_exact','title_approx']: for cat in ['title_popular','title_exact','title_approx']:
if jres.has_key(cat): if jres.has_key(cat):
for m in jres[cat]: for m in jres[cat]:
movie = self.get_movie(m['id']) #movie = self.get_movie(m['id'])
if movie != None: 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 yield movie
def iter_persons(self, pattern): def iter_persons(self, pattern):
@ -59,7 +66,17 @@ class ImdbBrowser(BaseBrowser):
for cat in ['name_popular','name_exact','name_approx']: for cat in ['name_popular','name_exact','name_approx']:
if jres.has_key(cat): if jres.has_key(cat):
for p in jres[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): 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 ) 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/>. # 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.capabilities.base import NotAvailable
from weboob.tools.browser import BasePage from weboob.tools.browser import BasePage
@ -70,7 +70,10 @@ class MovieCrewPage(BasePage):
tds = self.parser.select(table,'td.nm') tds = self.parser.select(table,'td.nm')
for td in tds: for td in tds:
id = td.find('a').attrib.get('href','').strip('/').split('/')[-1] 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'): for gloss_link in self.parser.select(self.document.getroot(),'table[cellspacing=1] h5 a'):
role = gloss_link.attrib.get('name','').rstrip('s') role = gloss_link.attrib.get('name','').rstrip('s')
@ -81,7 +84,10 @@ class MovieCrewPage(BasePage):
href = a.attrib.get('href','') href = a.attrib.get('href','')
if '/name/nm' in href: if '/name/nm' in href:
id = href.strip('/').split('/')[-1] 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): def iter_persons_ids(self):
tables = self.parser.select(self.document.getroot(),'table.cast') 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'): for a in self.parser.select(role_div,'ol > li > a'):
id = a.attrib.get('href','').strip('/').split('/')[-1] id = a.attrib.get('href','').strip('/').split('/')[-1]
if id.startswith('tt'): if id.startswith('tt'):
movie = self.browser.get_movie(id) title = a.text
if movie != None: #movie = self.browser.get_movie(id)
movie = Movie(id,title)
yield movie yield movie

View file

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