diff --git a/modules/imdb/backend.py b/modules/imdb/backend.py index 06620644..5802d61a 100644 --- a/modules/imdb/backend.py +++ b/modules/imdb/backend.py @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . -from weboob.capabilities.cinema import ICapCinema +from weboob.capabilities.cinema import ICapCinema, Person from weboob.tools.backend import BaseBackend from .browser import ImdbBrowser @@ -76,8 +76,11 @@ class ImdbBackend(BaseBackend, ICapCinema): or 'birth_date' in fields\ or 'gender' in fields or fields == None: return self.get_person(person.id) - else: - return person + + if 'biography' in fields: + person.biography = self.get_person_biography(person.id) + + return person def fill_movie(self, movie, fields): if 'other_titles' in fields or 'release_date' in fields\ @@ -87,3 +90,7 @@ class ImdbBackend(BaseBackend, ICapCinema): return self.get_movie(movie.id) else: return movie + + OBJECTS = { + Person:fill_person + } diff --git a/modules/parolesmusique/backend.py b/modules/parolesmusique/backend.py index c564989e..c80ab7b4 100644 --- a/modules/parolesmusique/backend.py +++ b/modules/parolesmusique/backend.py @@ -22,8 +22,6 @@ from weboob.tools.backend import BaseBackend from .browser import ParolesmusiqueBrowser -from urllib import quote_plus - __all__ = ['ParolesmusiqueBackend'] diff --git a/weboob/applications/cineoob/cineoob.py b/weboob/applications/cineoob/cineoob.py index 49695301..e684382c 100644 --- a/weboob/applications/cineoob/cineoob.py +++ b/weboob/applications/cineoob/cineoob.py @@ -24,12 +24,13 @@ from datetime import datetime from weboob.applications.weboorrents.weboorrents import TorrentInfoFormatter, TorrentListFormatter from weboob.applications.suboob.suboob import SubtitleInfoFormatter, SubtitleListFormatter -from weboob.capabilities.torrent import ICapTorrent +from weboob.capabilities.torrent import ICapTorrent, MagnetOnly from weboob.capabilities.cinema import ICapCinema from weboob.capabilities.subtitle import ICapSubtitle from weboob.capabilities.base import NotAvailable,NotLoaded from weboob.tools.application.repl import ReplApplication from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter +from weboob.core import CallErrors __all__ = ['Cineoob'] @@ -142,6 +143,17 @@ class PersonListFormatter(PrettyFormatter): return result +class PersonBiographyFormatter(PrettyFormatter): + MANDATORY_FIELDS = ('id', 'name', 'biography') + + def get_title(self, obj): + return u'Biography of %s'%obj.name + + def get_description(self, obj): + result = obj.biography + return result + + class Cineoob(ReplApplication): APPNAME = 'cineoob' VERSION = '0.f' @@ -155,6 +167,7 @@ class Cineoob(ReplApplication): 'movie_info': MovieInfoFormatter, 'person_list': PersonListFormatter, 'person_info': PersonInfoFormatter, + 'person_bio': PersonBiographyFormatter, 'torrent_list': TorrentListFormatter, 'torrent_info': TorrentInfoFormatter, 'subtitle_list': SubtitleListFormatter, @@ -166,6 +179,7 @@ class Cineoob(ReplApplication): 'info_person': 'person_info', 'casting': 'person_list', 'filmography': 'movie_list', + 'biography': 'person_bio', 'movies_in_common':'movie_list', 'persons_in_common':'person_list', 'search_torrent': 'torrent_list', @@ -291,7 +305,7 @@ class Cineoob(ReplApplication): Get information about a person. """ # TODO understand core to get a call to Backend.fill_person when get_object is called - #person = self.get_object(id, 'get_person',None) + #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, caps=ICapCinema): @@ -303,8 +317,6 @@ class Cineoob(ReplApplication): 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() @@ -381,15 +393,24 @@ class Cineoob(ReplApplication): Show the complete biography of a person. """ - person = self.get_object(person_id, 'get_person') + # TODO understand how to handle short id trying to be get by wrong backends and validate this line ! + # in other words, find a way to select CAP when 'get_object' to avoid useless errors and clarify the following code + #person = self.get_object(person_id,'get_person',('name','biography')) + + person = None + _id, backend = self.parse_id(person_id) + for _backend, result in self.do('get_person', _id, backends=backend, caps=ICapCinema): + if result: + backend = _backend + person = result if not person: - print >>sys.stderr, 'Person not found: %s' % id + print >>sys.stderr, 'Person not found: %s' % _id return 3 - for backend, bio in self.do('get_person_biography', person.id, caps=ICapCinema): - print '%s :\n\n%s' % (person.name,bio) - if bio != NotAvailable: - self.flush() + backend.fillobj(person,('biography')) + self.start_format() + self.format(person) + self.flush() def complete_releases(self, text, line, *ignored): args = line.split(' ') diff --git a/weboob/capabilities/cinema.py b/weboob/capabilities/cinema.py index 4bd1ff57..269325ef 100644 --- a/weboob/capabilities/cinema.py +++ b/weboob/capabilities/cinema.py @@ -47,16 +47,17 @@ class Person(CapBaseObject): """ Person object. """ - name = StringField('Star name of a person') - real_name = StringField('Real name of a person') - birth_date = DateField('Birth date of a person') - death_date = DateField('Death date of a person') - birth_place = StringField('City and country of birth of a person') - gender = StringField('Gender of a person') - nationality = StringField('Nationality of a person') - short_biography = StringField('Short biography of a person') - short_description = StringField('Short description of a person') - roles = Field('Lists of movies related to the person indexed by roles',dict) + name = StringField('Star name of a person') + real_name = StringField('Real name of a person') + birth_date = DateField('Birth date of a person') + death_date = DateField('Death date of a person') + birth_place = StringField('City and country of birth of a person') + gender = StringField('Gender of a person') + nationality = StringField('Nationality of a person') + short_biography = StringField('Short biography of a person') + biography = StringField('Full biography of a person') + short_description= StringField('Short description of a person') + roles = Field('Lists of movies related to the person indexed by roles',dict) def __init__(self, id, name): CapBaseObject.__init__(self, id) @@ -156,3 +157,13 @@ class ICapCinema(IBaseCap): :rtype: iter[str] """ raise NotImplementedError() + + def get_person_biography(self, id): + """ + Get the person full biography. + + :param _id: ID of person + :type _id: str + :rtype: str + """ + raise NotImplementedError()