def rdAuthorize():
    try:
        CLIENT_ID = 'TC3DG7YFNBKQK'
        USER_AGENT = 'SPECTO for Kodi/1.0'

        if not '' in credentials()['realdebrid'].values():
            if control.yesnoDialog(control.lang(32411).encode('utf-8'), control.lang(32413).encode('utf-8'), '', 'RealDebrid', control.lang(32415).encode('utf-8'), control.lang(32414).encode('utf-8')):
                control.set_setting('realdebrid_client_id','')
                control.set_setting('realdebrid_client_secret', '')
                control.set_setting('realdebrid_token', '')
                control.set_setting('realdebrid_refresh', '')
                control.set_setting('realdebrid_auth', '')
            raise Exception()

        headers = {'User-Agent': USER_AGENT}
        url = 'https://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 = control.lang(30416).encode('utf-8') + '[COLOR skyblue]%s[/COLOR]' % (result['verification_url'])
        user_code = control.lang(30417).encode('utf-8') + '[COLOR skyblue]%s[/COLOR]' % (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 = {'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.set_setting('realdebrid_client_id', id)
        control.set_setting('realdebrid_client_secret', secret)
        control.set_setting('realdebrid_token', token)
        control.set_setting('realdebrid_refresh', refresh)
        control.set_setting('realdebrid_auth', '*************')
        raise Exception()
    except:
        control.openSettings('3.13')
dataset/ETHPy150Open mrknow/filmkodi/plugin.video.specto/resources/lib/resolvers/realdebrid.py/rdAuthorize/original