Esempio n. 1
0
    def auth(self):
        resp = self.get_json('pin/get')
        expiry = pin_ttl = int(resp['expires_in'])
        auth_complete = False
        control.copy2clip(resp['pin'])
        control.progressDialog.create(control.ADDON_NAME + ': AllDebrid Auth',
                                    line1=control.lang(30100).format(control.colorString(resp['base_url'])),
                                    line2=control.lang(30101).format(control.colorString(resp['pin'])),
                                    line3=control.lang(30102))

        # Seems the All Debrid servers need some time do something with the pin before polling
        # Polling to early will cause an invalid pin error
        control.kodi.sleep(5 * 1000)
        control.progressDialog.update(100)
        while not auth_complete and not expiry <= 0 and not control.progressDialog.iscanceled():
            auth_complete, expiry = self.poll_auth(check=resp['check'], pin=resp['pin'])
            progress_percent = 100 - int((float(pin_ttl - expiry) / pin_ttl) * 100)
            control.progressDialog.update(progress_percent)
            control.kodi.sleep(1 * 1000)
        try:
            control.progressDialog.close()
        except:
            pass

        self.store_user_info()

        if auth_complete:
            control.ok_dialog(control.ADDON_NAME, 'AllDebrid {}'.format(control.lang(30103)))
        else:
            return
Esempio n. 2
0
    def auth(self):
        data = {'client_id': self.client_id, 'response_type': 'device_code'}
        token = requests.post('https://www.premiumize.me/token',
                              data=data).json()
        expiry = token['expires_in']
        token_ttl = token['expires_in']
        poll_again = True
        success = False
        control.copy2clip(token['user_code'])
        control.progressDialog.create(
            control.ADDON_NAME,
            line1=control.lang(30100).format(
                control.colorString(token['verification_uri'])),
            line2=control.lang(30101).format(
                control.colorString(token['user_code'])),
            line3=control.lang(30102))
        control.progressDialog.update(0)

        while poll_again and not token_ttl <= 0 and not control.progressDialog.iscanceled(
        ):
            poll_again, success = self.poll_token(token['device_code'])
            progress_percent = 100 - int((float(
                (expiry - token_ttl) / expiry) * 100))
            control.progressDialog.update(progress_percent)
            time.sleep(token['interval'])
            token_ttl -= int(token['interval'])

        control.progressDialog.close()

        if success:
            control.ok_dialog(control.ADDON_NAME,
                              'Premiumize ' + control.lang(30103))
    def auth(self):
        self.ClientSecret = ''
        self.ClientID = 'X245A4XAIBGVM'
        url = ("client_id=%s&new_credentials=yes" % self.ClientID)
        url = self.OauthUrl + self.DeviceCodeUrl % url
        response = json.loads(requests.get(url).text)
        control.copy2clip(response['user_code'])
        control.progressDialog.create(
            'Real-Debrid Auth',
            control.create_multiline_message(
                line1=g.lang(30100).format(
                    g.color_string('https://real-debrid.com/device')),
                line2=g.lang(30101).format(
                    g.color_string(response['user_code'])),
                line3=g.lang(30102),
            ),
        )
        self.OauthTimeout = int(response['expires_in'])
        self.OauthTimeStep = int(response['interval'])
        self.DeviceCode = response['device_code']

        while self.ClientSecret == '':
            self.auth_loop()

        self.token_request()

        user_information = self.get_url(
            'https://api.real-debrid.com/rest/1.0/user')
        if user_information['type'] != 'premium':
            control.ok_dialog(g.ADDON_NAME, g.lang(30104))
Esempio n. 4
0
    def token_request(self):
        if self.ClientSecret is '':
            return

        postData = {'client_id': self.ClientID,
                    'client_secret': self.ClientSecret,
                    'code': self.DeviceCode,
                    'grant_type': 'http://oauth.net/grant_type/device/1.0'}

        url = self.OauthUrl + self.TokenUrl
        response = requests.post(url, data=postData).text
        response = json.loads(response)
        control.setSetting('rd.auth', response['access_token'])
        control.setSetting('rd.refresh', response['refresh_token'])
        self.token = response['access_token']
        self.refresh = response['refresh_token']
        control.setSetting('rd.expiry', str(time.time() + int(response['expires_in'])))
        username = self.get_url('https://api.real-debrid.com/rest/1.0/user')['username']
        control.setSetting('rd.username', username)
        control.ok_dialog(control.ADDON_NAME, 'Real Debrid ' + control.lang(30103))
Esempio n. 5
0
 def auth_loop(self):
     if control.progressDialog.iscanceled():
         control.progressDialog.close()
         return
     time.sleep(self.OauthTimeStep)
     url = "client_id=%s&code=%s" % (self.ClientID, self.DeviceCode)
     url = self.OauthUrl + self.DeviceCredUrl % url
     response = json.loads(requests.get(url).text)
     if 'error' in response:
         return
     else:
         try:
             control.progressDialog.close()
             control.setSetting('rd.client_id', response['client_id'])
             control.setSetting('rd.secret', response['client_secret'])
             self.ClientSecret = response['client_secret']
             self.ClientID = response['client_id']
         except:
             control.ok_dialog(control.ADDON_NAME, control.lang(30105))
         return