[cineoob] filter casting and filmo by role
This commit is contained in:
parent
70dcda6e59
commit
84ea3ad59b
5 changed files with 56 additions and 35 deletions
|
|
@ -37,13 +37,13 @@ Get information about a movie.
|
||||||
.br
|
.br
|
||||||
Get information about a person.
|
Get information about a person.
|
||||||
.TP
|
.TP
|
||||||
\fBfilmography\fR \fIID\fR
|
\fBfilmography\fR \fIID\fR \fI[ROLE]\fR
|
||||||
.br
|
.br
|
||||||
List movies related to a person.
|
List movies related to a person. If ROLE is given, filter by ROLE.
|
||||||
.TP
|
.TP
|
||||||
\fBcasting\fR \fIID\fR
|
\fBcasting\fR \fIID\fR \fI[ROLE]\fR
|
||||||
.br
|
.br
|
||||||
List persons related to a movie.
|
List persons related to a movie. if ROLE is given, filter by ROLE.
|
||||||
.TP
|
.TP
|
||||||
\fBmovies_in_common\fR \fIID1\fR \fIID2\fR
|
\fBmovies_in_common\fR \fIID1\fR \fIID2\fR
|
||||||
.br
|
.br
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,11 @@ class ImdbBackend(BaseBackend, ICapCinema):
|
||||||
def iter_persons(self, pattern):
|
def iter_persons(self, pattern):
|
||||||
return self.browser.iter_persons(quote_plus(pattern.encode('utf-8')))
|
return self.browser.iter_persons(quote_plus(pattern.encode('utf-8')))
|
||||||
|
|
||||||
def iter_movie_persons(self, id):
|
def iter_movie_persons(self, id, role):
|
||||||
return self.browser.iter_movie_persons(id)
|
return self.browser.iter_movie_persons(id, role)
|
||||||
|
|
||||||
def iter_person_movies(self, id):
|
def iter_person_movies(self, id, role):
|
||||||
return self.browser.iter_person_movies(id)
|
return self.browser.iter_person_movies(id, role)
|
||||||
|
|
||||||
def iter_person_movies_ids(self, id):
|
def iter_person_movies_ids(self, id):
|
||||||
return self.browser.iter_person_movies_ids(id)
|
return self.browser.iter_person_movies_ids(id)
|
||||||
|
|
|
||||||
|
|
@ -133,15 +133,15 @@ class ImdbBrowser(BaseBrowser):
|
||||||
assert self.is_on_page(BiographyPage)
|
assert self.is_on_page(BiographyPage)
|
||||||
return self.page.get_biography()
|
return self.page.get_biography()
|
||||||
|
|
||||||
def iter_movie_persons(self, movie_id):
|
def iter_movie_persons(self, movie_id, role):
|
||||||
self.location('http://www.imdb.com/title/%s' % movie_id)
|
self.location('http://www.imdb.com/title/%s' % movie_id)
|
||||||
assert self.is_on_page(MoviePage)
|
assert self.is_on_page(MoviePage)
|
||||||
return self.page.iter_persons(movie_id)
|
return self.page.iter_persons(movie_id, role)
|
||||||
|
|
||||||
def iter_person_movies(self, person_id):
|
def iter_person_movies(self, person_id, role):
|
||||||
self.location('http://www.imdb.com/name/%s/filmotype' % person_id)
|
self.location('http://www.imdb.com/name/%s/filmotype' % person_id)
|
||||||
assert self.is_on_page(FilmographyPage)
|
assert self.is_on_page(FilmographyPage)
|
||||||
return self.page.iter_movies()
|
return self.page.iter_movies(role)
|
||||||
|
|
||||||
def iter_person_movies_ids(self, person_id):
|
def iter_person_movies_ids(self, person_id):
|
||||||
self.location('http://www.imdb.com/name/%s' % person_id)
|
self.location('http://www.imdb.com/name/%s' % person_id)
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,10 @@ __all__ = ['MoviePage','PersonPage','MovieCrewPage','BiographyPage','Filmography
|
||||||
class MoviePage(BasePage):
|
class MoviePage(BasePage):
|
||||||
''' Page describing a movie, only used to go on the MovieCrewPage
|
''' Page describing a movie, only used to go on the MovieCrewPage
|
||||||
'''
|
'''
|
||||||
def iter_persons(self,id):
|
def iter_persons(self, id, role=None):
|
||||||
self.browser.location('http://www.imdb.com/title/%s/fullcredits'%id)
|
self.browser.location('http://www.imdb.com/title/%s/fullcredits'%id)
|
||||||
assert self.browser.is_on_page(MovieCrewPage)
|
assert self.browser.is_on_page(MovieCrewPage)
|
||||||
for p in self.browser.page.iter_persons():
|
for p in self.browser.page.iter_persons(role):
|
||||||
yield p
|
yield p
|
||||||
|
|
||||||
def iter_persons_ids(self,id):
|
def iter_persons_ids(self,id):
|
||||||
|
|
@ -62,14 +62,26 @@ class BiographyPage(BasePage):
|
||||||
class MovieCrewPage(BasePage):
|
class MovieCrewPage(BasePage):
|
||||||
''' Page listing all the persons related to a movie
|
''' Page listing all the persons related to a movie
|
||||||
'''
|
'''
|
||||||
def iter_persons(self):
|
def iter_persons(self, role_filter=None):
|
||||||
tables = self.parser.select(self.document.getroot(),'table.cast')
|
if (role_filter == None or (role_filter != None and role_filter == 'actor')):
|
||||||
if len(tables) > 0:
|
tables = self.parser.select(self.document.getroot(),'table.cast')
|
||||||
table = tables[0]
|
if len(tables) > 0:
|
||||||
tds = self.parser.select(table,'td.nm')
|
table = tables[0]
|
||||||
for td in tds:
|
tds = self.parser.select(table,'td.nm')
|
||||||
id = td.find('a').attrib.get('href','').strip('/').split('/')[-1]
|
for td in tds:
|
||||||
yield self.browser.get_person(id)
|
id = td.find('a').attrib.get('href','').strip('/').split('/')[-1]
|
||||||
|
yield self.browser.get_person(id)
|
||||||
|
|
||||||
|
for gloss_link in self.parser.select(self.document.getroot(),'table[cellspacing=1] h5 a'):
|
||||||
|
role = gloss_link.attrib.get('name','').rstrip('s')
|
||||||
|
if (role_filter == None or (role_filter != None and role == role_filter)):
|
||||||
|
tbody = gloss_link.getparent().getparent().getparent().getparent()
|
||||||
|
for line in self.parser.select(tbody,'tr')[1:]:
|
||||||
|
for a in self.parser.select(line,'a'):
|
||||||
|
href = a.attrib.get('href','')
|
||||||
|
if '/name/nm' in href:
|
||||||
|
id = href.strip('/').split('/')[-1]
|
||||||
|
yield self.browser.get_person(id)
|
||||||
|
|
||||||
def iter_persons_ids(self):
|
def iter_persons_ids(self):
|
||||||
tables = self.parser.select(self.document.getroot(),'table.cast')
|
tables = self.parser.select(self.document.getroot(),'table.cast')
|
||||||
|
|
@ -170,10 +182,11 @@ class FilmographyPage(BasePage):
|
||||||
roles[role].append('(%s) %s'%(between_p,a.text))
|
roles[role].append('(%s) %s'%(between_p,a.text))
|
||||||
return roles
|
return roles
|
||||||
|
|
||||||
def iter_movies(self):
|
def iter_movies(self, role_filter=None):
|
||||||
for role_div in self.parser.select(self.document.getroot(),'div.filmo'):
|
for role_div in self.parser.select(self.document.getroot(),'div.filmo'):
|
||||||
role = self.parser.select(role_div,'h5 a',1).text.replace(':','')
|
role = self.parser.select(role_div,'h5 a',1).text.replace(':','')
|
||||||
if role != 'In Development':
|
if (role_filter == None or (role_filter != None and role.lower().strip() == role_filter))\
|
||||||
|
and role != 'In Development':
|
||||||
for a in self.parser.select(role_div,'ol > li > a'):
|
for a in self.parser.select(role_div,'ol > li > a'):
|
||||||
id = a.attrib.get('href','').strip('/').split('/')[-1]
|
id = a.attrib.get('href','').strip('/').split('/')[-1]
|
||||||
if id.startswith('tt'):
|
if id.startswith('tt'):
|
||||||
|
|
|
||||||
|
|
@ -165,11 +165,15 @@ class Cineoob(ReplApplication):
|
||||||
'movies_in_common':'movie_list',
|
'movies_in_common':'movie_list',
|
||||||
'persons_in_common':'person_list'
|
'persons_in_common':'person_list'
|
||||||
}
|
}
|
||||||
|
ROLE_LIST = ['actor','director','writer','composer','producer']
|
||||||
|
|
||||||
def complete_info(self, text, line, *ignored):
|
def complete_filmography(self, text, line, *ignored):
|
||||||
args = line.split(' ')
|
args = line.split(' ')
|
||||||
if len(args) == 2:
|
if len(args) == 3:
|
||||||
return self._complete_object()
|
return self.ROLE_LIST
|
||||||
|
|
||||||
|
def complete_casting(self, text, line, *ignored):
|
||||||
|
return self.complete_filmography(text,line,ignored)
|
||||||
|
|
||||||
def do_movies_in_common(self, line):
|
def do_movies_in_common(self, line):
|
||||||
"""
|
"""
|
||||||
|
|
@ -304,35 +308,39 @@ class Cineoob(ReplApplication):
|
||||||
self.cached_format(person)
|
self.cached_format(person)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def do_casting(self, movie_id):
|
def do_casting(self, line):
|
||||||
"""
|
"""
|
||||||
casting movie_ID
|
casting movie_ID [ROLE]
|
||||||
|
|
||||||
List persons related to a movie.
|
List persons related to a movie.
|
||||||
|
If ROLE is given, filter by ROLE
|
||||||
"""
|
"""
|
||||||
|
movie_id, role = self.parse_command_args(line, 2, 1)
|
||||||
|
|
||||||
movie = self.get_object(movie_id, 'get_movie')
|
movie = self.get_object(movie_id, 'get_movie')
|
||||||
if not movie:
|
if not movie:
|
||||||
print >>sys.stderr, 'Movie not found: %s' % id
|
print >>sys.stderr, 'Movie not found: %s' % id
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
self.change_path([u'casting'])
|
for backend, person in self.do('iter_movie_persons', movie.id, role):
|
||||||
for backend, person in self.do('iter_movie_persons', movie.id):
|
|
||||||
self.cached_format(person)
|
self.cached_format(person)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def do_filmography(self, person_id):
|
def do_filmography(self, line):
|
||||||
"""
|
"""
|
||||||
filmography person_ID
|
filmography person_ID [ROLE]
|
||||||
|
|
||||||
List movies of a person.
|
List movies of a person.
|
||||||
|
If ROLE is given, filter by ROLE
|
||||||
"""
|
"""
|
||||||
|
person_id, role = self.parse_command_args(line, 2, 1)
|
||||||
|
|
||||||
person = self.get_object(person_id, 'get_person')
|
person = self.get_object(person_id, 'get_person')
|
||||||
if not person:
|
if not person:
|
||||||
print >>sys.stderr, 'Person not found: %s' % id
|
print >>sys.stderr, 'Person not found: %s' % id
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
self.change_path([u'filmography'])
|
for backend, movie in self.do('iter_person_movies', person.id, role):
|
||||||
for backend, movie in self.do('iter_person_movies', person.id):
|
|
||||||
self.cached_format(movie)
|
self.cached_format(movie)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue