示例#1
0
    def ignoreView(self, imdb = None, **kwargs):

        ignored = splitString(Env.prop('charts_ignore', default = ''))

        if imdb:
            ignored.append(imdb)
            Env.prop('charts_ignore', ','.join(set(ignored)))

        return {
            'result': True
        }
示例#2
0
    def getCredentials(self, **kwargs):
        try:
            oauth_token = kwargs.get('oauth')
            refresh_token = kwargs.get('refresh')

            log.debug('oauth_token is: %s', oauth_token)
            self.conf('automation_oauth_token', value = oauth_token)
            self.conf('automation_oauth_refresh', value = refresh_token)

            Env.prop('last_trakt_refresh', value = int(time.time()))
        except:
            log.error('Failed setting trakt token: %s', traceback.format_exc())

        return 'redirect', Env.get('web_base') + 'settings/automation/'
示例#3
0
    def automationView(self, force_update = False, **kwargs):

        db = get_db()

        charts = fireEvent('automation.get_chart_list', merge = True)
        ignored = splitString(Env.prop('charts_ignore', default = ''))

        # Create a list the movie/list.js can use
        for chart in charts:
            medias = []
            for media in chart.get('list', []):

                identifier = media.get('imdb')
                if identifier in ignored:
                    continue

                try:
                    try:
                        in_library = db.get('media', 'imdb-%s' % identifier)
                        if in_library:
                            continue
                    except RecordNotFound:
                        pass
                except:
                    pass

                # Cache poster
                posters = media.get('images', {}).get('poster', [])
                poster = [x for x in posters if 'tmdb' in x]
                posters = poster if len(poster) > 0 else posters

                cached_poster = fireEvent('file.download', url = posters[0], single = True) if len(posters) > 0 else False
                files = {'image_poster': [cached_poster] } if cached_poster else {}

                medias.append({
                    'status': 'chart',
                    'title': getTitle(media),
                    'type': 'movie',
                    'info': media,
                    'files': files,
                    'identifiers': {
                        'imdb': identifier
                    }
                })

            chart['list'] = medias

        return {
            'success': True,
            'count': len(charts),
            'charts': charts,
            'ignored': ignored,
        }
示例#4
0
    def refreshToken(self):

        token = self.conf('automation_oauth_token')
        refresh_token = self.conf('automation_oauth_refresh')
        if token and refresh_token:

            prop_name = 'last_trakt_refresh'
            last_refresh = int(Env.prop(prop_name, default = 0))

            if last_refresh < time.time()-4838400:  # refresh every 8 weeks
                log.debug('Refreshing trakt token')

                url = self.urls['refresh_token'] + '?token=' + self.conf('automation_oauth_refresh')
                data = fireEvent('cp.api_call', url, cache_timeout = 0, single = True)
                if data and 'oauth' in data and 'refresh' in data:
                    log.debug('Oauth refresh: %s', data)
                    self.conf('automation_oauth_token', value = data.get('oauth'))
                    self.conf('automation_oauth_refresh', value = data.get('refresh'))
                    Env.prop(prop_name, value = int(time.time()))
                else:
                    log.error('Failed refreshing Trakt token, please re-register in settings')

        elif token and not refresh_token:
            log.error('Refresh token is missing, please re-register Trakt for autorefresh of the token in the future')