cineoob and imdb corrections

This commit is contained in:
Julien Veyssier 2013-03-04 13:57:22 +01:00
commit 4651aed18c
3 changed files with 17 additions and 63 deletions

View file

@ -72,7 +72,7 @@ class ImdbBrowser(BaseBrowser):
title = jres['title']
if jres.has_key('runtime'):
duration = int(jres['runtime'][0].split()[0])
duration = int(jres['runtime'][0].split(':')[-1].split()[0])
if jres.has_key('also_known_as'):
for other_t in jres['also_known_as']:
if other_t.has_key('country') and other_t.has_key('title'):
@ -102,7 +102,6 @@ class ImdbBrowser(BaseBrowser):
if jres.has_key('%ss'%r):
roles['%s'%r] = list(jres['%ss'%r])
movie = Movie(id,title.strip())
movie.other_titles = other_titles
movie.release_date = release_date
@ -113,11 +112,6 @@ class ImdbBrowser(BaseBrowser):
movie.roles = roles
return movie
#self.location('http://www.imdb.com/title/%s' % id)
#assert self.is_on_page(MoviePage)
#return self.page.get_movie(id)
def get_person(self, id):
self.location('http://www.imdb.com/name/%s' % id)
assert self.is_on_page(PersonPage)

View file

@ -30,41 +30,6 @@ __all__ = ['MoviePage','PersonPage','MovieCrewPage']
class MoviePage(BasePage):
def get_movie(self,id):
title = NotAvailable
duration = NotAvailable
release_date = NotAvailable
description = NotAvailable
td_overview = self.parser.select(self.document.getroot(),'td#overview-top',1)
for span in self.parser.select(td_overview,'h1.header span[itemprop=name]'):
if span.attrib.get('class','') == 'itemprop':
other_titles = span.text
if title == NotAvailable:
title = other_titles
elif span.attrib.get('class','') == 'title-extra':
title = span.text
metas = self.parser.select(td_overview,'meta[itemprop=datePublished]')
if len(metas) > 0:
datestrings = metas[0].attrib.get('content','').split('-')
if len(datestrings) == 2:
datestrings.append('1')
release_date = datetime(int(datestrings[0]),int(datestrings[1]),int(datestrings[2]))
time = self.parser.select(td_overview,'time[itemprop=duration]')
if len(time) > 0:
duration = int(time[0].attrib.get('datetime','').strip(string.letters))
desc = self.parser.select(td_overview,'p[itemprop=description]')
if len(desc) > 0:
description = desc[0].text
movie = Movie(id,title.strip())
movie.other_titles = other_titles.strip()
movie.release_date = release_date
movie.duration = duration
movie.description = description
movie.note = "10/10"
movie.awards = ["aw1","aw2"]
movie.roles = {}
return movie
def iter_persons(self,id):
self.browser.location('http://www.imdb.com/title/%s/fullcredits'%id)
assert self.browser.is_on_page(MovieCrewPage)
@ -78,15 +43,8 @@ class MovieCrewPage(BasePage):
table = tables[0]
tds = self.parser.select(table,'td.nm')
for td in tds:
name = td.text_content()
id = td.find('a').attrib.get('href','').strip('/').split('/')[-1]
person = Person(id,name)
person.real_name = NotAvailable
person.birth_date = NotAvailable
person.nationality = NotAvailable
person.biography = NotAvailable
person.gender = NotAvailable
yield person
yield self.browser.get_person(id)
class PersonPage(BasePage):
@ -131,13 +89,3 @@ class PersonPage(BasePage):
a = self.parser.select(movie_div,'b a',1)
id = a.attrib.get('href','').strip('/').split('/')[-1]
yield self.browser.get_movie(id)
#title = a.text
#movie = Movie(id,title)
#movie.other_titles = NotAvailable
#movie.release_date = NotAvailable
#movie.duration = NotAvailable
#movie.description = NotAvailable
#movie.note = NotAvailable
#movie.awards = NotAvailable
#movie.roles = NotAvailable
#yield movie

View file

@ -37,9 +37,15 @@ class MovieInfoFormatter(IFormatter):
def format_obj(self, obj, alias):
result = u'%s%s%s\n' % (self.BOLD, obj.original_title, self.NC)
result += 'ID: %s\n' % obj.fullid
result += 'Released: %s\n' % obj.release_date
if obj.release_date != NotAvailable:
result += 'Released: %s\n' % obj.release_date.strftime('%Y-%m-%d')
else:
result += 'Released: %s\n' % obj.release_date
result += 'Country: %s\n' % obj.country
result += 'Duration: %s\n' % obj.duration
if obj.duration != NotAvailable:
result += 'Duration: %smin\n' % obj.duration
else:
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)
@ -63,7 +69,13 @@ class MovieListFormatter(PrettyFormatter):
return obj.original_title
def get_description(self, obj):
return 'Released: %s (note: %s, duration: %s)' % (obj.release_date, obj.note, obj.duration)
date_str = obj.release_date
if obj.release_date != NotAvailable:
date_str = obj.release_date.strftime('%Y-%m-%d')
duration_suffix = ''
if obj.duration != NotAvailable:
duration_suffix = 'min'
return 'Released: %s (note: %s, duration: %s%s)' % (date_str, obj.note, obj.duration, duration_suffix)
def yearsago(years, from_date=None):
if from_date is None: