Esempio n. 1
0
def importDBFiles():
    status = True
    try:
        dBImportURL = control.setting('databaseImportURL')
        
        # Shows DB file
        fileSource = dBImportURL + 'shows.db' 
        logger.logInfo('Copying %s to %s' % (fileSource, control.showsFile))
        status = True if status is True and logger.logInfo(xbmcvfs.copy(fileSource, control.showsFile)) != 0 else False

        # Episodes DB file
        fileSource = dBImportURL + 'episodes.db' 
        logger.logInfo('Copying %s to %s' % (fileSource, control.episodesFile))
        status = True if status is True and logger.logInfo(xbmcvfs.copy(fileSource, control.episodesFile)) != 0 else False

        # Celebrities DB file
        fileSource = dBImportURL + 'celebrities.db' 
        logger.logInfo('Copying %s to %s' % (fileSource, control.celebritiesFile))
        status = True if status is True and logger.logInfo(xbmcvfs.copy(fileSource, control.celebritiesFile)) != 0 else False
    except:
        status = False
        pass
    if status is True:
        control.setSetting('showUpdateCatalog', 'false')
        control.showNotification(control.lang(57003), control.lang(50010))
    else:
        control.showNotification(control.lang(57027), control.lang(50004))
    return status
Esempio n. 2
0
    def firstInstall(self):
        if control.setting('showWelcomeMessage') == 'true':
            control.showMessage(control.lang(57016), control.lang(57018))
            control.setSetting('showWelcomeMessage', 'false')

        self.addDirectoryItem(control.lang(56025), config.uri.get('base'),
                              config.LOGINWITHTFC, control.addonIcon())
        self.addDirectoryItem(control.lang(56024), config.uri.get('base'),
                              config.LOGINWITHFB, control.facebookIcon())
        self.endDirectory()
Esempio n. 3
0
File: trakt.py Progetto: mpie/repo
def getTrakt(url, post=None):
    try:
        url = urlparse.urljoin('http://api-v2launch.trakt.tv', url)

        headers = {
            'Content-Type': 'application/json',
            'trakt-api-key':
            'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa',
            'trakt-api-version': '2'
        }

        if not post == None: post = json.dumps(post)

        if getTraktCredentialsInfo() == False:
            result = client.request(url, post=post, headers=headers)
            return result

        headers['Authorization'] = 'Bearer %s' % control.setting('trakt.token')

        result = client.request(url,
                                post=post,
                                headers=headers,
                                output='extended',
                                error=True)
        if not (result[1] == '401' or result[1] == '405'): return result[0]

        oauth = 'http://api-v2launch.trakt.tv/oauth/token'
        opost = {
            'client_id':
            'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa',
            'client_secret':
            '90a1840447a1e39d350023263902fe7010338d19789e6260f18df56a8b07a68a',
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'grant_type': 'refresh_token',
            'refresh_token': control.setting('trakt.refresh')
        }

        result = client.request(oauth, post=json.dumps(opost), headers=headers)
        result = json.loads(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)
        return result
    except:
        pass
Esempio n. 4
0
def getTrakt(url, post=None):
    try:
        url = urlparse.urljoin('http://api-v2launch.trakt.tv', url)

        headers = {
            'Content-Type': 'application/json',
            'trakt-api-key': control.trakt_key,
            'trakt-api-version': '2'
        }

        if not post == None: post = json.dumps(post)

        if getTraktCredentialsInfo() == False:
            result = client.request(url, post=post, headers=headers)
            return result

        headers['Authorization'] = 'Bearer %s' % control.setting('trakt.token')

        result = client.request(url,
                                post=post,
                                headers=headers,
                                output='response',
                                error=True)
        if not (result[0] == '401' or result[0] == '405'): return result[1]

        oauth = 'http://api-v2launch.trakt.tv/oauth/token'
        opost = {
            'client_id': control.trakt_key,
            'client_secret': control.trakt_secret,
            'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
            'grant_type': 'refresh_token',
            'refresh_token': control.setting('trakt.refresh')
        }

        result = client.request(oauth, post=json.dumps(opost), headers=headers)
        result = json.loads(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)
        return result
    except:
        pass
Esempio n. 5
0
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
Esempio n. 6
0
 def loginWithTFC(self):
     control.setSetting('loginType', 'TFC.tv')
     if control.setting('emailAddress') == '':
         if control.setting('showEnterCredentials') == 'true':
             self.addDirectoryItem(
                 control.lang(56011), config.uri.get('base'),
                 config.ENTERCREDENTIALS,
                 control.addonFolderIcon(control.lang(56011)))
         # self.addDirectoryItem(control.lang(56012) % (' ' if control.setting('showPersonalize') == 'true' else 'x'), config.uri.get('base'), config.PERSONALIZESETTINGS, control.addonFolderIcon(control.lang(56012)))
         # self.addDirectoryItem(control.lang(56013) % (' ' if control.setting('showUpdateCatalog') == 'true' else 'x'), config.uri.get('base'), config.IMPORTALLDB, control.addonFolderIcon(control.lang(56013)))
         self.addDirectoryItem(
             control.lang(56014) %
             (control.lang(56015) if control.setting('showEnterCredentials')
              == 'true' else control.lang(56016)), config.uri.get('base'),
             config.ENDSETUP, control.addonFolderIcon('Skip'))
         self.endDirectory()
     else:
         self.endSetup()
Esempio n. 7
0
def rdAuthorize():
    try:
        CLIENT_ID = 'MUQMIQX6YWDSU'
        USER_AGENT = 'URLResolver for Kodi'

        headers = {'User-Agent': USER_AGENT}
        url = 'http://api.real-debrid.com/oauth/v2/device/code?client_id=%s&new_credentials=yes' % (CLIENT_ID)
        result = client.request(url, headers=headers)
        result = json.loads(result)
        verification_url = 'Go to URL: %s' % (result['verification_url'])
        user_code = 'When prompted enter: %s' % (result['user_code'])
        device_code = result['device_code']
        interval = result['interval']

        progressDialog = control.progressDialog
        progressDialog.create('RealDebrid', verification_url, user_code)

        for i in range(0, 3600):
            try:
                if progressDialog.iscanceled(): break
                time.sleep(1)
                if not float(i) % interval == 0: raise Exception()
                url = 'https://api.real-debrid.com/oauth/v2/device/credentials?client_id=%s&code=%s' % (CLIENT_ID, device_code)
                result = client.request(url, headers=headers, error=True)
                result = json.loads(result)
                if 'client_secret' in result: break
            except:
                pass

        try: progressDialog.close()
        except: pass

        id, secret = result['client_id'], result['client_secret'] 

        url = 'https://api.real-debrid.com/oauth/v2/token'
        post = urllib.urlencode({'client_id': id, 'client_secret': secret, 'code': device_code, 'grant_type': 'http://oauth.net/grant_type/device/1.0'})

        result = client.request(url, post=post, headers=headers)
        result = json.loads(result)

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

        control.setSetting(id='realdebrid_id', value=id)
        control.setSetting(id='realdebrid_secret', value=secret)
        control.setSetting(id='realdebrid_token', value=token)
        control.setSetting(id='realdebrid_refresh', value=refresh)
    except:
        return
Esempio n. 8
0
def rdAuthorize():
    try:
        CLIENT_ID = 'MUQMIQX6YWDSU'
        USER_AGENT = 'URLResolver for Kodi'

        headers = {'User-Agent': USER_AGENT}
        url = 'http://api.real-debrid.com/oauth/v2/device/code?client_id=%s&new_credentials=yes' % (CLIENT_ID)
        result = client.request(url, headers=headers)
        result = json.loads(result)
        verification_url = 'Go to URL: %s' % (result['verification_url'])
        user_code = 'When prompted enter: %s' % (result['user_code'])
        device_code = result['device_code']
        interval = result['interval']

        progressDialog = control.progressDialog
        progressDialog.create('RealDebrid', verification_url, user_code)

        for i in range(0, 3600):
            try:
                if progressDialog.iscanceled(): break
                time.sleep(1)
                if not float(i) % interval == 0: raise Exception()
                url = 'https://api.real-debrid.com/oauth/v2/device/credentials?client_id=%s&code=%s' % (CLIENT_ID, device_code)
                result = client.request(url, headers=headers, error=True)
                result = json.loads(result)
                if 'client_secret' in result: break
            except:
                pass

        try: progressDialog.close()
        except: pass

        id, secret = result['client_id'], result['client_secret'] 

        url = 'https://api.real-debrid.com/oauth/v2/token'
        post = urllib.urlencode({'client_id': id, 'client_secret': secret, 'code': device_code, 'grant_type': 'http://oauth.net/grant_type/device/1.0'})

        result = client.request(url, post=post, headers=headers)
        result = json.loads(result)

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

        control.setSetting(id='realdebrid_id', value=id)
        control.setSetting(id='realdebrid_secret', value=secret)
        control.setSetting(id='realdebrid_token', value=token)
        control.setSetting(id='realdebrid_refresh', value=refresh)
    except:
        return
Esempio n. 9
0
 def firstInstall(self):
     self.addDirectoryItem(
         control.lang(56011) %
         (' '
          if control.setting('showEnterCredentials') == 'true' else 'x'),
         config.uri.get('base'), config.ENTERCREDENTIALS,
         control.addonFolderIcon(control.lang(56011)))
     self.addDirectoryItem(
         control.lang(56012) %
         (' ' if control.setting('showPersonalize') == 'true' else 'x'),
         config.uri.get('base'), config.PERSONALIZESETTINGS,
         control.addonFolderIcon(control.lang(56012)))
     # self.addDirectoryItem(control.lang(56013) % (' ' if control.setting('showUpdateCatalog') == 'true' else 'x'), config.uri.get('base'), config.IMPORTALLDB, control.addonFolderIcon(control.lang(56013)))
     self.addDirectoryItem(
         control.lang(56014) %
         (control.lang(56015) if control.setting('showEnterCredentials')
          == 'true' or control.setting('showPersonalize') == 'true' else
          control.lang(56016)), config.uri.get('base'), config.ENDSETUP,
         control.addonFolderIcon('Skip'))
     self.endDirectory()
     if control.setting('showWelcomeMessage') == 'true':
         control.showMessage(control.lang(57016), control.lang(57018))
         control.setSetting('showWelcomeMessage', 'false')
Esempio n. 10
0
def getTrakt(url, post=None):
    try:
        url = urlparse.urljoin('http://api-v2launch.trakt.tv', url)

        headers = {'Content-Type': 'application/json', 'trakt-api-key': control.trakt_key, 'trakt-api-version': '2'}

        if not post == None: post = json.dumps(post)


        if getTraktCredentialsInfo() == False:
            result = client.request(url, post=post, headers=headers)
            return result


        headers['Authorization'] = 'Bearer %s' % control.setting('trakt.token')

        result = client.request(url, post=post, headers=headers, output='response', error=True)
        if not (result[0] == '401' or result[0] == '405'): return result[1]


        oauth = 'http://api-v2launch.trakt.tv/oauth/token'
        opost = {'client_id': control.trakt_key , 'client_secret': control.trakt_secret, 'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 'grant_type': 'refresh_token', 'refresh_token': control.setting('trakt.refresh')}

        result = client.request(oauth, post=json.dumps(opost), headers=headers)
        result = json.loads(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)
        return result
    except:
        pass
Esempio n. 11
0
File: trakt.py Progetto: mpie/repo
def getTrakt(url, post=None):
    try:
        url = urlparse.urljoin('http://api-v2launch.trakt.tv', url)

        headers = {'Content-Type': 'application/json', 'trakt-api-key': 'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa', 'trakt-api-version': '2'}

        if not post == None: post = json.dumps(post)


        if getTraktCredentialsInfo() == False:
            result = client.request(url, post=post, headers=headers)
            return result


        headers['Authorization'] = 'Bearer %s' % control.setting('trakt.token')

        result = client.request(url, post=post, headers=headers, output='extended', error=True)
        if not (result[1] == '401' or result[1] == '405'): return result[0]


        oauth = 'http://api-v2launch.trakt.tv/oauth/token'
        opost = {'client_id': 'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa', 'client_secret': '90a1840447a1e39d350023263902fe7010338d19789e6260f18df56a8b07a68a', 'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 'grant_type': 'refresh_token', 'refresh_token': control.setting('trakt.refresh')}

        result = client.request(oauth, post=json.dumps(opost), headers=headers)
        result = json.loads(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)
        return result
    except:
        pass
Esempio n. 12
0
 def endSetup(self):
     control.setSetting('addonNewInstall', 'false')
     # control.refresh()
     self.showMainMenu()
Esempio n. 13
0
 def personalizeSettings(self):
     control.openSettings()
     control.setSetting('showPersonalize', 'false')
     control.refresh()
Esempio n. 14
0
 def optimizeLibrary(self):
     gmatv.reloadCatalogCache()
     control.setSetting('showUpdateCatalog', 'false')
     control.refresh()
Esempio n. 15
0
 def enterCredentials(self):
     if gmatv.enterCredentials() == True:
         control.setSetting('showEnterCredentials', 'false')
         self.endSetup()
Esempio n. 16
0
def authTrakt():
    try:
        if getTraktCredentialsInfo() == True:
            if control.yesnoDialog(control.lang(30479).encode('utf-8'), control.lang(30481).encode('utf-8'), '', 'Trakt', control.lang(30483).encode('utf-8'), control.lang(30482).encode('utf-8')):
                control.setSetting(id='trakt.user', value='')
                control.setSetting(id='trakt.token', value='')
                control.setSetting(id='trakt.refresh', value='')
            raise Exception()

        result = getTrakt('/oauth/device/code', {'client_id': control.trakt_key })
        result = json.loads(result)
        verification_url = (control.lang(30416) + '[COLOR skyblue]%s[/COLOR]' % result['verification_url']).encode('utf-8')
        user_code = (control.lang(30417) + '[COLOR skyblue]%s[/COLOR]' % 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 = getTrakt('/oauth/device/token', {'client_id': control.trakt_key , 'client_secret': control.trakt_secret, 'code': device_code})
                r = json.loads(r)
                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': control.trakt_key , 'trakt-api-version': '2', 'Authorization': 'Bearer %s' % token}

        result = client.request('http://api-v2launch.trakt.tv/users/me', headers=headers)
        result = json.loads(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('3.1')
Esempio n. 17
0
File: trakt.py Progetto: mpie/repo
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 = getTrakt('/oauth/device/code', {'client_id': 'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa'})
        result = json.loads(result)
        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 = getTrakt('/oauth/device/token', {'client_id': 'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa', 'client_secret': '90a1840447a1e39d350023263902fe7010338d19789e6260f18df56a8b07a68a', 'code': device_code})
                r = json.loads(r)
                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': 'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa', 'trakt-api-version': '2', 'Authorization': 'Bearer %s' % token}

        result = client.request('http://api-v2launch.trakt.tv/users/me', headers=headers)
        result = json.loads(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('3.1')
Esempio n. 18
0
 def enterCredentials(self):
     tfctv.enterCredentials()
     control.setSetting('showEnterCredentials', 'false')
     control.refresh()
Esempio n. 19
0
def upgradeSettings():
    if control.addonInfo('version') == '1.5.0': 
        control.setSetting('proxyStreamingUrl', 'http://%s:%s/?url=%s%s')
        control.showMessage(control.lang(57047), control.lang(50002))
Esempio n. 20
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('3.1')
Esempio n. 21
0
image = params.get('image')

caller = params.get('caller', 'addon')

thumbnail = urllib.unquote_plus(params.get('thumbnail', ''))

# if caller == 'addon' and control.setting('addonNewInstall') == 'true' and control.setting('lastVersion') != control.addonInfo('version'):
if caller == 'addon' and control.setting('lastVersion') != control.addonInfo(
        'version'):
    from resources import upgrade
    control.showMessage(
        control.lang(57023) % control.addonInfo('version'),
        control.lang(50002))
    upgrade.upgradeDB()
    upgrade.upgradeSettings()
    control.setSetting('lastVersion', control.addonInfo('version'))

if mode == None:
    from resources.lib.indexers import navigator
    navigator.navigator().root()
elif mode == config.SUBCATEGORIES:
    from resources.lib.indexers import navigator
    navigator.navigator().showSubCategories(url)
elif mode == config.SUBCATEGORYSHOWS:
    from resources.lib.indexers import navigator
    navigator.navigator().showSubCategoryShows(url)
elif mode == config.SHOWEPISODES:
    from resources.lib.indexers import navigator
    navigator.navigator().showEpisodes(url, page, params.get('parentid', -1),
                                       params.get('year', ''))
elif mode == config.CHOOSEBANDWIDTH:
Esempio n. 22
0
File: trakt.py Progetto: mpie/repo
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 = getTrakt(
            '/oauth/device/code', {
                'client_id':
                'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa'
            })
        result = json.loads(result)
        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 = getTrakt(
                    '/oauth/device/token', {
                        'client_id':
                        'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa',
                        'client_secret':
                        '90a1840447a1e39d350023263902fe7010338d19789e6260f18df56a8b07a68a',
                        'code': device_code
                    })
                r = json.loads(r)
                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':
            'c029c80fd3d3a5284ee820ba1cf7f0221da8976b8ee5e6c4af714c22fc4f46fa',
            'trakt-api-version': '2',
            'Authorization': 'Bearer %s' % token
        }

        result = client.request('http://api-v2launch.trakt.tv/users/me',
                                headers=headers)
        result = json.loads(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('3.1')
Esempio n. 23
0
def rdAuthorize():
    try:
        CLIENT_ID = "MUQMIQX6YWDSU"
        USER_AGENT = "URLResolver for Kodi"

        headers = {"User-Agent": USER_AGENT}
        url = "http://api.real-debrid.com/oauth/v2/device/code?client_id=%s&new_credentials=yes" % (CLIENT_ID)
        result = client.request(url, headers=headers)
        result = json.loads(result)
        verification_url = "Go to URL: %s" % (result["verification_url"])
        user_code = "When prompted enter: %s" % (result["user_code"])
        device_code = result["device_code"]
        interval = result["interval"]

        progressDialog = control.progressDialog
        progressDialog.create("RealDebrid", verification_url, user_code)

        for i in range(0, 3600):
            try:
                if progressDialog.iscanceled():
                    break
                time.sleep(1)
                if not float(i) % interval == 0:
                    raise Exception()
                url = "https://api.real-debrid.com/oauth/v2/device/credentials?client_id=%s&code=%s" % (
                    CLIENT_ID,
                    device_code,
                )
                result = client.request(url, headers=headers, error=True)
                result = json.loads(result)
                if "client_secret" in result:
                    break
            except:
                pass

        try:
            progressDialog.close()
        except:
            pass

        id, secret = result["client_id"], result["client_secret"]

        url = "https://api.real-debrid.com/oauth/v2/token"
        post = urllib.urlencode(
            {
                "client_id": id,
                "client_secret": secret,
                "code": device_code,
                "grant_type": "http://oauth.net/grant_type/device/1.0",
            }
        )

        result = client.request(url, post=post, headers=headers)
        result = json.loads(result)

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

        control.setSetting(id="realdebrid_id", value=id)
        control.setSetting(id="realdebrid_secret", value=secret)
        control.setSetting(id="realdebrid_token", value=token)
        control.setSetting(id="realdebrid_refresh", value=refresh)
    except:
        return
Esempio n. 24
0
 def endSetup(self):
     control.setSetting('addonNewInstall', 'false')
     control.refresh()
Esempio n. 25
0
def authTrakt():
    try:
        if getTraktCredentialsInfo() == True:
            if control.yesnoDialog(
                    control.lang(30479).encode('utf-8'),
                    control.lang(30481).encode('utf-8'), '', 'Trakt',
                    control.lang(30483).encode('utf-8'),
                    control.lang(30482).encode('utf-8')):
                control.setSetting(id='trakt.user', value='')
                control.setSetting(id='trakt.token', value='')
                control.setSetting(id='trakt.refresh', value='')
            raise Exception()

        result = getTrakt('/oauth/device/code',
                          {'client_id': control.trakt_key})
        result = json.loads(result)
        verification_url = (control.lang(30416) + '[COLOR skyblue]%s[/COLOR]' %
                            result['verification_url']).encode('utf-8')
        user_code = (
            control.lang(30417) +
            '[COLOR skyblue]%s[/COLOR]' % 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 = getTrakt(
                    '/oauth/device/token', {
                        'client_id': control.trakt_key,
                        'client_secret': control.trakt_secret,
                        'code': device_code
                    })
                r = json.loads(r)
                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': control.trakt_key,
            'trakt-api-version': '2',
            'Authorization': 'Bearer %s' % token
        }

        result = client.request('http://api-v2launch.trakt.tv/users/me',
                                headers=headers)
        result = json.loads(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('3.1')
Esempio n. 26
0
 def loginWithFB(self):
     control.setSetting('loginType', 'Facebook')
     self.endSetup()