예제 #1
0
 def tvdbLookup(self, tvdb_id, season_num, episode_num, dateSearch):
     #TvDB Lookup for episodes
     
     meta = {}
     tvdb = TheTVDB()
     if dateSearch:
         aired=self.get_date(season_num, episode_num)
         episode = tvdb.get_episode_by_airdate(tvdb_id, aired)
         
         #We do this because the airdate method returns just a part of the overview unfortunately
         if episode is not None:
             ep_id = episode.id
             if ep_id is not None:
                 episode = tvdb.get_episode(ep_id)
     else:
         episode = tvdb.get_episode_by_season_ep(tvdb_id, season_num, episode_num)
         
     if episode is None:
         return None
     
     meta['episode_id'] = episode.id
     meta['tvdb_name'] = self.check(episode.name)
     meta['plot'] = self.check(episode.overview)
     '''if episode.season_number is not None and episode.episode_number is not None:
         meta['plot'] = "Episode: " + episode.season_number + "x" + episode.episode_number + "\n" + meta['plot']
     if episode.first_aired is not None:
         meta['plot'] = "Aired  : " + episode.first_aired + "\n" + meta['plot']
     if episode.name is not None:
         meta['plot'] = episode.name + "\n" + meta['plot']'''
     meta['rating'] = self.check(episode.rating,0)
     meta['aired'] = self.check(episode.first_aired)
     meta['poster'] = self.check(episode.image)
     meta['season_num'] = self.check(episode.season_number,0)
     meta['episode_num'] = self.check(episode.episode_number,0)
     
     print meta
     '''
     show_and_episodes = tvdb.get_show_and_episodes(tvdb_id)
     if show_and_episodes == None:
         return meta
     
     (show, ep_list) = show_and_episodes
     for episode in ep_list:
         print '      S'+ episode.season_number + '.E' + episode.episode_number
         if episode.season_number == season_num and episode.episode_number == episode_num:
             meta['']=''
             break
     '''
     
     return meta
예제 #2
0
파일: models.py 프로젝트: antoviaque/plebia
    def apply_tvdb_updates(self):
        '''Retreives last updates from TVDB and update existing series/seasons/episodes 
        accordingly'''

        from thetvdbapi import TheTVDB
        tvdb = TheTVDB(settings.TVDB_API_KEY)

        try:
            update = TVDBCache.objects.get(type='last')
        except TVDBCache.DoesNotExist:
            server_time = tvdb.get_server_time()
            update = TVDBCache(type='last', time=server_time)
            update.save()
            return False

        log.info("Updating series from TVDB (last update: %s)", update.time)

        (timestamp, series_list, episode_list) = tvdb.get_updates_by_timestamp(update.time)

        # Update series (details, seasons & episodes)
        for series_tvdb_id in series_list:
            try:
                series = Series.objects.get(tvdb_id=series_tvdb_id)
                # Check if this has been downloaded in the past
                if series.is_active():
                    log.info('Applying update to series "%s"', series.name)
                    series.update_from_tvdb()
            except Series.DoesNotExist:
                pass

        # Update individual episodes modifications (not new episodes)
        for episode_tvdb_id in episode_list:
            try:
                episode = Episode.objects.get(tvdb_id=episode_tvdb_id)
                episode_tvdb = tvdb.get_episode(episode_tvdb_id)
                log.info('Applying update to episode "%s s%de%d"', episode.season.series.name, episode.season.number, episode.number)
                episode.update_details(episode_tvdb)
            except Episode.DoesNotExist:
                pass

        # Update timestamp
        update.time = timestamp
        update.save()