def perform(self, query): self.checkValid(query) self.query = query ep = query.find_one(Episode) log.debug('EpisodeTvdb: finding more info on %s' % ep) if ep.get('series') is None: raise SmewtException( "EpisodeTVDB: Episode doesn't contain 'series' field: %s" % ep) # little hack: if we have no season number, add 1 as default season number # (helps for series which have only 1 season) if ep.get('season') is None: ep.season = 1 try: mdprovider = TVDBMetadataProvider() result = mdprovider.startEpisode(ep) except SmewtException: # series could not be found, return a dummy Unknown series instead # so we can group them somewhere log.warning('Could not find series for file: %s' % query.find_one(Media).filename) noposter = '/static/images/noposter.png' result = MemoryObjectGraph() result.Series(title='Unknown', loresImage=noposter, hiresImage=noposter) # update the series query.delete_node(ep.series.node) ep.series = query.add_object( result.find_one(Series)) # this add_object should be unnecessary series = ep.series # and add all the potential episodes for found_ep in result.find_all(Episode): data = {'series': series} data.update(found_ep.literal_items()) ep = query.Episode(**data) return query
def getEpisodes(self, series, language): """From a given TVDBPy series object, return a graph containing its information as well as its episodes nodes.""" show, episodes = self.tvdb.get_show_and_episodes(series, language=language) # TODO: debug to see if this is the correct way to access the series' title result = MemoryObjectGraph() smewtSeries = result.Series(title=show.name) for episode in episodes: ep = result.Episode(series=smewtSeries, season=episode.season_number, episodeNumber=episode.episode_number) ep.set('title', episode.name) ep.set('synopsis', episode.overview) ep.set('originalAirDate', str(episode.first_aired)) return result