diff --git a/modules/allocine/browser.py b/modules/allocine/browser.py index 12235949d6281b522ead4c741ae07af36aa7078e..8a556f0d5324b116f3bbf341cbda5081d8098663 100644 --- a/modules/allocine/browser.py +++ b/modules/allocine/browser.py @@ -190,7 +190,8 @@ def get_movie(self, id): for cast in jres['castMember']: if cast['activity']['$'] not in roles: roles[cast['activity']['$']] = [] - roles[cast['activity']['$']].append(cast['person']['name']) + person_to_append = (u'%s'%cast['person']['code'], cast['person']['name']) + roles[cast['activity']['$']].append(person_to_append) movie = Movie(id, title) movie.other_titles = other_titles @@ -277,7 +278,8 @@ def get_person(self, id): pyear = '????' if 'productionYear' in m['movie']: pyear = m['movie']['productionYear'] - roles[m['activity']['$']].append(u'(%s) %s' % (pyear, m['movie']['originalTitle'])) + movie_to_append = (u'%s' % (m['movie']['code']), u'(%s) %s' % (pyear, m['movie']['originalTitle'])) + roles[m['activity']['$']].append(movie_to_append) person = Person(id, name) diff --git a/modules/imdb/browser.py b/modules/imdb/browser.py index 4a5d062c93137cbcaedaf07fba400e77f14f2d11..56fdc498896906c7905591c3a861a6507ef98715 100644 --- a/modules/imdb/browser.py +++ b/modules/imdb/browser.py @@ -157,7 +157,7 @@ def get_movie(self, id): note = u'%s/10 (%s votes)' % (jres['imdbRating'], jres['imdbVotes']) for r in ['Actors', 'Director', 'Writer']: if '%s' % r in jres.keys(): - roles['%s' % r] = jres['%s' % r].split(', ') + roles['%s' % r] = [('N/A',e) for e in jres['%s' % r].split(', ')] movie = Movie(id, title) movie.other_titles = other_titles diff --git a/modules/imdb/pages.py b/modules/imdb/pages.py index 84781187e94878d455c1f3294d1281ad8e287a0f..157ee664f2032526749f4ca835ece877e0c7dbe7 100644 --- a/modules/imdb/pages.py +++ b/modules/imdb/pages.py @@ -206,7 +206,7 @@ def get_roles(self): category = role_div.attrib.get('data-category') for infos in self.parser.select(self.document.getroot(), 'div#filmography > div.filmo-category-section > div'): if category in infos.attrib.get('id'): - roles[role].append(infos.text_content().replace('\n', ' ').strip()) + roles[role].append(('N/A',infos.text_content().replace('\n', ' ').strip())) return roles def iter_movies(self, role_filter=None): diff --git a/weboob/applications/cineoob/cineoob.py b/weboob/applications/cineoob/cineoob.py index fdc1a2a781bc97f845dd96ce3e2716189c344afc..a8dfe88a048c86070bf9a355b54ddc6889c55b18 100644 --- a/weboob/applications/cineoob/cineoob.py +++ b/weboob/applications/cineoob/cineoob.py @@ -59,8 +59,8 @@ def format_obj(self, obj, alias): result += '\n%sRelated persons%s\n' % (self.BOLD, self.NC) for role, lpersons in obj.roles.items(): result += ' -- %s\n' % role - for name in lpersons: - result += ' * %s\n' % name + for person in lpersons: + result += ' * %s\n' % person[1] if not empty(obj.other_titles): result += '\n%sOther titles%s\n' % (self.BOLD, self.NC) for t in obj.other_titles: @@ -143,7 +143,7 @@ def format_obj(self, obj, alias): for role, lmovies in obj.roles.items(): result += ' -- %s\n' % role for movie in lmovies: - result += ' * %s\n' % movie + result += ' * %s\n' % movie[1] if not empty(obj.short_biography): result += '\n%sShort biography%s\n' % (self.BOLD, self.NC) result += '%s' % obj.short_biography @@ -250,6 +250,13 @@ def do_movies_in_common(self, line): inter = list(set(lid1) & set(lid2)) for common in inter: movie = self.get_object(common, 'get_movie', caps=CapCinema) + role1 = movie.get_role_by_person_id(person1.id) + if not role1: + role1 = movie.get_role_by_person_name(person1.name) + role2 = movie.get_role_by_person_id(person2.id) + if not role2: + role2 = movie.get_role_by_person_name(person2.name) + movie.short_description = '%s as %s ; %s as %s'%(person1.name, role1, person2.name, role2) if movie: self.cached_format(movie) @@ -283,6 +290,13 @@ def do_persons_in_common(self, line): inter = list(set(lid1) & set(lid2)) for common in inter: person = self.get_object(common, 'get_person', caps=CapCinema) + role1 = person.get_role_by_movie_id(movie1.id) + if not role1: + role1 = person.get_role_by_movie_title(movie1.original_title) + role2 = person.get_role_by_movie_id(movie2.id) + if not role2: + role2 = person.get_role_by_movie_title(movie2.original_title) + person.short_description = '%s in %s ; %s in %s'%(role1, movie1.original_title, role2, movie2.original_title) self.cached_format(person) def do_info_movie(self, id): diff --git a/weboob/capabilities/cinema.py b/weboob/capabilities/cinema.py index 59885acb818b307044c8cb3c3b29b6adacfb0986..1e8a2d0d2fc16b8078027c108dda14c5085a69e2 100644 --- a/weboob/capabilities/cinema.py +++ b/weboob/capabilities/cinema.py @@ -46,6 +46,18 @@ def __init__(self, id, original_title): BaseObject.__init__(self, id) self.original_title = original_title + def get_role_by_person_name(self,name): + for role in self.roles.keys(): + if name.lower() in [person[1].lower() for person in self.roles[role]]: + return role + return None + + def get_role_by_person_id(self,id): + for role in self.roles.keys(): + if id in [person[0] for person in self.roles[role]]: + return role + return None + class Person(BaseObject): """ @@ -68,6 +80,20 @@ def __init__(self, id, name): BaseObject.__init__(self, id) self.name = name + def get_role_by_movie_title(self,title): + for role in self.roles.keys(): + for mt in [movie[1] for movie in self.roles[role]]: + # title we have is included ? + if title.lower() in mt.lower(): + return role + return None + + def get_role_by_movie_id(self,id): + for role in self.roles.keys(): + if id in [movie[0] for movie in self.roles[role]]: + return role + return None + class CapCinema(Capability): """