imdb in progress...
This commit is contained in:
parent
3492dbb9d6
commit
a82483727b
4 changed files with 62 additions and 21 deletions
|
|
@ -42,7 +42,8 @@ class ImdbBrowser(BaseBrowser):
|
||||||
# the api leads to a json result or the html movie page if there is only one result
|
# the api leads to a json result or the html movie page if there is only one result
|
||||||
self.location('http://www.imdb.com/xml/find?json=1&tt=on&q=%s' % pattern.encode('utf-8'))
|
self.location('http://www.imdb.com/xml/find?json=1&tt=on&q=%s' % pattern.encode('utf-8'))
|
||||||
if self.is_on_page(MoviePage):
|
if self.is_on_page(MoviePage):
|
||||||
yield self.page.get_movie()
|
id = 'tt'+self.geturl().split('/tt')[1].split('/')[0]
|
||||||
|
yield self.page.get_movie(id)
|
||||||
else:
|
else:
|
||||||
res = self.readurl('http://www.imdb.com/xml/find?json=1&tt=on&q=%s' % pattern.encode('utf-8'))
|
res = self.readurl('http://www.imdb.com/xml/find?json=1&tt=on&q=%s' % pattern.encode('utf-8'))
|
||||||
jres = json.loads(res)
|
jres = json.loads(res)
|
||||||
|
|
@ -51,10 +52,11 @@ class ImdbBrowser(BaseBrowser):
|
||||||
yield self.get_movie(m['id'])
|
yield self.get_movie(m['id'])
|
||||||
|
|
||||||
def iter_persons(self, pattern):
|
def iter_persons(self, pattern):
|
||||||
# the api leads to a json result or the html movie page if there is only one result
|
# the api leads to a json result or the html person page if there is only one result
|
||||||
self.location('http://www.imdb.com/xml/find?json=1&nm=on&q=%s' % pattern.encode('utf-8'))
|
self.location('http://www.imdb.com/xml/find?json=1&nm=on&q=%s' % pattern.encode('utf-8'))
|
||||||
if self.is_on_page(PersonPage):
|
if self.is_on_page(PersonPage):
|
||||||
yield self.page.get_person()
|
id = 'nm'+self.geturl().split('/nm')[1].split('/')[0]
|
||||||
|
yield self.page.get_person(id)
|
||||||
else:
|
else:
|
||||||
res = self.readurl('http://www.imdb.com/xml/find?json=1&nm=on&q=%s' % pattern.encode('utf-8'))
|
res = self.readurl('http://www.imdb.com/xml/find?json=1&nm=on&q=%s' % pattern.encode('utf-8'))
|
||||||
jres = json.loads(res)
|
jres = json.loads(res)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ class MoviePage(BasePage):
|
||||||
def get_movie(self,id):
|
def get_movie(self,id):
|
||||||
title = NotAvailable
|
title = NotAvailable
|
||||||
duration = NotAvailable
|
duration = NotAvailable
|
||||||
description = NotAvailable.__unicode__()
|
release_date = NotAvailable
|
||||||
|
description = NotAvailable
|
||||||
td_overview = self.parser.select(self.document.getroot(),'td#overview-top',1)
|
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]'):
|
for span in self.parser.select(td_overview,'h1.header span[itemprop=name]'):
|
||||||
if span.attrib.get('class','') == 'itemprop':
|
if span.attrib.get('class','') == 'itemprop':
|
||||||
|
|
@ -42,10 +43,12 @@ class MoviePage(BasePage):
|
||||||
title = other_titles
|
title = other_titles
|
||||||
elif span.attrib.get('class','') == 'title-extra':
|
elif span.attrib.get('class','') == 'title-extra':
|
||||||
title = span.text
|
title = span.text
|
||||||
meta = self.parser.select(td_overview,'meta[itemprop=datePublished]',1)
|
metas = self.parser.select(td_overview,'meta[itemprop=datePublished]')
|
||||||
datestrings = meta.attrib.get('content','').split('-')
|
if len(metas) > 0:
|
||||||
if len(datestrings) == 2:
|
datestrings = metas[0].attrib.get('content','').split('-')
|
||||||
datestrings.append('1')
|
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]')
|
time = self.parser.select(td_overview,'time[itemprop=duration]')
|
||||||
if len(time) > 0:
|
if len(time) > 0:
|
||||||
duration = int(time[0].attrib.get('datetime','').strip(string.letters))
|
duration = int(time[0].attrib.get('datetime','').strip(string.letters))
|
||||||
|
|
@ -54,7 +57,7 @@ class MoviePage(BasePage):
|
||||||
description = desc[0].text
|
description = desc[0].text
|
||||||
movie = Movie(id,title.strip())
|
movie = Movie(id,title.strip())
|
||||||
movie.other_titles = other_titles.strip()
|
movie.other_titles = other_titles.strip()
|
||||||
movie.release_date = datetime(int(datestrings[0]),int(datestrings[1]),int(datestrings[2]))
|
movie.release_date = release_date
|
||||||
movie.duration = duration
|
movie.duration = duration
|
||||||
movie.description = description
|
movie.description = description
|
||||||
movie.note = "10/10"
|
movie.note = "10/10"
|
||||||
|
|
@ -81,22 +84,55 @@ class MovieCrewPage(BasePage):
|
||||||
person.real_name = NotAvailable
|
person.real_name = NotAvailable
|
||||||
person.birth_date = NotAvailable
|
person.birth_date = NotAvailable
|
||||||
person.nationality = NotAvailable
|
person.nationality = NotAvailable
|
||||||
|
person.biography = NotAvailable
|
||||||
person.gender = NotAvailable
|
person.gender = NotAvailable
|
||||||
yield person
|
yield person
|
||||||
|
|
||||||
|
|
||||||
class PersonPage(BasePage):
|
class PersonPage(BasePage):
|
||||||
def get_person(self,id):
|
def get_person(self,id):
|
||||||
person = Person(id,'nameplop')
|
name = NotAvailable
|
||||||
person.real_name = 'rn'
|
biography = NotAvailable
|
||||||
person.birth_date = datetime.now()
|
birth_place = NotAvailable
|
||||||
person.birth_place = "place"
|
birth_date = NotAvailable
|
||||||
person.gender = "M"
|
real_name = NotAvailable
|
||||||
person.nationality = "nn"
|
gender = NotAvailable
|
||||||
person.biography = 'bio'
|
nationality = NotAvailable
|
||||||
|
td_overview = self.parser.select(self.document.getroot(),'td#overview-top',1)
|
||||||
|
descs = self.parser.select(td_overview,'span[itemprop=description]')
|
||||||
|
if len(descs) > 0:
|
||||||
|
biography = descs[0].text
|
||||||
|
names = self.parser.select(td_overview,'h1[itemprop=name]')
|
||||||
|
if len(names) > 0:
|
||||||
|
name = names[0].text
|
||||||
|
times = self.parser.select(td_overview,'time[itemprop=birthDate]')
|
||||||
|
if len(times) > 0:
|
||||||
|
time = times[0].attrib.get('datetime','').split('-')
|
||||||
|
birth_date = datetime(int(time[0]),int(time[1]),int(time[2]))
|
||||||
|
|
||||||
|
person = Person(id,name)
|
||||||
|
person.real_name = real_name
|
||||||
|
person.birth_date = birth_date
|
||||||
|
person.birth_place = birth_place
|
||||||
|
person.gender = gender
|
||||||
|
person.nationality = nationality
|
||||||
|
person.biography = biography
|
||||||
person.awards = ["aw1","aw2"]
|
person.awards = ["aw1","aw2"]
|
||||||
person.roles = {}
|
person.roles = {}
|
||||||
return person
|
return person
|
||||||
|
|
||||||
def iter_movies(self,person_id):
|
def iter_movies(self,person_id):
|
||||||
pass
|
for movie_div in self.parser.select(self.document.getroot(),'div[class~=filmo-row]'):
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class MovieInfoFormatter(IFormatter):
|
||||||
for a in obj.awards:
|
for a in obj.awards:
|
||||||
result += ' * %s\n' % a
|
result += ' * %s\n' % a
|
||||||
result += '\n%sDescription%s\n' % (self.BOLD, self.NC)
|
result += '\n%sDescription%s\n' % (self.BOLD, self.NC)
|
||||||
result += obj.description
|
result += '%s'%obj.description
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -93,7 +93,10 @@ class PersonInfoFormatter(IFormatter):
|
||||||
result += 'ID: %s\n' % obj.fullid
|
result += 'ID: %s\n' % obj.fullid
|
||||||
result += 'Real name: %s\n' % obj.real_name
|
result += 'Real name: %s\n' % obj.real_name
|
||||||
result += 'Birth date: %s\n' % obj.birth_date
|
result += 'Birth date: %s\n' % obj.birth_date
|
||||||
age = num_years(obj.birth_date)
|
if obj.birth_date != NotAvailable:
|
||||||
|
age = num_years(obj.birth_date)
|
||||||
|
else:
|
||||||
|
age = NotAvailable
|
||||||
result += 'Age: %s\n' % age
|
result += 'Age: %s\n' % age
|
||||||
result += 'Birth place: %s\n' % obj.birth_place
|
result += 'Birth place: %s\n' % obj.birth_place
|
||||||
result += 'Gender: %s\n' % obj.gender
|
result += 'Gender: %s\n' % obj.gender
|
||||||
|
|
@ -109,7 +112,7 @@ class PersonInfoFormatter(IFormatter):
|
||||||
for a in obj.awards:
|
for a in obj.awards:
|
||||||
result += ' * %s\n' % a
|
result += ' * %s\n' % a
|
||||||
result += '\n%sBiography%s\n' % (self.BOLD, self.NC)
|
result += '\n%sBiography%s\n' % (self.BOLD, self.NC)
|
||||||
result += obj.biography
|
result += '%s'%obj.biography
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class SubtitleInfoFormatter(IFormatter):
|
||||||
result += 'LANG: %s\n' % obj.language
|
result += 'LANG: %s\n' % obj.language
|
||||||
result += 'NB CD: %s\n' % obj.nb_cd
|
result += 'NB CD: %s\n' % obj.nb_cd
|
||||||
result += '\n%sDescription%s\n' % (self.BOLD, self.NC)
|
result += '\n%sDescription%s\n' % (self.BOLD, self.NC)
|
||||||
result += obj.description
|
result += '%s'%obj.description
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue