Version 0.4.1
This commit is contained in:
1 parent
97984337a5
commit
7b856bed8b
5 files changed
+91
-37
No files matched your search
@@ -241,6 +241,10 @@ msgctxt "#30182"
|
||||
msgid "Select the key file"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30183"
|
||||
msgid "Login with username"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "#30200"
|
||||
msgid "Error"
|
||||
msgstr ""
|
||||
|
||||
@@ -241,6 +241,10 @@ msgctxt "#30182"
|
||||
msgid "Select the key file"
|
||||
msgstr "Selecciona el fichero key"
|
||||
|
||||
msgctxt "#30183"
|
||||
msgid "Login with username"
|
||||
msgstr "Iniciar sesión con nombre y clave"
|
||||
|
||||
msgctxt "#30200"
|
||||
msgid "Error"
|
||||
msgstr "Error"
|
||||
|
||||
+39
-27
@@ -48,6 +48,9 @@ class Movistar(object):
|
||||
# Cache
|
||||
self.cache = Cache(config_directory)
|
||||
|
||||
# Endpoints
|
||||
self.endpoints = self.get_endpoints()
|
||||
|
||||
# Access token
|
||||
self.load_key_file() # Default access_token
|
||||
content = self.cache.load_file('access_token.conf')
|
||||
@@ -56,9 +59,6 @@ class Movistar(object):
|
||||
#LOG('access_token: {}'.format(self.account['access_token']))
|
||||
if not self.account['access_token']: return
|
||||
|
||||
# Endpoints
|
||||
self.endpoints = self.get_endpoints()
|
||||
|
||||
# Account
|
||||
data = None
|
||||
content = self.cache.load('account.json')
|
||||
@@ -155,19 +155,6 @@ class Movistar(object):
|
||||
#print_json(self.entitlements)
|
||||
self.logged = True
|
||||
|
||||
def install_key_file(self, filename):
|
||||
import shutil
|
||||
if sys.version_info[0] > 2:
|
||||
filename = bytes(filename, 'utf-8')
|
||||
shutil.copyfile(filename, self.cache.config_directory + 'auth.key')
|
||||
|
||||
def load_key_file(self):
|
||||
content = self.cache.load_file('auth.key')
|
||||
if content:
|
||||
data = json.loads(content)
|
||||
data = json.loads(data['data'])
|
||||
self.account['access_token'] = data['response']['access_token']
|
||||
|
||||
def get_token(self):
|
||||
data = {"accountNumber": self.account['id'],
|
||||
"userProfile": self.account['profile_id'],
|
||||
@@ -224,28 +211,33 @@ class Movistar(object):
|
||||
#LOG("**** open_session response: {}".format(d))
|
||||
return d
|
||||
|
||||
def login(self):
|
||||
def login(self, username, password):
|
||||
headers = self.net.headers.copy()
|
||||
headers['x-movistarplus-deviceid'] = self.account['device_id']
|
||||
if self.account['device_id']:
|
||||
headers['x-movistarplus-deviceid'] = self.account['device_id']
|
||||
headers['x-movistarplus-ui'] = '2.36.30'
|
||||
headers['x-movistarplus-os'] = 'Linux88'
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
p = base64.b64decode(bytes(self.account['password']))
|
||||
else:
|
||||
p = base64.b64decode(bytes(self.account['password'], encoding='ascii')).decode('ascii')
|
||||
|
||||
data = {
|
||||
'grant_type': 'password',
|
||||
'deviceClass': 'webplayer',
|
||||
'username': self.account['username'],
|
||||
'password': p,
|
||||
'captchaResult': '',
|
||||
'username': username,
|
||||
'password': password,
|
||||
}
|
||||
|
||||
url = self.endpoints['token']
|
||||
response = self.net.session.post(url, headers=headers, data=data)
|
||||
print(response.content)
|
||||
content = response.content.decode('utf-8')
|
||||
LOG(content)
|
||||
success = False
|
||||
try:
|
||||
d = json.loads(content)
|
||||
if 'access_token' in d:
|
||||
success = True
|
||||
self.save_key_file(d)
|
||||
except:
|
||||
pass
|
||||
return success, content
|
||||
|
||||
def authenticate(self):
|
||||
headers = self.net.headers.copy()
|
||||
@@ -749,3 +741,23 @@ class Movistar(object):
|
||||
url += '&topic=IN'
|
||||
#LOG('vod url: {}'.format(url))
|
||||
return url
|
||||
|
||||
def install_key_file(self, filename):
|
||||
import shutil
|
||||
if sys.version_info[0] > 2:
|
||||
filename = bytes(filename, 'utf-8')
|
||||
shutil.copyfile(filename, self.cache.config_directory + 'auth.key')
|
||||
|
||||
def load_key_file(self):
|
||||
content = self.cache.load_file('auth.key')
|
||||
if content:
|
||||
data = json.loads(content)
|
||||
if 'response' in data:
|
||||
self.account['access_token'] = data['response']['access_token']
|
||||
elif 'data' in data:
|
||||
data = json.loads(data['data'])
|
||||
self.account['access_token'] = data['response']['access_token']
|
||||
|
||||
def save_key_file(self, d):
|
||||
data = {'timestamp': int(time.time()*1000), 'response': d}
|
||||
self.cache.save_file('auth.key', json.dumps(data, ensure_ascii=False))
|
||||
+43
-9
@@ -369,16 +369,47 @@ def list_vod():
|
||||
add_menu_option(name, get_url(action='listing', name=name, url=m.get_vod_list_url(cat='kids'))) # Kids
|
||||
close_folder()
|
||||
|
||||
def clear_session():
|
||||
m.cache.remove_file('access_token.conf')
|
||||
m.cache.remove_file('account.json')
|
||||
m.cache.remove_file('device_id.conf')
|
||||
m.cache.remove_file('devices.json')
|
||||
m.cache.remove_file('profile_id.conf')
|
||||
m.cache.remove_file('tokens.json')
|
||||
|
||||
def logout():
|
||||
clear_session()
|
||||
m.cache.remove_file('auth.key')
|
||||
|
||||
def login():
|
||||
def ask_credentials(username=''):
|
||||
username = input_window(addon.getLocalizedString(30163), username) # Username
|
||||
if username:
|
||||
password = input_window(addon.getLocalizedString(30164), hidden=True) # Password
|
||||
if password:
|
||||
return username, password
|
||||
return None, None
|
||||
|
||||
username, password = ask_credentials()
|
||||
if username:
|
||||
success, _ = m.login(username, password)
|
||||
if success:
|
||||
clear_session()
|
||||
else:
|
||||
show_notification(addon.getLocalizedString(30166)) # Failed
|
||||
|
||||
def login_with_key():
|
||||
filename = xbmcgui.Dialog().browseSingle(1, addon.getLocalizedString(30182), '', '.key')
|
||||
if filename:
|
||||
m.install_key_file(filename)
|
||||
m.cache.remove_file('access_token.conf')
|
||||
m.cache.remove_file('account.json')
|
||||
m.cache.remove_file('device_id.conf')
|
||||
m.cache.remove_file('devices.json')
|
||||
m.cache.remove_file('profile_id.conf')
|
||||
m.cache.remove_file('tokens.json')
|
||||
clear_session()
|
||||
|
||||
def list_users():
|
||||
open_folder(addon.getLocalizedString(30160)) # Change user
|
||||
add_menu_option(addon.getLocalizedString(30183), get_url(action='login')) # Login with username
|
||||
add_menu_option(addon.getLocalizedString(30181), get_url(action='login_with_key')) # Login with key
|
||||
add_menu_option(addon.getLocalizedString(30150), get_url(action='logout')) # Close session
|
||||
close_folder()
|
||||
|
||||
def router(paramstring):
|
||||
"""
|
||||
@@ -405,8 +436,12 @@ def router(paramstring):
|
||||
list_profiles(params)
|
||||
elif params['action'] == 'login_with_key':
|
||||
login_with_key()
|
||||
elif params['action'] == 'login':
|
||||
login()
|
||||
elif params['action'] == 'user':
|
||||
list_users()
|
||||
elif params['action'] == 'logout':
|
||||
pass
|
||||
logout()
|
||||
elif params['action'] == 'epg':
|
||||
list_epg(params)
|
||||
elif params['action'] == 'wishlist':
|
||||
@@ -438,9 +473,8 @@ def router(paramstring):
|
||||
add_menu_option(addon.getLocalizedString(30111), get_url(action='vod')) # VOD
|
||||
add_menu_option(addon.getLocalizedString(30180), get_url(action='profiles')) # Profiles
|
||||
add_menu_option(addon.getLocalizedString(30108), get_url(action='devices')) # Devices
|
||||
#add_menu_option(addon.getLocalizedString(30150), get_url(action='logout')) # Close session
|
||||
|
||||
add_menu_option(addon.getLocalizedString(30181), get_url(action='login_with_key')) # Login with key
|
||||
add_menu_option(addon.getLocalizedString(30160), get_url(action='user')) # Accounts
|
||||
close_folder(cacheToDisc=False)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user