diff --git a/man/cineoob.1 b/man/cineoob.1 index d8ce0be3..1fc1bbe7 100644 --- a/man/cineoob.1 +++ b/man/cineoob.1 @@ -37,13 +37,13 @@ Get information about a movie. .br Get information about a person. .TP -\fBfilmography\fR \fIID\fR +\fBfilmography\fR \fIID\fR \fI[ROLE]\fR .br -List movies related to a person. +List movies related to a person. If ROLE is given, filter by ROLE. .TP -\fBcasting\fR \fIID\fR +\fBcasting\fR \fIID\fR \fI[ROLE]\fR .br -List persons related to a movie. +List persons related to a movie. if ROLE is given, filter by ROLE. .TP \fBmovies_in_common\fR \fIID1\fR \fIID2\fR .br diff --git a/modules/imdb/backend.py b/modules/imdb/backend.py index 7219585d..93beca01 100644 --- a/modules/imdb/backend.py +++ b/modules/imdb/backend.py @@ -51,11 +51,11 @@ class ImdbBackend(BaseBackend, ICapCinema): def iter_persons(self, pattern): return self.browser.iter_persons(quote_plus(pattern.encode('utf-8'))) - def iter_movie_persons(self, id): - return self.browser.iter_movie_persons(id) + def iter_movie_persons(self, id, role): + return self.browser.iter_movie_persons(id, role) - def iter_person_movies(self, id): - return self.browser.iter_person_movies(id) + def iter_person_movies(self, id, role): + return self.browser.iter_person_movies(id, role) def iter_person_movies_ids(self, id): return self.browser.iter_person_movies_ids(id) diff --git a/modules/imdb/browser.py b/modules/imdb/browser.py index c7e22f10..821ad43e 100644 --- a/modules/imdb/browser.py +++ b/modules/imdb/browser.py @@ -133,15 +133,15 @@ class ImdbBrowser(BaseBrowser): assert self.is_on_page(BiographyPage) 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) 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) 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): self.location('http://www.imdb.com/name/%s' % person_id) diff --git a/modules/imdb/pages.py b/modules/imdb/pages.py index 0b36de4f..bc8bf153 100644 --- a/modules/imdb/pages.py +++ b/modules/imdb/pages.py @@ -31,10 +31,10 @@ __all__ = ['MoviePage','PersonPage','MovieCrewPage','BiographyPage','Filmography class MoviePage(BasePage): ''' 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) 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 def iter_persons_ids(self,id): @@ -62,14 +62,26 @@ class BiographyPage(BasePage): class MovieCrewPage(BasePage): ''' Page listing all the persons related to a movie ''' - def iter_persons(self): - tables = self.parser.select(self.document.getroot(),'table.cast') - if len(tables) > 0: - table = tables[0] - tds = self.parser.select(table,'td.nm') - for td in tds: - id = td.find('a').attrib.get('href','').strip('/').split('/')[-1] - yield self.browser.get_person(id) + def iter_persons(self, role_filter=None): + if (role_filter == None or (role_filter != None and role_filter == 'actor')): + tables = self.parser.select(self.document.getroot(),'table.cast') + if len(tables) > 0: + table = tables[0] + tds = self.parser.select(table,'td.nm') + for td in tds: + 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): 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)) 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'): 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'): id = a.attrib.get('href','').strip('/').split('/')[-1] if id.startswith('tt'): diff --git a/weboob/applications/cineoob/cineoob.py b/weboob/applications/cineoob/cineoob.py index 72daad1a..392976a5 100644 --- a/weboob/applications/cineoob/cineoob.py +++ b/weboob/applications/cineoob/cineoob.py @@ -165,11 +165,15 @@ class Cineoob(ReplApplication): 'movies_in_common':'movie_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(' ') - if len(args) == 2: - return self._complete_object() + if len(args) == 3: + 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): """ @@ -304,35 +308,39 @@ class Cineoob(ReplApplication): self.cached_format(person) 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. + 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') 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, role): self.cached_format(person) 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. + 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') 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, role): self.cached_format(movie) self.flush()