示例#1
0
def authTrakt():
    try:
        if getTraktCredentialsInfo() == True:
            if control.yesnoDialog(
                    control.lang(32511).encode('utf-8'),
                    control.lang(32512).encode('utf-8'), '', 'Trakt'):
                control.setSetting(id='trakt.user', value='')
                control.setSetting(id='trakt.token', value='')
                control.setSetting(id='trakt.refresh', value='')
            raise Exception()
        result = getTraktAsJson('/oauth/device/code',
                                {'client_id': V2_API_KEY})
        verification_url = (control.lang(32513) %
                            result['verification_url']).encode('utf-8')
        user_code = (control.lang(32514) % result['user_code']).encode('utf-8')
        expires_in = int(result['expires_in'])
        device_code = result['device_code']
        interval = result['interval']
        progressDialog = control.progressDialog
        progressDialog.create('Trakt', verification_url, user_code)
        for i in range(0, expires_in):
            try:
                if progressDialog.iscanceled(): break
                time.sleep(1)
                if not float(i) % interval == 0: raise Exception()
                r = getTraktAsJson(
                    '/oauth/device/token', {
                        'client_id': V2_API_KEY,
                        'client_secret': CLIENT_SECRET,
                        'code': device_code
                    })
                if 'access_token' in r: break
            except:
                pass
        try:
            progressDialog.close()
        except:
            pass
        token, refresh = r['access_token'], r['refresh_token']
        headers = {
            'Content-Type': 'application/json',
            'trakt-api-key': V2_API_KEY,
            'trakt-api-version': 2,
            'Authorization': 'Bearer %s' % token
        }
        result = client.request(urlparse.urljoin(BASE_URL, '/users/me'),
                                headers=headers)
        result = utils.json_loads_as_str(result)
        user = result['username']
        control.setSetting(id='trakt.user', value=user)
        control.setSetting(id='trakt.token', value=token)
        control.setSetting(id='trakt.refresh', value=refresh)
        raise Exception()
    except:
        control.openSettings('4.1')
示例#2
0
    def resolve(self, url):
        try:
            url = client.request(urlparse.urljoin(self.base_link, url),
                                 output='geturl')
            if self.base_link not in url:
                return url

            header = {'User-Agent': self.user_agent, 'Accept': 'text/html'}

            self.__login()
            cookie = self.cookie

            try:
                res = client.request(url,
                                     headers=header,
                                     cookie=cookie,
                                     redirect=False,
                                     output='geturl')
                if self.base_link not in res:
                    url = res
                else:
                    control.infoDialog(control.lang(32572).encode('utf-8'),
                                       sound=True,
                                       icon='WARNING')
            except:
                return

            return url
        except:
            return
示例#3
0
def cache_version_check():
    if _find_cache_version():
        cache_clear()
        cache_clear_meta()
        cache_clear_providers()
        control.infoDialog(control.lang(32057).encode('utf-8'),
                           sound=True,
                           icon='INFO')
示例#4
0
def manager(name, imdb, tvdb, content):
    try:
        post = {
            "movies": [{
                "ids": {
                    "imdb": imdb
                }
            }]
        } if content == 'movie' else {
            "shows": [{
                "ids": {
                    "tvdb": tvdb
                }
            }]
        }
        items = [(control.lang(32516).encode('utf-8'), '/sync/collection')]
        items += [(control.lang(32517).encode('utf-8'),
                   '/sync/collection/remove')]
        items += [(control.lang(32518).encode('utf-8'), '/sync/watchlist')]
        items += [(control.lang(32519).encode('utf-8'),
                   '/sync/watchlist/remove')]
        items += [(control.lang(32520).encode('utf-8'),
                   '/users/me/lists/%s/items')]
        result = getTraktAsJson('/users/me/lists')
        lists = [(i['name'], i['ids']['slug']) for i in result]
        lists = [lists[i // 2] for i in range(len(lists) * 2)]
        for i in range(0, len(lists), 2):
            lists[i] = ((control.lang(32521) % lists[i][0]).encode('utf-8'),
                        '/users/me/lists/%s/items' % lists[i][1])
        for i in range(1, len(lists), 2):
            lists[i] = ((control.lang(32522) % lists[i][0]).encode('utf-8'),
                        '/users/me/lists/%s/items/remove' % lists[i][1])
        items += lists
        select = control.selectDialog([i[0] for i in items],
                                      control.lang(32515).encode('utf-8'))
        if select == -1:
            return
        elif select == 4:
            t = control.lang(32520).encode('utf-8')
            k = control.keyboard('', t)
            k.doModal()
            new = k.getText() if k.isConfirmed() else None
            if (new == None or new == ''): return
            result = __getTrakt('/users/me/lists',
                                post={
                                    "name": new,
                                    "privacy": "private"
                                })[0]
            try:
                slug = utils.json_loads_as_str(result)['ids']['slug']
            except:
                return control.infoDialog(control.lang(32515).encode('utf-8'),
                                          heading=str(name),
                                          sound=True,
                                          icon='ERROR')
            result = __getTrakt(items[select][1] % slug, post=post)[0]
        else:
            result = __getTrakt(items[select][1], post=post)[0]
        icon = control.infoLabel(
            'ListItem.Icon') if not result == None else 'ERROR'
        control.infoDialog(control.lang(32515).encode('utf-8'),
                           heading=str(name),
                           sound=True,
                           icon=icon)
    except:
        return