Beispiel #1
0
 def revoke(self):
     try:
         control.setSetting('premiumize.token', '')
         control.setSetting('premiumize.username', '')
         control.dialog.ok(control.lang(40057), control.lang(32314))
     except:
         log_utils.error()
Beispiel #2
0
 def auth(self):
     data = {'client_id': CLIENT_ID, 'response_type': 'device_code'}
     token = requests.post('https://www.premiumize.me/token',
                           data=data,
                           timeout=15).json()
     expiry = float(token['expires_in'])
     token_ttl = token['expires_in']
     poll_again = True
     success = False
     progressDialog = control.progressDialog
     progressDialog.create(
         control.lang(40054), control.progress_line %
         (control.lang(32513) % token['verification_uri'],
          control.lang(32514) % token['user_code'], ''))
     progressDialog.update(0)
     while poll_again and not token_ttl <= 0 and not progressDialog.iscanceled(
     ):
         poll_again, success = self.poll_token(token['device_code'])
         progress_percent = 100 - int((float(
             (expiry - token_ttl) / expiry) * 100))
         progressDialog.update(progress_percent)
         control.sleep(token['interval'] * 1000)
         token_ttl -= int(token['interval'])
     progressDialog.close()
     if success:
         control.notification(title=40057, message=40081, icon=pm_icon)
Beispiel #3
0
	def get_device_token(self, device_codes):
		try:
			data = {"code": device_codes["device_code"],
					"client_id": self.client_id,
					"client_secret": self.client_secret}
			start = time.time()
			expires_in = device_codes['expires_in']
			verification_url = control.lang(32513) % str(device_codes['verification_url'])
			user_code = control.lang(32514) % str(device_codes['user_code'])
			control.progressDialog.create(control.lang(32073), control.progress_line % (verification_url, user_code, ''))
			try:
				time_passed = 0
				while not control.progressDialog.iscanceled() and time_passed < expires_in:
					try:
						response = self.call("oauth/device/token", data=data, with_auth=False, suppress_error_notification=True)
					except requests.HTTPError as e:
						log_utils.log('Request Error: %s' % str(e), __name__, log_utils.LOGDEBUG)
						if e.response.status_code != 400: raise e
						progress = int(100 * time_passed / expires_in)
						control.progressDialog.update(progress)
						control.sleep(max(device_codes['interval'], 1)*1000)
					else:
						if not response: continue
						else: return response
					time_passed = time.time() - start
			finally:
				control.progressDialog.close()
			return None
		except:
			log_utils.error()
Beispiel #4
0
    def auth(self):
        self.secret = ''
        self.client_ID = 'X245A4XAIBGVM'
        url = 'client_id=%s&new_credentials=yes' % self.client_ID
        url = oauth_base_url + device_code_url % url
        response = json.loads(requests.get(url).text)
        control.progressDialog.create(control.lang(40055))
        control.progressDialog.update(
            -1, control.progress_line %
            (control.lang(32513) % 'https://real-debrid.com/device',
             control.lang(32514) % response['user_code'], ''))

        self.auth_timeout = int(response['expires_in'])
        self.auth_step = int(response['interval'])
        self.device_code = response['device_code']

        while self.secret == '':
            if control.progressDialog.iscanceled():
                control.progressDialog.close()
                break
            self.auth_loop()
        if self.secret:
            if self.get_token():
                control.notification(title=40058, message=40081, icon=rd_icon)
            else:
                return control.okDialog(title='default',
                                        message=control.lang(40019))
Beispiel #5
0
 def revoke(self):
     try:
         control.setSetting('alldebrid.username', '')
         control.setSetting('alldebrid.token', '')
         control.dialog.ok(control.lang(40059), control.lang(32314))
     except:
         log_utils.error()
Beispiel #6
0
	def revoke(self):
		data = {"token": control.setting('trakt.token')}
		try: self.call("oauth/revoke", data=data, with_auth=False)
		except: pass
		control.setSetting('trakt.username', '')
		control.setSetting('trakt.expires', '')
		control.setSetting('trakt.token', '')
		control.setSetting('trakt.refresh', '')
		control.dialog.ok(control.lang(32315), control.lang(32314))
Beispiel #7
0
 def revoke(self):
     try:
         control.setSetting('realdebrid.client_id', '')
         control.setSetting('realdebrid.secret', '')
         control.setSetting('realdebrid.token', '')
         control.setSetting('realdebrid.refresh', '')
         control.setSetting('realdebrid.username', '')
         control.dialog.ok(control.lang(40058), control.lang(32314))
     except:
         log_utils.error()
Beispiel #8
0
 def poll_token(self, device_code):
     data = {
         'client_id': CLIENT_ID,
         'code': device_code,
         'grant_type': 'device_code'
     }
     token = requests.post('https://www.premiumize.me/token',
                           data=data,
                           timeout=15).json()
     if 'error' in token:
         if token['error'] == "access_denied":
             control.okDialog(title='default', message=control.lang(40020))
             return False, False
         return True, False
     self.token = token['access_token']
     self.headers = {
         'User-Agent': 'My Accounts for Kodi',
         'Authorization': 'Bearer %s' % self.token
     }
     control.sleep(500)
     account_info = self.account_info()
     control.setSetting('premiumize.token', token['access_token'])
     control.setSetting('premiumize.username',
                        str(account_info['customer_id']))
     return False, True
	def auth(self):
		self.token = ''
		url = base_url + 'pin/get?agent=%s' % user_agent
		response = requests.get(url, timeout=self.timeout).json()
		response = response['data']
		control.progressDialog.create(control.lang(40056))
		control.progressDialog.update(-1, control.progress_line % (control.lang(32513) % 'https://alldebrid.com/pin/', control.lang(32514) % response['pin'], ''))
		self.check_url = response.get('check_url')
		control.sleep(2000)
		while not self.token:
			if control.progressDialog.iscanceled():
				control.progressDialog.close()
				break
			self.auth_loop()
		if self.token in (None, '', 'failed'):
			return
		control.sleep(2000)
		account_info = self.account_info()
		control.setSetting('alldebrid.username', str(account_info['user']['username']))
		control.notification(title=40059, message=40081, icon=ad_icon)
 def account_info_to_dialog(self):
     from datetime import datetime
     import math
     try:
         accountInfo = self.account_info()
         expires = datetime.fromtimestamp(accountInfo['premium_until'])
         days_remaining = (expires - datetime.today()).days
         expires = expires.strftime("%A, %B %d, %Y")
         points_used = int(
             math.floor(float(accountInfo['space_used']) / 1073741824.0))
         space_used = float(int(accountInfo['space_used'])) / 1073741824
         percentage_used = str(
             round(float(accountInfo['limit_used']) * 100.0, 1))
         items = []
         items += [control.lang(40040) % accountInfo['customer_id']]
         items += [control.lang(40041) % expires]
         items += [control.lang(40042) % days_remaining]
         items += [control.lang(40043) % points_used]
         items += [control.lang(40044) % space_used]
         items += [control.lang(40045) % percentage_used]
         return control.selectDialog(items, 'Premiumize')
     except:
         log_utils.error()
         pass
     return
 def account_info_to_dialog(self):
     from datetime import datetime
     import time
     try:
         userInfo = self.account_info()
         try:
             expires = datetime.strptime(userInfo['expiration'],
                                         FormatDateTime)
         except:
             expires = datetime(*(time.strptime(userInfo['expiration'],
                                                FormatDateTime)[0:6]))
         days_remaining = (expires - datetime.today()).days
         expires = expires.strftime("%A, %B %d, %Y")
         items = []
         items += [control.lang(40035) % userInfo['email']]
         items += [control.lang(40036) % userInfo['username']]
         items += [control.lang(40037) % userInfo['type'].capitalize()]
         items += [control.lang(40041) % expires]
         items += [control.lang(40042) % days_remaining]
         items += [control.lang(40038) % userInfo['points']]
         return control.selectDialog(items, 'Real-Debrid')
     except:
         log_utils.error()
         pass
     return
Beispiel #12
0
def upload_LogFile():
    from myaccounts.modules.control import notification
    url = 'https://paste.kodi.tv/'
    log_file = joinPath(LOGPATH, 'myaccounts.log')
    if not existsPath(log_file):
        return notification(
            message='Log File not found, likely logging is not enabled.')
    try:
        import requests
        from myaccounts.modules.control import addonVersion, selectDialog
        f = open(log_file, 'r', encoding='utf-8', errors='ignore')
        text = f.read()
        f.close()
        UserAgent = 'MyAccounts %s' % addonVersion()
        response = requests.post(url + 'documents',
                                 data=text.encode('utf-8', errors='ignore'),
                                 headers={'User-Agent': UserAgent})
        # log('log_response: ' + str(response))
        if 'key' in response.json():
            result = url + response.json()['key']
            log('My Accounts log file uploaded to: %s' % result)
            from sys import platform as sys_platform
            supported_platform = any(value in sys_platform
                                     for value in ['win32', 'linux2'])
            highlight_color = 'gold'
            list = [
                ('[COLOR %s]url:[/COLOR]  %s' % (highlight_color, str(result)),
                 str(result))
            ]
            if supported_platform:
                list += [('[COLOR %s]  -- Copy url To Clipboard[/COLOR]' %
                          highlight_color, ' ')]
            select = selectDialog([i[0] for i in list], lang(32349))
            if 'Copy url To Clipboard' in list[select][0]:
                copy2clip(list[select - 1][1])
        elif 'message' in response.json():
            notification(message='myaccounts Log upload failed: %s' %
                         str(response.json()['message']))
            log('My Accounts Log upload failed: %s' %
                str(response.json()['message']),
                level=LOGERROR)
        else:
            notification(message='myaccounts Log upload failed')
            log('My Accounts Log upload failed: %s' % response.text,
                level=LOGERROR)
    except:
        error('My Accounts log upload failed')
        notification(message='pastebin post failed: See log for more info')
Beispiel #13
0
 def auth_loop(self):
     control.sleep(self.auth_step * 1000)
     url = 'client_id=%s&code=%s' % (self.client_ID, self.device_code)
     url = oauth_base_url + credentials_url % url
     response = json.loads(requests.get(url).text)
     if 'error' in response:
         return  #
     else:
         try:
             control.progressDialog.close()
             self.client_ID = response['client_id']
             self.secret = response['client_secret']
         except:
             log_utils.error()
             control.okDialog(title='default', message=control.lang(40019))
         return
Beispiel #14
0
def clear_logFile():
    cleared = False
    try:
        from myaccounts.modules.control import yesnoDialog
        if not yesnoDialog(lang(32074), '', ''): return 'canceled'
        log_file = joinPath(LOGPATH, 'myaccounts.log')
        if not existsPath(log_file):
            f = open(log_file, 'w')
            return f.close()
        f = open(log_file, 'r+')
        f.truncate(0)  # need '0' when using r
        f.close()
        cleared = True
    except Exception as e:
        import xbmc
        xbmc.log(
            '[ script.module.myaccounts ] log_utils.clear_logFile() Failure: %s'
            % (e), LOGERROR)
        cleared = False
    return cleared
Beispiel #15
0
 def account_info_to_dialog(self):
     from datetime import datetime
     try:
         account_info = self.account_info()['user']
         username = account_info['username']
         email = account_info['email']
         status = 'Premium' if account_info['isPremium'] else 'Not Active'
         expires = datetime.fromtimestamp(account_info['premiumUntil'])
         days_remaining = (expires - datetime.today()).days
         heading = control.lang(40059).upper()
         items = []
         items += [control.lang(40036) % username]
         items += [control.lang(40035) % email]
         items += [control.lang(40037) % status]
         items += [control.lang(40041) % expires]
         items += [control.lang(40042) % days_remaining]
         return control.selectDialog(items, 'All Debrid')
     except:
         log_utils.error()
     return
Beispiel #16
0
 def account_info_to_dialog(self):
     from datetime import datetime, timedelta
     try:
         account_info, stats = self.extended_account_info()
         username = account_info['user']['username']
         timezone = account_info['account']['timezone']
         joined = control.jsondate_to_datetime(
             account_info['user']['joined_at'], "%Y-%m-%dT%H:%M:%S.%fZ")
         private = account_info['user']['private']
         vip = account_info['user']['vip']
         if vip: vip = '%s Years' % str(account_info['user']['vip_years'])
         total_given_ratings = stats['ratings']['total']
         movies_collected = stats['movies']['collected']
         movies_watched = stats['movies']['watched']
         movies_watched_minutes = ("{:0>8}".format(
             str(timedelta(
                 minutes=stats['movies']['minutes'])))).split(', ')
         movies_watched_minutes = control.lang(40071) % (
             movies_watched_minutes[0],
             movies_watched_minutes[1].split(':')[0],
             movies_watched_minutes[1].split(':')[1])
         shows_collected = stats['shows']['collected']
         shows_watched = stats['shows']['watched']
         episodes_watched = stats['episodes']['watched']
         episodes_watched_minutes = ("{:0>8}".format(
             str(timedelta(
                 minutes=stats['episodes']['minutes'])))).split(', ')
         episodes_watched_minutes = control.lang(40071) % (
             episodes_watched_minutes[0],
             episodes_watched_minutes[1].split(':')[0],
             episodes_watched_minutes[1].split(':')[1])
         heading = control.lang(32315)
         items = []
         items += [control.lang(40036) % username]
         items += [control.lang(40063) % timezone]
         items += [control.lang(40064) % joined]
         items += [control.lang(40065) % private]
         items += [control.lang(40066) % vip]
         items += [control.lang(40067) % str(total_given_ratings)]
         items += [
             control.lang(40068) %
             (movies_collected, movies_watched, movies_watched_minutes)
         ]
         items += [control.lang(40069) % (shows_collected, shows_watched)]
         items += [
             control.lang(40070) %
             (episodes_watched, episodes_watched_minutes)
         ]
         return control.selectDialog(items, heading)
     except:
         log_utils.error()
         return