示例#1
0
    def estimate(self, entry):
        if 'movie_name' not in entry:
            return

        movie_name = entry['movie_name']
        movie_year = entry.get('movie_year')

        if movie_year is not None and movie_year > datetime.datetime.now(
        ).year:
            log.debug('Skipping Blu-ray.com lookup since movie year is %s',
                      movie_year)
            return

        log.debug('Searching Blu-ray.com for release date of {} ({})'.format(
            movie_name, movie_year))

        release_date = None
        try:
            with Session() as session:
                lookup = plugin.get('api_bluray', self).lookup
                movie = lookup(title=movie_name,
                               year=movie_year,
                               session=session)
                if movie:
                    release_date = movie.release_date
        except LookupError as e:
            log.debug(e)
        if release_date:
            log.debug('received release date: {0}'.format(release_date))
        return release_date
示例#2
0
    def get_auth_token(self, refresh=False):
        with Session() as session:
            auth_token = session.query(TVDBTokens).filter(
                TVDBTokens.name == self.auth_key).first()
            if not auth_token:
                auth_token = TVDBTokens()
                auth_token.name = self.auth_key

            if refresh or auth_token.has_expired():
                data = {'apikey': TVDBRequest.API_KEY}
                if self.username:
                    data['username'] = self.username
                if self.account_id:
                    data['userkey'] = self.account_id
                if self.api_key:
                    data['apikey'] = self.api_key

                logger.debug(
                    'Authenticating to TheTVDB with {}',
                    self.username if self.username else 'api_key',
                )

                auth_token.token = (requests.post(
                    TVDBRequest.BASE_URL + 'login',
                    json=data).json().get('token'))
                auth_token.refreshed = datetime.now()
                auth_token = session.merge(auth_token)

            return auth_token.token
示例#3
0
    def estimate(self, entry):
        if 'movie_name' not in entry:
            return

        movie_name = entry['movie_name']
        movie_year = entry.get('movie_year')

        if movie_year is not None and movie_year > datetime.datetime.now(
        ).year:
            logger.debug('Skipping Blu-ray.com lookup since movie year is {}',
                         movie_year)
            return

        logger.debug('Searching Blu-ray.com for release date of {} ({})',
                     movie_name, movie_year)

        entity_data = {'data_exists': True, 'entity_date': None}
        try:
            with Session() as session:
                lookup = plugin.get('api_bluray', self).lookup
                movie = lookup(title=movie_name,
                               year=movie_year,
                               session=session)
                if movie:
                    entity_data['entity_date'] = movie.release_date
        except LookupError as e:
            logger.debug(e)
            entity_data['data_exists'] = False
        if entity_data['entity_date']:
            logger.debug('received release date: {}',
                         entity_data['entity_date'])
        return entity_data
示例#4
0
def action_purge(options):
    with Session() as session:
        regexp_list = get_list_by_exact_name(options.list_name)
        if not regexp_list:
            console('Could not find regexp list with name {}'.format(options.list_name))
            return
        console('Deleting list %s' % options.list_name)
        session.delete(regexp_list)
示例#5
0
def action_del(options):
    with Session() as session:
        regexp_list = get_list_by_exact_name(options.list_name)
        if not regexp_list:
            console('Could not find regexp list with name {}'.format(options.list_name))
            return
        regexp = get_regexp(list_id=regexp_list.id, regexp=options.regexp, session=session)
        if regexp:
            console('Removing regexp {} from list {}'.format(options.regexp, options.list_name))
            session.delete(regexp)
        else:
            console('Could not find regexp {} in list {}'.format(options.movie_title, options.list_name))
            return
示例#6
0
def action_add(options):
    with Session() as session:
        regexp_list = get_list_by_exact_name(options.list_name)
        if not regexp_list:
            console('Could not find regexp list with name {}, creating'.format(options.list_name))
            regexp_list = create_list(options.list_name, session=session)

        regexp = get_regexp(list_id=regexp_list.id, regexp=options.regexp, session=session)
        if not regexp:
            console("Adding regexp {} to list {}".format(options.regexp, regexp_list.name))
            add_to_list_by_name(regexp_list.name, options.regexp, session=session)
            console('Successfully added regexp {} to regexp list {} '.format(options.regexp, regexp_list.name))
        else:
            console("Regexp {} already exists in list {}".format(options.regexp, regexp_list.name))
示例#7
0
文件: cli.py 项目: ksurl/Flexget
def action_list(options):
    """List regexp list"""
    with Session() as session:
        regexp_list = db.get_list_by_exact_name(options.list_name)
        if not regexp_list:
            console('Could not find regexp list with name {}'.format(
                options.list_name))
            return
        table = TerminalTable('Regexp', table_type=options.table_type)
        regexps = db.get_regexps_by_list_id(regexp_list.id,
                                            order_by='added',
                                            descending=True,
                                            session=session)
        for regexp in regexps:
            table.add_row(regexp.regexp or '')
    console(table)
示例#8
0
def action_list(options):
    """List regexp list"""
    with Session() as session:
        regexp_list = get_list_by_exact_name(options.list_name)
        if not regexp_list:
            console('Could not find regexp list with name {}'.format(options.list_name))
            return
        header = ['Regexp']
        table_data = [header]
        regexps = get_regexps_by_list_id(regexp_list.id, order_by='added', descending=True, session=session)
        for regexp in regexps:
            regexp_row = [regexp.regexp or '']
            table_data.append(regexp_row)
        table = TerminalTable(options.table_type, table_data)
        try:
            console(table.output)
        except TerminalTableError as e:
            console('ERROR: %s' % str(e))
示例#9
0
    def estimate(self, entry):
        if 'movie_name' not in entry:
            return

        movie_name = entry['movie_name']
        movie_year = entry.get('movie_year')

        log.debug('Searching Blu-ray.com for release date of {} ({})'.format(movie_name, movie_year))

        release_date = None
        try:
            with Session() as session:
                lookup = get_plugin_by_name('api_bluray').instance.lookup
                movie = lookup(title=movie_name, year=movie_year, session=session)
                if movie:
                    release_date = movie.release_date
        except LookupError as e:
            log.debug(e)
        if release_date:
            log.debug('received release date: {0}'.format(release_date))
        return release_date