Skip to content

Commit

Permalink
Version 0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Paco8 committed Jan 27, 2023
1 parent 9798433 commit 7b856be
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 37 deletions.
2 changes: 1 addition & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.movistarplus"
name="Movistar+"
version="0.3.13"
version="0.4.1"
provider-name="Paco8">
<requires>
<!--- <import addon="xbmc.python" version="2.25.0"/> -->
Expand Down
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ msgctxt "#30182"
msgid "Select the key file"
msgstr ""

msgctxt "#30183"
msgid "Login with username"
msgstr ""

msgctxt "#30200"
msgid "Error"
msgstr ""
Expand Down
4 changes: 4 additions & 0 deletions resources/language/resource.language.es_es/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
66 changes: 39 additions & 27 deletions resources/lib/movistar.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __init__(self, config_directory, reuse_devices=False):
# 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')
Expand All @@ -56,9 +59,6 @@ def __init__(self, config_directory, reuse_devices=False):
#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')
Expand Down Expand Up @@ -155,19 +155,6 @@ def __init__(self, config_directory, reuse_devices=False):
#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'],
Expand Down Expand Up @@ -224,28 +211,33 @@ def open_session(self, data, session_token, session_id = None):
#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()
Expand Down Expand Up @@ -749,3 +741,23 @@ def get_vod_list_url(self, cat='movies'):
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))
52 changes: 43 additions & 9 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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':
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 7b856be

Please sign in to comment.