def __getTrakt(url, post=None):
    try:
        url = urlparse.urljoin(BASE_URL, url)
        post = json.dumps(post) if post else None
        headers = {'Content-Type': 'application/json', 'trakt-api-key': V2_API_KEY, 'trakt-api-version': 2}

        if getTraktCredentialsInfo():
            headers.update({'Authorization': 'Bearer %s' % control.setting('trakt.token')})

        result = client.request(url, post=post, headers=headers, output='extended', error=True)

        resp_code = result[1]
        resp_header = result[2]
        result = result[0]

        if resp_code in ['500', '502', '503', '504', '520', '521', '522', '524']:
            log_utils.log('Temporary Trakt Error: %s' % resp_code, log_utils.LOGWARNING)
            return
        elif resp_code in ['404']:
            log_utils.log('Object Not Found : %s' % resp_code, log_utils.LOGWARNING)
            return
#        elif resp_code in ['429']:
#            log_utils.log('Trakt Rate Limit Reached: %s' % resp_code, log_utils.LOGWARNING)
#            return

        if resp_code not in ['401', '405']:
            return result, resp_header

        oauth = urlparse.urljoin(BASE_URL, '/oauth/token')
        opost = {'client_id': V2_API_KEY, 'client_secret': CLIENT_SECRET, 'redirect_uri': REDIRECT_URI, 'grant_type': 'refresh_token', 'refresh_token': control.setting('trakt.refresh')}

        result = client.request(oauth, post=json.dumps(opost), headers=headers)
        result = utils.json_loads_as_str(result)

        token, refresh = result['access_token'], result['refresh_token']

        control.setSetting(id='trakt.token', value=token)
        control.setSetting(id='trakt.refresh', value=refresh)

        headers['Authorization'] = 'Bearer %s' % token

        result = client.request(url, post=post, headers=headers, output='extended', error=True)
        return result[0], result[2]
    except Exception as e:
        log_utils.log('Unknown Trakt Error: %s' % e, log_utils.LOGWARNING)
        pass
Exemple #2
0
def checkRegistery(email=None, userHash=None):

    if email == None:
        return userHash

    if userHash == None:
        query = 'email=%s' % (email)
    else:
        query = 'email=%s&userHash=%s' % (email, userHash)

    url = '%s?%s' % (baseUrl, query)
    headers = {'Authorization': auth}
    result = client.request(url, headers=headers)
    result = json.loads(result)
    userHash = result.get('userHash')
    error = result.get('error')

    control.setSetting(id="userHash", value=userHash)
    return error
Exemple #3
0
 def GetNewMovies(self):
     from cdapl import searchCDA
     import thread_pool
     import time
     self.check_setting = 'false'
     url = 'https://www.cda.pl/video/show/cale_filmy_or_caly_film_or_lektor_or_pl_or_dubbing_or_napisy_or_fps_or_odc/p%d?duration=dlugie&section=&quality=720p&section=&s=date&section='
     if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'):
         try:
             control.infoDialog('Szukam nowych film\xc3\xb3w ...', time=3)
             self.infoDialog = True
         except:
             self.infoDialog = False
     self.progressDialogBG = control.progressDialogBG
     self.progressDialogBG.create('cda.pl','Szukam nowych film\xc3\xb3w ...')
     items=[]
     control.setSetting('library.service.last.run', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
     for stronkaX in range(int(control.setting('library.service.pages') or 1)):
         stronkaX +=1
         printuj_linka('[AddMovie]: Searching cda.pl, page [%d]'%stronkaX)
         nowy_link,next=searchCDA(url%(stronkaX),False,False)
         items.extend(nowy_link)
         self.progressDialogBG.update(0,message='Znalaz\xc5\x82em pozycji [%d] '%(len(items)))
     self.progressDialogBG.update(0,message='Indentyfikuje %d film\xc3\xb3w w %d w\xc4\x85tkach ...'%(len(items),self.fredy))
     items = [x for x in items if x.get('code','')!= '']
     printuj_linka('[AddMovie]: Found Total %d videos ... '%(len(items)))
     pool = thread_pool.ThreadPool(self.fredy)
     self.out=[]
     N=len(items)
     for idx,one in enumerate(items):
         pool.add_task(self.dod_Movies, *(one,idx,N))
         time.sleep(0.1)
     pool.wait_completion()
     printuj_linka('[AddMovie]: (After Threading) Found Total %d Movies ... '%(len(self.out)))
     self.out.reverse()
     self.progressDialogBG.close()
     self.add2( self.out )
     control.setSetting('library.service.last.run', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
Exemple #4
0
 def clearCacheSearch(self):
     control.idle()
     if control.yesnoDialog(control.lang(32056).encode('utf-8'), '', ''):
         control.setSetting('tvsearch', '')
         control.setSetting('moviesearch', '')
         control.refresh()
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')