imdb and cineoob in progress

This commit is contained in:
Julien Veyssier 2013-03-04 04:07:12 +01:00
commit 3492dbb9d6
8 changed files with 334 additions and 16 deletions

View file

@ -23,6 +23,7 @@ import sys
from datetime import datetime
from weboob.capabilities.cinema import ICapCinema
from weboob.capabilities.base import NotAvailable
from weboob.tools.application.repl import ReplApplication
from weboob.tools.application.formatters.iformatter import IFormatter, PrettyFormatter
@ -38,7 +39,7 @@ class MovieInfoFormatter(IFormatter):
result += 'ID: %s\n' % obj.fullid
result += 'Other titles: %s\n' % obj.other_titles
result += 'Released: %s\n' % obj.release_date
result += 'Duration: %d\n' % obj.duration
result += 'Duration: %s\n' % obj.duration
result += 'Note: %s\n' % obj.note
if obj.roles:
result += '\n%sRelated persons%s\n' % (self.BOLD, self.NC)
@ -62,7 +63,7 @@ class MovieListFormatter(PrettyFormatter):
return obj.original_title
def get_description(self, obj):
return 'Released: %s (note: %d, duration: %d)' % (obj.release_date, obj.note, obj.duration)
return 'Released: %s (note: %s, duration: %s)' % (obj.release_date, obj.note, obj.duration)
def yearsago(years, from_date=None):
if from_date is None:
@ -94,7 +95,7 @@ class PersonInfoFormatter(IFormatter):
result += 'Birth date: %s\n' % obj.birth_date
age = num_years(obj.birth_date)
result += 'Age: %s\n' % age
result += 'Birth place: %d\n' % obj.birth_place
result += 'Birth place: %s\n' % obj.birth_place
result += 'Gender: %s\n' % obj.gender
result += 'Nationality: %s\n' % obj.nationality
if obj.roles:
@ -107,7 +108,7 @@ class PersonInfoFormatter(IFormatter):
result += '\n%sAwards%s\n' % (self.BOLD, self.NC)
for a in obj.awards:
result += ' * %s\n' % a
result += '\n%Biography%s\n' % (self.BOLD, self.NC)
result += '\n%sBiography%s\n' % (self.BOLD, self.NC)
result += obj.biography
return result
@ -119,8 +120,11 @@ class PersonListFormatter(PrettyFormatter):
return obj.name
def get_description(self, obj):
age = num_years(obj.birth_date)
return 'Real name: %s (age: %d, nationality: %s, gender: %s)' % (obj.real_name, age, obj.nationality, obj.gender)
if obj.birth_date != NotAvailable:
age = num_years(obj.birth_date)
else:
age = NotAvailable
return 'Real name: %s (age: %s, nationality: %s, gender: %s)' % (obj.real_name, age, obj.nationality, obj.gender)
class Cineoob(ReplApplication):
@ -155,7 +159,7 @@ class Cineoob(ReplApplication):
Get information about a movie.
"""
# TODO verify if path = search movie or filmo
movie = self.get_object(id, 'get_movie')
if not movie:
print >>sys.stderr, 'Movie not found: %s' % id
@ -171,7 +175,7 @@ class Cineoob(ReplApplication):
Get information about a person.
"""
# TODO verify if path = search person or casting
person = self.get_object(id, 'get_person')
if not person:
print >>sys.stderr, 'Person not found: %s' % id
@ -217,8 +221,13 @@ class Cineoob(ReplApplication):
List persons related to a movie.
"""
movie = self.get_object(movie_id, 'get_movie')
if not movie:
print >>sys.stderr, 'Movie not found: %s' % id
return 3
self.change_path([u'casting'])
for backend, person in self.do('iter_movie_persons', movie_id):
for backend, person in self.do('iter_movie_persons', movie.id):
self.cached_format(person)
self.flush()
@ -228,7 +237,12 @@ class Cineoob(ReplApplication):
List movies of a person.
"""
person = self.get_object(person_id, 'get_person')
if not person:
print >>sys.stderr, 'Person not found: %s' % id
return 3
self.change_path([u'filmography'])
for backend, movie in self.do('iter_person_movies', person_id):
for backend, movie in self.do('iter_person_movies', person.id):
self.cached_format(movie)
self.flush()

View file

@ -30,7 +30,7 @@ from weboob.tools.ordereddict import OrderedDict
__all__ = ['UserError', 'FieldNotFound', 'NotAvailable',
'NotLoaded', 'IBaseCap', 'Field', 'IntField', 'DecimalField',
'FloatField', 'StringField', 'BytesField', 'DateField',
'DeltaField', 'HashTableField', 'empty', 'CapBaseObject']
'DeltaField', 'empty', 'CapBaseObject']
def empty(value):

View file

@ -18,7 +18,7 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .base import IBaseCap, CapBaseObject, DateField, StringField, IntField, HashTableField
from .base import IBaseCap, CapBaseObject, DateField, StringField, IntField, Field
__all__ = ['Movie', 'Person', 'ICapCinema']
@ -34,8 +34,8 @@ class Movie(CapBaseObject):
duration = IntField('Duration of the movie in minutes')
description = StringField('Short description of the movie')
note = StringField('Notation of the movie')
awards = StringField('Awards won by the movie')
roles = HashTableField('Lists of Persons related to the movie indexed by roles')
awards = Field('Awards won by the movie',list)
roles = Field('Lists of Persons related to the movie indexed by roles',dict)
def __init__(self, id, original_title):
CapBaseObject.__init__(self, id)
@ -53,8 +53,8 @@ class Person(CapBaseObject):
gender = StringField('Gender of a person')
nationality = StringField('Nationality of a person')
biography = StringField('Short biography of a person')
awards = StringField('Awards won by the person')
roles = HashTableField('Lists of movies related to the person indexed by roles')
awards = Field('Awards won by the person',list)
roles = Field('Lists of movies related to the person indexed by roles',dict)
def __init__(self, id, name):
CapBaseObject.__init__(self, id)