From 8e796cc5c3b9e8a41fa54474665693d68d0ee9d5 Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Sat, 9 Mar 2013 03:50:32 +0100 Subject: [PATCH] [cineoob] releases command improved --- modules/imdb/backend.py | 8 +++--- weboob/applications/cineoob/cineoob.py | 36 +++++++++++++++++++++----- weboob/capabilities/cinema.py | 1 + 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/modules/imdb/backend.py b/modules/imdb/backend.py index 5802d61a..49a4e27d 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, Person +from weboob.capabilities.cinema import ICapCinema, Person, Movie from weboob.tools.backend import BaseBackend from .browser import ImdbBrowser @@ -88,9 +88,9 @@ class ImdbBackend(BaseBackend, ICapCinema): or 'roles' in fields or 'note' in fields\ or fields == None: return self.get_movie(movie.id) - else: - return movie + return movie OBJECTS = { - Person:fill_person + Person:fill_person, + Movie:fill_movie } diff --git a/weboob/applications/cineoob/cineoob.py b/weboob/applications/cineoob/cineoob.py index e684382c..f185ec9f 100644 --- a/weboob/applications/cineoob/cineoob.py +++ b/weboob/applications/cineoob/cineoob.py @@ -76,6 +76,17 @@ class MovieListFormatter(PrettyFormatter): result = obj.short_description return result + +class MovieReleasesFormatter(PrettyFormatter): + MANDATORY_FIELDS = ('id', 'original_title', 'all_release_dates') + + def get_title(self, obj): + return u'Releases of %s'%obj.original_title + + def get_description(self, obj): + return u'\n%s'%obj.all_release_dates + + def yearsago(years, from_date=None): if from_date is None: from_date = datetime.now() @@ -150,7 +161,7 @@ class PersonBiographyFormatter(PrettyFormatter): return u'Biography of %s'%obj.name def get_description(self, obj): - result = obj.biography + result = u'\n%s'%obj.biography return result @@ -165,6 +176,7 @@ class Cineoob(ReplApplication): CAPS = (ICapCinema,ICapTorrent,ICapSubtitle) EXTRA_FORMATTERS = {'movie_list': MovieListFormatter, 'movie_info': MovieInfoFormatter, + 'movie_releases': MovieReleasesFormatter, 'person_list': PersonListFormatter, 'person_info': PersonInfoFormatter, 'person_bio': PersonBiographyFormatter, @@ -180,6 +192,7 @@ class Cineoob(ReplApplication): 'casting': 'person_list', 'filmography': 'movie_list', 'biography': 'person_bio', + 'releases': 'movie_releases', 'movies_in_common':'movie_list', 'persons_in_common':'person_list', 'search_torrent': 'torrent_list', @@ -425,17 +438,28 @@ class Cineoob(ReplApplication): If COUNTRY is given, show release in this country. """ id, country = self.parse_command_args(line, 2, 1) - # TODO try without getting object - movie = self.get_object(id, 'get_movie') + + movie = None + _id, backend = self.parse_id(id) + for _backend, result in self.do('get_movie', _id, backends=backend, caps=ICapCinema): + if result: + backend = _backend + movie = result if not movie: print >>sys.stderr, 'Movie not found: %s' % id return 3 + # i would like to clarify with fillobj but how could i fill the movie AND choose the country ? for backend, release in self.do('get_movie_releases', movie.id, country, caps=ICapCinema): - print '%s :\n\n%s' % (movie.original_title,release) - if release != NotAvailable: - self.flush() + if release != NotAvailable: + movie.all_release_dates = u'%s' % (release) + else: + print >>sys.stderr, 'Movie releases not found: %s' % id + return 3 + self.start_format() + self.format(movie) + self.flush() #================== TORRENT ================== diff --git a/weboob/capabilities/cinema.py b/weboob/capabilities/cinema.py index 269325ef..4abbe070 100644 --- a/weboob/capabilities/cinema.py +++ b/weboob/capabilities/cinema.py @@ -31,6 +31,7 @@ class Movie(CapBaseObject): original_title = StringField('Original title of the movie') other_titles = Field('Titles in other countries',list) release_date = DateField('Release date of the movie') + all_release_dates= StringField('Release dates list of the movie') duration = IntField('Duration of the movie in minutes') short_description= StringField('Short description of the movie') pitch = StringField('Short story description of the movie')