Example #1
0
 def get_person_main(self, personID):
     infosets = ('main', 'biography', 'other works')
     nl = getLabel(personID, '%snames.index' % self.__db,
                     '%snames.key' % self.__db)
     # No name, no party.
     if nl is None:
         raise IMDbDataAccessError, 'unable to get personID "%s"' % personID
     res = analyze_name(nl)
     res.update(getBio(personID, '%sbiographies.index' % self.__db,
                 '%sbiographies.data' % self.__db))
     akas = getAkaNames(personID,
                 '%saka-names.data' % self.__db,
                 '%snames.index' % self.__db,
                 '%snames.key' % self.__db)
     if akas: res['akas'] = akas
     # XXX: horrible hack!  The getBio() function is not able to
     #      retrieve the movieID!
     #      A cleaner solution, would be to NOT return Movies object
     #      at first, from the getBio() function.
     # XXX: anyway, this is no more needed, since "guest appearances"
     #      are gone with the new tv series episodes support.
     if res.has_key('notable tv guest appearances'):
         nl = []
         for m in res['notable tv guest appearances']:
             movieID = self._getTitleID(m.get('long imdb canonical title'))
             if movieID is None: continue
             m.movieID = movieID
             nl.append(m)
         if nl:
             nl.sort()
             res['notable tv guest appearances'][:] = nl
         else: del res['notable tv guest appearances']
     trefs, nrefs = self._extractRefs(res)
     return {'data': res, 'info sets': infosets,
             'titlesRefs': trefs, 'namesRefs': nrefs}
Example #2
0
 def _buildEpisodes(self, eps_list, parentID):
     episodes = {}
     parentTitle = getLabel(parentID, '%stitles.index' % self.__db,
                            '%stitles.key' % self.__db)
     parentSeries = Movie(title=parentTitle,
                          movieID=parentID,
                          accessSystem='local')
     for episodeID, episodeTitle in eps_list:
         episodeTitle = unicode(episodeTitle, 'latin_1', 'replace')
         data = analyze_title(episodeTitle, canonical=1)
         m = Movie(data=data, movieID=episodeID, accessSystem='local')
         m['episode of'] = parentSeries
         if data.get('year') is None:
             year = getFullIndex('%smovies.data' % self.__db,
                                 key=episodeID,
                                 kind='moviedata',
                                 rindex=1)
             if year: m['year'] = year
         season = data.get('season', 'UNKNOWN')
         if not episodes.has_key(season): episodes[season] = {}
         ep_number = data.get('episode')
         if ep_number is None:
             ep_number = max((episodes[season].keys() or [0])) + 1
         episodes[season][ep_number] = m
     return episodes
Example #3
0
 def get_person_main(self, personID):
     infosets = ('main', 'biography', 'other works')
     nl = getLabel(personID, '%snames.index' % self.__db,
                     '%snames.key' % self.__db)
     # No name, no party.
     if nl is None:
         raise IMDbDataAccessError, 'unable to get personID "%s"' % personID
     res = analyze_name(nl)
     res.update(getBio(personID, '%sbiographies.index' % self.__db,
                 '%sbiographies.data' % self.__db))
     akas = getAkaNames(personID,
                 '%saka-names.data' % self.__db,
                 '%snames.index' % self.__db,
                 '%snames.key' % self.__db)
     if akas: res['akas'] = akas
     # XXX: horrible hack!  The getBio() function is not able to
     #      retrieve the movieID!
     #      A cleaner solution, would be to NOT return Movies object
     #      at first, from the getBio() function.
     # XXX: anyway, this is no more needed, since "guest appearances"
     #      are gone with the new tv series episodes support.
     if res.has_key('notable tv guest appearances'):
         nl = []
         for m in res['notable tv guest appearances']:
             movieID = self._getTitleID(m.get('long imdb canonical title'))
             if movieID is None: continue
             m.movieID = movieID
             nl.append(m)
         if nl:
             nl.sort()
             res['notable tv guest appearances'][:] = nl
         else: del res['notable tv guest appearances']
     trefs, nrefs = self._extractRefs(res)
     return {'data': res, 'info sets': infosets,
             'titlesRefs': trefs, 'namesRefs': nrefs}
Example #4
0
 def _search_movie(self, title, results, _episodes=False):
     title = title.strip()
     if not title: return []
     # Search for these title variations.
     if not _episodes:
         title1, title2, title3 = titleVariations(title, fromPtdf=1)
     else:
         title1 = normalizeTitle(title)
         title2 = ''
         title3 = ''
     # XXX: only a guess: results are shrinked, to exclude Adult
     #      titles and to remove duplicated entries.
     resultsST = results * 3
     res = _scan_titles('%stitles.key' % self.__db,
                         title1, title2, title3, resultsST, _episodes)
     res[:] = [x[1] for x in res]
     # Check for adult movies.
     if not self.doAdult:
         newlist = []
         for entry in res:
             genres = getMovieMisc(movieID=entry[0],
                             dataF='%s%s.data' % (self.__db, 'genres'),
                             indexF='%s%s.index' % (self.__db, 'genres'),
                             attrIF='%sattributes.index' % self.__db,
                             attrKF='%sattributes.key' % self.__db)
             if 'Adult' not in genres: newlist.append(entry)
         res[:] = newlist
     # Get the real name, if this is an AKA.
     # XXX: duplicated code!
     new_res = []
     seen_MID = []
     for idx, (movieID, r) in enumerate(res):
         # Remove duplicates.
         # XXX: find a way to prefer titles with an AKA?  Or prefer
         #      the original title?
         if movieID in seen_MID:
             continue
         else:
             seen_MID.append(movieID)
         realMID = self._get_real_movieID(movieID)
         if movieID == realMID:
             new_res.append((movieID, r))
             continue
         if realMID in seen_MID:
             continue
         else:
             seen_MID.append(realMID)
         aka_title = build_title(r, canonical=0)
         real_title = getLabel(realMID, '%stitles.index' % self.__db,
                             '%stitles.key' % self.__db)
         if aka_title == real_title:
             new_res.append((realMID, r))
             continue
         new_r = analyze_title(real_title, canonical=1)
         new_r['akas'] = [aka_title]
         new_res.append((realMID, new_r))
     if results > 0: new_res[:] = new_res[:results]
     return new_res
Example #5
0
 def get_imdbPersonID(self, personID):
     """Translate a personID in an imdbID.
     Try an Exact Primary Name search on IMDb;
     return None if it's unable to get the imdbID.
     """
     name = getLabel(personID, '%snames.index' % self.__db,
                     '%snames.key' % self.__db)
     if name is None: return None
     return self.name2imdbID(name)
Example #6
0
 def get_imdbMovieID(self, movieID):
     """Translate a movieID in an imdbID.
     Try an Exact Primary Title search on IMDb;
     return None if it's unable to get the imdbID.
     """
     titline = getLabel(movieID, '%stitles.index' % self.__db,
                         '%stitles.key' % self.__db)
     if titline is None: return None
     return self.title2imdbID(titline)
Example #7
0
 def get_imdbPersonID(self, personID):
     """Translate a personID in an imdbID.
     Try an Exact Primary Name search on IMDb;
     return None if it's unable to get the imdbID.
     """
     name = getLabel(personID, '%snames.index' % self.__db,
                     '%snames.key' % self.__db)
     if name is None: return None
     return self.name2imdbID(name)
Example #8
0
 def get_imdbMovieID(self, movieID):
     """Translate a movieID in an imdbID.
     Try an Exact Primary Title search on IMDb;
     return None if it's unable to get the imdbID.
     """
     titline = getLabel(movieID, '%stitles.index' % self.__db,
                         '%stitles.key' % self.__db)
     if titline is None: return None
     return self.title2imdbID(titline)
Example #9
0
 def _get_top_bottom_movies(self, kind):
     if kind == 'top':
         kind = 'top 250 rank'
     elif kind == 'bottom':
         kind = 'bottom 10 rank'
     else:
         return []
     info = getTopBottomList(kind, '%stopbottom.db' % self.__db)
     if not info:
         return []
     res = []
     for d in info:
         if not 'movieID' in d:
             continue
         movieID = d['movieID']
         del d['movieID']
         minfo = analyze_title(getLabel(movieID,
                                 '%stitles.index' % self.__db,
                                 '%stitles.key' % self.__db))
         minfo.update(d)
         res.append((movieID, minfo))
     return res
Example #10
0
 def _buildEpisodes(self, eps_list, parentID):
     episodes = {}
     parentTitle = getLabel(parentID, '%stitles.index' % self.__db,
                         '%stitles.key' % self.__db)
     parentSeries = Movie(title=parentTitle,
                         movieID=parentID, accessSystem='local')
     for episodeID, episodeTitle in eps_list:
         episodeTitle = unicode(episodeTitle, 'latin_1', 'replace')
         data = analyze_title(episodeTitle, canonical=1)
         m = Movie(data=data, movieID=episodeID, accessSystem='local')
         m['episode of'] = parentSeries
         if data.get('year') is None:
             year = getFullIndex('%smovies.data' % self.__db,
                                 key=episodeID, kind='moviedata', rindex=1)
             if year: m['year'] = year
         season = data.get('season', 'UNKNOWN')
         if not episodes.has_key(season): episodes[season] = {}
         ep_number = data.get('episode')
         if ep_number is None:
             ep_number = max((episodes[season].keys() or [0])) + 1
         episodes[season][ep_number] = m
     return episodes
Example #11
0
 def _search_person(self, name, results):
     name = name.strip()
     if not name: return []
     name1, name2, name3 = nameVariations(name)
     res =  _scan_names('%snames.key' % self.__db,
                         name1, name2, name3, results)
     res[:] = [x[1] for x in res]
     new_res = []
     seen_PID = []
     for idx, (personID, r) in enumerate(res):
         # Remove duplicates.
         # XXX: find a way to prefer names with an AKA?  Or prefer
         #      the original name?
         if personID in seen_PID:
             continue
         else:
             seen_PID.append(personID)
         realPID = self._get_real_personID(personID)
         if personID == realPID:
             new_res.append((personID, r))
             continue
         if realPID in seen_PID:
             continue
         else:
             seen_PID.append(realPID)
         aka_name = build_name(r, canonical=1)
         real_name = getLabel(realPID, '%snames.index' % self.__db,
                             '%snames.key' % self.__db)
         if aka_name == real_name:
             new_res.append((realPID, r))
             continue
         new_r = analyze_name(real_name, canonical=1)
         new_r['akas'] = [aka_name]
         new_res.append((realPID, new_r))
     if results > 0: new_res[:] = new_res[:results]
     return new_res
Example #12
0
 def get_movie_main(self, movieID):
     # Information sets provided by this method.
     infosets = ('main', 'vote details')
     tl = getLabel(movieID, '%stitles.index' % self.__db,
                     '%stitles.key' % self.__db)
     # No title, no party.
     if tl is None:
         raise IMDbDataAccessError, 'unable to get movieID "%s"' % movieID
     res = analyze_title(tl)
     # Build the cast list.
     actl = []
     for castG in ('actors', 'actresses'):
         midx = getFullIndex('%s%s.titles' % (self.__db, castG),
                         movieID, multi=1)
         if midx is not None:
             params = {'movieID': movieID,
                         'dataF': '%s%s.data' % (self.__db, castG),
                         'indexF': '%snames.index' % self.__db,
                         'keyF': '%snames.key' % self.__db,
                         'attrIF': '%sattributes.index' % self.__db,
                         'attrKF': '%sattributes.key' % self.__db,
                         'charNF': '%scharacter2id.index' % self.__db,
                         'offsList': midx, 'doCast': 1}
             actl += getMovieCast(**params)
     if actl:
         actl.sort()
         res['cast'] = actl
     # List of other workers.
     works = ('writer', 'cinematographer', 'composer',
             'costume-designer', 'director', 'editor', 'miscellaneou',
             'producer', 'production-designer', 'cinematographer')
     for i in works:
         index = getFullIndex('%s%ss.titles' % (self.__db, i),
                                 movieID, multi=1)
         if index is not None:
             params = {'movieID': movieID,
                         'dataF': '%s%s.data' % (self.__db, i),
                         'indexF': '%snames.index' % self.__db,
                         'keyF': '%snames.key' % self.__db,
                         'attrIF': '%sattributes.index' % self.__db,
                         'attrKF': '%sattributes.key' % self.__db,
                         'offsList': index}
             name = key = i
             if '-' in name:
                 name = name.replace('-', ' ')
             elif name == 'miscellaneou':
                 name = 'miscellaneous crew'
                 key = 'miscellaneou'
             elif name == 'writer':
                 params['doWriters'] = 1
             params['dataF'] = '%s%ss.data' % (self.__db, key)
             data = getMovieCast(**params)
             if name == 'writer': data.sort()
             res[name] = data
     # Rating.
     rt = self.get_movie_vote_details(movieID)['data']
     if rt: res.update(rt)
     # Various information.
     miscInfo = (('runtimes', 'running-times'), ('color info', 'color-info'),
                 ('genres', 'genres'), ('distributors', 'distributors'),
                 ('languages', 'language'), ('certificates', 'certificates'),
                 ('special effects companies', 'special-effects-companies'),
                 ('sound mix', 'sound-mix'), ('tech info', 'technical'),
                 ('production companies', 'production-companies'),
                 ('countries', 'countries'))
     for name, fname in miscInfo:
         params = {'movieID': movieID,
             'dataF': '%s%s.data' % (self.__db, fname),
             'indexF': '%s%s.index' % (self.__db, fname),
             'attrIF': '%sattributes.index' % self.__db,
             'attrKF': '%sattributes.key' % self.__db}
         data = getMovieMisc(**params)
         if name in ('distributors', 'special effects companies',
                     'production companies'):
             for nitem in xrange(len(data)):
                 n, notes = split_company_name_notes(data[nitem])
                 company = Company(name=n, companyID=getCompanyID(n,
                                     '%scompany2id.index' % self.__db),
                                     notes=notes,
                                     accessSystem=self.accessSystem)
                 data[nitem] = company
         if data: res[name] = data
     if res.has_key('runtimes') and len(res['runtimes']) > 0:
         rt = res['runtimes'][0]
         episodes = re_episodes.findall(rt)
         if episodes:
             res['runtimes'][0] = re_episodes.sub('', rt)
             res['number of episodes'] = episodes[0]
     # AKA titles.
     akas = getAkaTitles(movieID,
                 '%saka-titles.data' % self.__db,
                 '%stitles.index' % self.__db,
                 '%stitles.key' % self.__db,
                 '%sattributes.index' % self.__db,
                 '%sattributes.key' % self.__db)
     if akas:
         # normalize encoding.
         for i in xrange(len(akas)):
             ts = akas[i].split('::')
             if len(ts) != 2: continue
             t = ts[0]
             n = ts[1]
             nt = self._changeAKAencoding(n, t)
             if nt is not None: akas[i] = '%s::%s' % (nt, n)
         res['akas'] = akas
     if res.get('kind') == 'episode':
         # Things to do if this is a tv series episode.
         episodeOf = res.get('episode of')
         if episodeOf is not None:
             parentSeries = Movie(data=res['episode of'],
                                         accessSystem='local')
             seriesID = self._getTitleID(parentSeries.get(
                                         'long imdb canonical title'))
             parentSeries.movieID = seriesID
             res['episode of'] = parentSeries
         if not res.get('year'):
             year = getFullIndex('%smovies.data' % self.__db,
                                 movieID, kind='moviedata', rindex=1)
             if year: res['year'] = year
     # MPAA info.
     mpaa = getMPAA(movieID, '%smpaa-ratings-reasons.index' % self.__db,
                     '%smpaa-ratings-reasons.data' % self.__db)
     if mpaa: res.update(mpaa)
     return {'data': res, 'info sets': infosets}
Example #13
0
 def _get_keyword(self, keyword, results):
     return [(movieID, analyze_title(getLabel(movieID,
             '%stitles.index' % self.__db, '%stitles.key' % self.__db)))
             for movieID in getKeywordMovies(keyword,
                 '%skeywords.data' % self.__db)][:results]
Example #14
0
 def get_movie_main(self, movieID):
     # Information sets provided by this method.
     infosets = ('main', 'vote details')
     tl = getLabel(movieID, '%stitles.index' % self.__db,
                     '%stitles.key' % self.__db)
     # No title, no party.
     if tl is None:
         raise IMDbDataAccessError, 'unable to get movieID "%s"' % movieID
     res = analyze_title(tl)
     # Build the cast list.
     actl = []
     for castG in ('actors', 'actresses'):
         midx = getFullIndex('%s%s.titles' % (self.__db, castG),
                         movieID, multi=1)
         if midx is not None:
             params = {'movieID': movieID,
                         'dataF': '%s%s.data' % (self.__db, castG),
                         'indexF': '%snames.index' % self.__db,
                         'keyF': '%snames.key' % self.__db,
                         'attrIF': '%sattributes.index' % self.__db,
                         'attrKF': '%sattributes.key' % self.__db,
                         'charNF': '%scharacter2id.index' % self.__db,
                         'offsList': midx, 'doCast': 1}
             actl += getMovieCast(**params)
     if actl:
         actl.sort()
         res['cast'] = actl
     # List of other workers.
     works = ('writer', 'cinematographer', 'composer',
             'costume-designer', 'director', 'editor', 'miscellaneou',
             'producer', 'production-designer', 'cinematographer')
     for i in works:
         index = getFullIndex('%s%ss.titles' % (self.__db, i),
                                 movieID, multi=1)
         if index is not None:
             params = {'movieID': movieID,
                         'dataF': '%s%s.data' % (self.__db, i),
                         'indexF': '%snames.index' % self.__db,
                         'keyF': '%snames.key' % self.__db,
                         'attrIF': '%sattributes.index' % self.__db,
                         'attrKF': '%sattributes.key' % self.__db,
                         'offsList': index}
             name = key = i
             if '-' in name:
                 name = name.replace('-', ' ')
             elif name == 'miscellaneou':
                 name = 'miscellaneous crew'
                 key = 'miscellaneou'
             elif name == 'writer':
                 params['doWriters'] = 1
             params['dataF'] = '%s%ss.data' % (self.__db, key)
             data = getMovieCast(**params)
             if name == 'writer': data.sort()
             res[name] = data
     # Rating.
     rt = self.get_movie_vote_details(movieID)['data']
     if rt: res.update(rt)
     # Various information.
     miscInfo = (('runtimes', 'running-times'), ('color info', 'color-info'),
                 ('genres', 'genres'), ('distributors', 'distributors'),
                 ('languages', 'language'), ('certificates', 'certificates'),
                 ('special effects companies', 'special-effects-companies'),
                 ('sound mix', 'sound-mix'), ('tech info', 'technical'),
                 ('production companies', 'production-companies'),
                 ('countries', 'countries'))
     for name, fname in miscInfo:
         params = {'movieID': movieID,
             'dataF': '%s%s.data' % (self.__db, fname),
             'indexF': '%s%s.index' % (self.__db, fname),
             'attrIF': '%sattributes.index' % self.__db,
             'attrKF': '%sattributes.key' % self.__db}
         data = getMovieMisc(**params)
         if name in ('distributors', 'special effects companies',
                     'production companies'):
             for nitem in xrange(len(data)):
                 n, notes = split_company_name_notes(data[nitem])
                 company = Company(name=n, companyID=getCompanyID(n,
                                     '%scompany2id.index' % self.__db),
                                     notes=notes,
                                     accessSystem=self.accessSystem)
                 data[nitem] = company
         if data: res[name] = data
     if res.has_key('runtimes') and len(res['runtimes']) > 0:
         rt = res['runtimes'][0]
         episodes = re_episodes.findall(rt)
         if episodes:
             res['runtimes'][0] = re_episodes.sub('', rt)
             res['number of episodes'] = episodes[0]
     # AKA titles.
     akas = getAkaTitles(movieID,
                 '%saka-titles.data' % self.__db,
                 '%stitles.index' % self.__db,
                 '%stitles.key' % self.__db,
                 '%sattributes.index' % self.__db,
                 '%sattributes.key' % self.__db)
     if akas:
         # normalize encoding.
         for i in xrange(len(akas)):
             ts = akas[i].split('::')
             if len(ts) != 2: continue
             t = ts[0]
             n = ts[1]
             nt = self._changeAKAencoding(n, t)
             if nt is not None: akas[i] = '%s::%s' % (nt, n)
         res['akas'] = akas
     if res.get('kind') == 'episode':
         # Things to do if this is a tv series episode.
         episodeOf = res.get('episode of')
         if episodeOf is not None:
             parentSeries = Movie(data=res['episode of'],
                                         accessSystem='local')
             seriesID = self._getTitleID(parentSeries.get(
                                         'long imdb canonical title'))
             parentSeries.movieID = seriesID
             res['episode of'] = parentSeries
         if not res.get('year'):
             year = getFullIndex('%smovies.data' % self.__db,
                                 movieID, kind='moviedata', rindex=1)
             if year: res['year'] = year
     # MPAA info.
     mpaa = getMPAA(movieID, '%smpaa-ratings-reasons.index' % self.__db,
                     '%smpaa-ratings-reasons.data' % self.__db)
     if mpaa: res.update(mpaa)
     return {'data': res, 'info sets': infosets}