Skip to content

Commit

Permalink
Version 0.9.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Paco8 committed Nov 7, 2024
1 parent 3ff3135 commit fe2f12b
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 22 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.9.14"
version="0.9.15"
provider-name="Paco8">
<requires>
<!--- <import addon="xbmc.python" version="2.25.0"/> -->
Expand Down
16 changes: 16 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,22 @@ msgctxt "#30192"
msgid "Use a {} account"
msgstr ""

msgctxt "#30193"
msgid "Select the credentials file"
msgstr ""

msgctxt "#30194"
msgid "Select a folder to save the credentials file"
msgstr ""

msgctxt "#30195"
msgid "Export credentials"
msgstr ""

msgctxt "#30196"
msgid "Import credentials"
msgstr ""

msgctxt "#30200"
msgid "Error"
msgstr ""
Expand Down
16 changes: 16 additions & 0 deletions resources/language/resource.language.es_es/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,22 @@ msgctxt "#30192"
msgid "Use a {} account"
msgstr "Usar una cuenta de {}"

msgctxt "#30193"
msgid "Select the credentials file"
msgstr "Selecciona el fichero de credenciales"

msgctxt "#30194"
msgid "Select a folder to save the credentials file"
msgstr "Seleccion una carpeta donde guardar las credenciales"

msgctxt "#30195"
msgid "Export credentials"
msgstr "Exportar credenciales"

msgctxt "#30196"
msgid "Import credentials"
msgstr "Importar credenciales"

msgctxt "#30200"
msgid "Error"
msgstr "Error"
Expand Down
46 changes: 31 additions & 15 deletions resources/lib/movistar.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(self, config_directory, reuse_devices=False):
if content:
data = json.loads(content)
if not data or 'ofertas' not in data:
data = self.authenticate()
data = self.get_account_info()
if not data or 'ofertas' not in data: return
self.cache.save_file('account.json', json.dumps(data, ensure_ascii=False))
self.account['id'] = data['ofertas'][0]['accountNumber']
Expand All @@ -139,7 +139,7 @@ def __init__(self, config_directory, reuse_devices=False):
if not reuse_devices:
LOG('not reusing devices')
if not self.account['device_id']:
self.account['device_id'] = self.new_device_id()
self.account['device_id'] = self.request_device_id()
self.cache.save_file('device_id.conf', self.account['device_id'])
else:
LOG('reusing devices')
Expand All @@ -159,7 +159,7 @@ def __init__(self, config_directory, reuse_devices=False):
self.account['device_id'] = wp_device
else:
LOG('device not found, registering new device')
self.account['device_id'] = self.new_device_id()
self.account['device_id'] = self.request_device_id()
self.cache.save_file('device_id.conf', self.account['device_id'])
LOG('device_id: {}'. format(self.account['device_id']))

Expand Down Expand Up @@ -293,7 +293,7 @@ def login(self, username, password):
pass
return success, content

def authenticate(self):
def get_account_info(self):
headers = self.net.headers.copy()
headers['Content-Type'] = 'application/x-www-form-urlencoded'
#headers['x-movistarplus-deviceid'] = self.account['device_id']
Expand All @@ -302,9 +302,9 @@ def authenticate(self):
headers['Authorization'] = 'Bearer ' + self.account['access_token']
url = self.endpoints['autenticacion_tk'].format(deviceType=self.dplayer) + '?_=' + str(int(time.time()*1000))
#LOG(url)
#LOG('authenticate: headers: {}'.format(headers))
#LOG('get_account_info: headers: {}'.format(headers))
data = self.net.load_data(url, headers)
#LOG('authenticate: data: {}'.format(data))
#LOG('get_account_info: data: {}'.format(data))
return data

def change_device(self, id):
Expand Down Expand Up @@ -348,7 +348,7 @@ def register_device(self):
def unregister_device(self):
return self.delete_device(self.account['device_id'])

def new_device_id(self):
def request_device_id(self):
headers = self.net.headers.copy()
headers['Content-Type'] = 'application/json'
#headers['x-movistarplus-ui'] = '2.36.30'
Expand All @@ -361,10 +361,11 @@ def new_device_id(self):
content = response.content.decode('utf-8')
return content.strip('"')

#import random
#s = ''
#for _ in range(0, 32): s += random.choice('abcdef0123456789')
#return s
#def generate_device_id(self):
# import random
# s = ''
# for _ in range(0, 32): s += random.choice('abcdef0123456789')
# return s

def delete_device(self, device_id):
headers = self.net.headers.copy()
Expand Down Expand Up @@ -1281,6 +1282,16 @@ 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))

def import_credentials(self, filename):
if sys.version_info[0] > 2:
filename = bytes(filename, 'utf-8')
shutil.copyfile(filename, self.cache.config_directory + 'credentials.json')

def export_credentials(self, filename):
if sys.version_info[0] > 2:
filename = bytes(filename, 'utf-8')
shutil.copyfile(self.cache.config_directory + 'credentials.json', filename)

def delete_session_files(self):
for f in ['access_token.conf', 'account.json', 'device_id.conf', 'devices.json', 'profile_id.conf', 'tokens.json', 'channels2.json', 'channels_UHD.json', 'channels_HD.json', 'epg2.json', 'epg_UHD.json', 'epg_HD.json']:
self.cache.remove_file(f)
Expand Down Expand Up @@ -1464,20 +1475,25 @@ def load_credentials(self):
else:
return '', ''

def get_token_expire_date(self, token):
def get_token_properties(self, token=None):
from .b64 import decode_base64
res = 0
if not token:
token = self.account['access_token']
data = None
try:
l = token.split('.')
if len(l) > 1:
padding = len(l[1]) % 4
l[1] += '=' * (4 - padding) if padding != 0 else ''
s = decode_base64(l[1])
data = json.loads(s)
res = data['exp']
except:
pass
return res
return data

def get_token_expire_date(self, token):
data = self.get_token_properties(token)
return data.get('exp', 0)

def get_accounts(self):
accounts = []
Expand Down
25 changes: 21 additions & 4 deletions resources/lib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ def play(params):
subpaths.append(filename_srt)
play_item.setSubtitles(subpaths)

if True:
m.unregister_device()
m.register_device()
#if True:
# m.unregister_device()
# m.register_device()

xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)

Expand Down Expand Up @@ -647,6 +647,16 @@ def export_key():
if directory:
m.export_key_file(directory + 'movistarplus.key')

def import_credentials():
filename = xbmcgui.Dialog().browseSingle(1, addon.getLocalizedString(30193), '', '.json')
if filename:
m.import_credentials(filename)

def export_credentials():
directory = xbmcgui.Dialog().browseSingle(0, addon.getLocalizedString(30194), '')
if directory:
m.export_credentials(os.path.join(directory, 'credenciales.json'))

def select_account(id, name):
m.switch_account(id)
open_folder(name)
Expand All @@ -656,7 +666,10 @@ def select_account(id, name):
if os.path.exists(os.path.join(m.cache.config_directory, 'auth.key')):
add_menu_option(addon.getLocalizedString(30184), get_url(action='export_key')) # Export key
add_menu_option(addon.getLocalizedString(30150), get_url(action='logout')) # Close session
close_folder()
add_menu_option(addon.getLocalizedString(30196), get_url(action='import_credentials'))
if os.path.exists(os.path.join(m.cache.config_directory, 'credentials.json')):
add_menu_option(addon.getLocalizedString(30195), get_url(action='export_credentials'))
close_folder(cacheToDisc=False)

def list_accounts(params):
LOG('list_accounts: {}'.format(params))
Expand Down Expand Up @@ -779,6 +792,10 @@ def router(paramstring):
login()
elif params['action'] == 'export_key':
export_key()
elif params['action'] == 'export_credentials':
export_credentials()
elif params['action'] == 'import_credentials':
import_credentials()
elif params['action'] == 'select_account':
select_account(params['id'], params['name'])
elif params['action'] == 'accounts':
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ def do_POST(self):
LOG('license response: {}'.format(license_data))
d = try_load_json(license_data)
if d and 'errorCode' in d:
from .gui import show_notification
show_notification('Error {}: {}'.format(d['errorCode'], d['message']))
if d['errorCode'] == 4027:
if not reregister_needed and addon.getSettingBool('reregister'):
reregister_needed = True
continue
from .gui import show_notification
show_notification('Error {}: {}'.format(d['errorCode'], d['message']))
else:
LOG('license response: {}'.format(encode_base64(license_data)))
break
Expand Down

0 comments on commit fe2f12b

Please sign in to comment.