Ejemplo n.º 1
0
    def lazy_episode_lookup(self, entry, field):
        try:
            season_offset = entry.get('thetvdb_lookup_season_offset', 0)
            episode_offset = entry.get('thetvdb_lookup_episode_offset', 0)
            if not isinstance(season_offset, int):
                log.error('thetvdb_lookup_season_offset must be an integer')
                season_offset = 0
            if not isinstance(episode_offset, int):
                log.error('thetvdb_lookup_episode_offset must be an integer')
                episode_offset = 0
            if season_offset != 0 or episode_offset != 0:
                log.debug('Using offset for tvdb lookup: season: %s, episode: %s' % (season_offset, episode_offset))

            lookupargs = {'name': entry.get('series_name', eval_lazy=False),
                          'tvdb_id': entry.get('thetvdb_id', eval_lazy=False)}
            if entry['series_id_type'] == 'ep':
                lookupargs['seasonnum'] = entry['series_season'] + season_offset
                lookupargs['episodenum'] = entry['series_episode'] + episode_offset
            elif entry['series_id_type'] == 'sequence':
                lookupargs['absolutenum'] = entry['series_id'] + episode_offset
            elif entry['series_id_type'] == 'date':
                lookupargs['airdate'] = entry['series_date']
            episode = lookup_episode(**lookupargs)
            entry.update_using_map(self.episode_map, episode)
        except LookupError as e:
            log.debug('Error looking up tvdb episode information for %s: %s' % (entry['title'], e.message))
            entry.unregister_lazy_fields(self.episode_map, self.lazy_episode_lookup)

        return entry[field]
Ejemplo n.º 2
0
    def get(self, tvdb_id, session=None):
        args = episode_parser.parse_args()
        air_date = args.get('air_date')
        absolute_num = args.get('absolute_num')
        season_num = args.get('season_num')
        ep_num = args.get('ep_num')

        kwargs = {'tvdb_id': tvdb_id,
                  'session': session}

        if air_date:
            kwargs['airdate'] = air_date
        elif absolute_num:
            kwargs['absolutenum'] = absolute_num
        elif season_num and ep_num:
            kwargs['seasonnum'] = season_num
            kwargs['episodenum'] = ep_num
        else:
            return {'status': 'error',
                    'message': 'not enough parameters sent for lookup'}, 500
        try:
            episode = lookup_episode(**kwargs)
        except LookupError as e:
            return {'status': 'error',
                    'message': e.args[0]
                    }, 404
        return jsonify(episode.to_dict())
Ejemplo n.º 3
0
    def get(self, tvdb_id, session=None):
        args = episode_parser.parse_args()
        absolute_number = args.get('absolute_number')
        season_number = args.get('season_number')
        ep_number = args.get('ep_number')
        if not ((season_number and ep_number) or absolute_number):
            return {'status': 'error',
                    'message': 'not enough parameters for lookup. Either season and episode number or absolute number '
                               'are required.'
                    }, 500

        kwargs = {'tvdb_id': tvdb_id,
                  'session': session}

        if absolute_number:
            kwargs['absolute_number'] = absolute_number
        if season_number and ep_number:
            kwargs['season_number'] = season_number
            kwargs['episode_number'] = ep_number

        try:
            episode = lookup_episode(**kwargs)
        except LookupError as e:
            return {'status': 'error',
                    'message': e.args[0]
                    }, 404
        return jsonify(episode.to_dict())
Ejemplo n.º 4
0
    def get(self, tvdb_id, session=None):
        args = episode_parser.parse_args()
        absolute_number = args.get('absolute_number')
        season_number = args.get('season_number')
        ep_number = args.get('ep_number')
        if not ((season_number and ep_number) or absolute_number):
            return {
                'status':
                'error',
                'message':
                'not enough parameters for lookup. Either season and episode number or absolute number '
                'are required.'
            }, 500

        kwargs = {'tvdb_id': tvdb_id, 'session': session}

        if absolute_number:
            kwargs['absolute_number'] = absolute_number
        if season_number and ep_number:
            kwargs['season_number'] = season_number
            kwargs['episode_number'] = ep_number

        try:
            episode = lookup_episode(**kwargs)
        except LookupError as e:
            return {'status': 'error', 'message': e.args[0]}, 404
        return jsonify(episode.to_dict())
Ejemplo n.º 5
0
    def lazy_episode_lookup(self, entry):
        try:
            season_offset = entry.get('thetvdb_lookup_season_offset', 0)
            episode_offset = entry.get('thetvdb_lookup_episode_offset', 0)
            if not isinstance(season_offset, int):
                log.error('thetvdb_lookup_season_offset must be an integer')
                season_offset = 0
            if not isinstance(episode_offset, int):
                log.error('thetvdb_lookup_episode_offset must be an integer')
                episode_offset = 0
            if season_offset != 0 or episode_offset != 0:
                log.debug('Using offset for tvdb lookup: season: %s, episode: %s' % (season_offset, episode_offset))

            lookupargs = {'name': entry.get('series_name', eval_lazy=False),
                          'tvdb_id': entry.get('tvdb_id', eval_lazy=False)}
            if entry['series_id_type'] == 'ep':
                lookupargs['season_number'] = entry['series_season'] + season_offset
                lookupargs['episode_number'] = entry['series_episode'] + episode_offset
            elif entry['series_id_type'] == 'sequence':
                lookupargs['absolute_number'] = entry['series_id'] + episode_offset
            elif entry['series_id_type'] == 'date':
                # TODO: Should thetvdb_lookup_episode_offset be used for date lookups as well?
                lookupargs['first_aired'] = entry['series_date']

            episode = lookup_episode(**lookupargs)
            entry.update_using_map(self.episode_map, episode)
        except LookupError as e:
            log.debug('Error looking up tvdb episode information for %s: %s' % (entry['title'], e.args[0]))
Ejemplo n.º 6
0
 def lazy_episode_lookup(self, entry, field):
     try:
         episode = lookup_episode(entry.get('series_name', lazy=False), entry['series_season'],
                                  entry['series_episode'], tvdb_id=entry.get('thetvdb_id', lazy=False))
         entry.update_using_map(self.episode_map, episode)
     except LookupError, e:
         log.debug('Error looking up tvdb episode information for %s: %s' % (entry['title'], e.message))
         entry.unregister_lazy_fields(self.episode_map, self.lazy_episode_lookup)
Ejemplo n.º 7
0
    def get(self, tvdb_id, session=None):
        args = episode_parser.parse_args()
        absolute_number = args.get('absolute_number')
        season_number = args.get('season_number')
        ep_number = args.get('ep_number')

        kwargs = {'tvdb_id': tvdb_id, 'session': session}

        if absolute_number:
            kwargs['absolute_number'] = absolute_number
        if season_number and ep_number:
            kwargs['season_number'] = season_number
            kwargs['episode_number'] = ep_number

        try:
            episode = lookup_episode(**kwargs)
        except LookupError as e:
            return {'status': 'error', 'message': e.args[0]}, 404
        return jsonify(episode.to_dict())
Ejemplo n.º 8
0
    def test_mark_expired(self):

        def test_run():
            # Run the task and check tvdb data was populated.
            self.execute_task('test_mark_expired')
            entry = self.task.find_entry(title='House.S02E02.hdtv')
            assert entry['tvdb_ep_name'] == 'Autopsy'

        # Run the task once, this populates data from tvdb
        test_run()
        # Run the task again, this should load the data from cache
        test_run()
        # Manually mark the data as expired, to test cache update
        session = Session()
        ep = lookup_episode(name='House', seasonnum=2, episodenum=2, session=session)
        ep.expired = True
        ep.series.expired = True
        session.commit()
        session.close()
        test_run()
Ejemplo n.º 9
0
    def lazy_episode_lookup(self, entry, field):
        try:
            season_offset = entry.get('thetvdb_lookup_season_offset', 0)
            episode_offset = entry.get('thetvdb_lookup_episode_offset', 0)
            if not isinstance(season_offset, int):
                log.error('thetvdb_lookup_season_offset must be an integer')
                season_offset = 0
            if not isinstance(episode_offset, int):
                log.error('thetvdb_lookup_episode_offset must be an integer')
                episode_offset = 0
            if season_offset != 0 or episode_offset != 0:
                log.debug('Using offset for tvdb lookup: season: %s, episode: %s' % (season_offset, episode_offset))

            episode = lookup_episode(entry.get('series_name', eval_lazy=False),
                                     entry['series_season'] + season_offset,
                                     entry['series_episode'] + episode_offset,
                                     tvdb_id=entry.get('thetvdb_id', eval_lazy=False))
            entry.update_using_map(self.episode_map, episode)
        except LookupError, e:
            log.debug('Error looking up tvdb episode information for %s: %s' % (entry['title'], e.message))
            entry.unregister_lazy_fields(self.episode_map, self.lazy_episode_lookup)
Ejemplo n.º 10
0
    def test_mark_expired(self):
        def test_run():
            # Run the task and check tvdb data was populated.
            self.execute_task('test_mark_expired')
            entry = self.task.find_entry(title='House.S02E02.hdtv')
            assert entry['tvdb_ep_name'] == 'Autopsy'

        # Run the task once, this populates data from tvdb
        test_run()
        # Run the task again, this should load the data from cache
        test_run()
        # Manually mark the data as expired, to test cache update
        session = Session()
        ep = lookup_episode(name='House',
                            seasonnum=2,
                            episodenum=2,
                            session=session)
        ep.expired = True
        ep.series.expired = True
        session.commit()
        session.close()
        test_run()
Ejemplo n.º 11
0
    def get(self, tvdb_id, session=None):
        args = episode_parser.parse_args()
        absolute_number = args.get('absolute_number')
        season_number = args.get('season_number')
        ep_number = args.get('ep_number')

        kwargs = {'tvdb_id': tvdb_id,
                  'session': session}

        if absolute_number:
            kwargs['absolute_number'] = absolute_number
        if season_number and ep_number:
            kwargs['season_number'] = season_number
            kwargs['episode_number'] = ep_number

        try:
            episode = lookup_episode(**kwargs)
        except LookupError as e:
            return {'status': 'error',
                    'message': e.args[0]
                    }, 404
        return jsonify(episode.to_dict())
Ejemplo n.º 12
0
    def lazy_episode_lookup(self, entry):
        try:
            season_offset = entry.get('thetvdb_lookup_season_offset', 0)
            episode_offset = entry.get('thetvdb_lookup_episode_offset', 0)
            if not isinstance(season_offset, int):
                log.error('thetvdb_lookup_season_offset must be an integer')
                season_offset = 0
            if not isinstance(episode_offset, int):
                log.error('thetvdb_lookup_episode_offset must be an integer')
                episode_offset = 0
            if season_offset != 0 or episode_offset != 0:
                log.debug(
                    'Using offset for tvdb lookup: season: %s, episode: %s' %
                    (season_offset, episode_offset))

            lookupargs = {
                'name': entry.get('series_name', eval_lazy=False),
                'tvdb_id': entry.get('tvdb_id', eval_lazy=False)
            }
            if entry['series_id_type'] == 'ep':
                lookupargs[
                    'season_number'] = entry['series_season'] + season_offset
                lookupargs['episode_number'] = entry[
                    'series_episode'] + episode_offset
            elif entry['series_id_type'] == 'sequence':
                lookupargs[
                    'absolute_number'] = entry['series_id'] + episode_offset
            elif entry['series_id_type'] == 'date':
                # TODO: Should thetvdb_lookup_episode_offset be used for date lookups as well?
                lookupargs['first_aired'] = entry['series_date']

            episode = lookup_episode(**lookupargs)
            entry.update_using_map(self.episode_map, episode)
        except LookupError as e:
            log.debug('Error looking up tvdb episode information for %s: %s' %
                      (entry['title'], e.args[0]))