Version 0.8.4

This commit is contained in:
Paco8 committed 2023-12-22 14:13:05 +01:00
1 parent 683ba9da45
commit 18d7f85b43
4 files changed
+66 -57

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.movistarplus" <addon id="plugin.video.movistarplus"
name="Movistar+" name="Movistar+"
version="0.8.3" version="0.8.4"
provider-name="Paco8"> provider-name="Paco8">
<requires> <requires>
<!--- <import addon="xbmc.python" version="2.25.0"/> --> <!--- <import addon="xbmc.python" version="2.25.0"/> -->
+56 -49
View File
@@ -91,49 +91,37 @@ class Movistar(object):
self.account['device_id'] = self.cache.load_file('device_id.conf') self.account['device_id'] = self.cache.load_file('device_id.conf')
if self.account['device_id']: if self.account['device_id']:
self.account['device_id'] = self.account['device_id'].strip('"') self.account['device_id'] = self.account['device_id'].strip('"')
if not reuse_devices:
LOG('not reusing devices')
if not self.account['device_id']:
self.account['device_id'] = self.new_device_id()
self.cache.save_file('device_id.conf', self.account['device_id'])
# Check if device is registered
device_list = self.get_devices()
found_device = False
for device in device_list:
if device['id'] == self.account['device_id']:
found_device = True
break
if not found_device:
LOG('device not found, trying to register device')
self.register_device()
device_list = self.get_devices(use_cache=False) # To store the updated list in cache
else: else:
LOG('reusing devices') # Create new device
# Check if device is registered if not reuse_devices:
device_list = self.get_devices() LOG('not reusing devices')
found_device = False if not self.account['device_id']:
wp_device = None
for device in device_list:
if not wp_device and device['type_code'] == 'WP':
wp_device = device['id']
if device['id'] == self.account['device_id']:
found_device = True
break
if not found_device:
if wp_device:
LOG('device not found, using {}'.format(wp_device))
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.new_device_id()
self.register_device() self.cache.save_file('device_id.conf', self.account['device_id'])
device_list = self.get_devices(use_cache=False) # To store the updated list in cache else:
self.cache.save_file('device_id.conf', self.account['device_id']) LOG('reusing devices')
# Check if device is registered
device_list = self.get_devices()
found_device = False
wp_device = None
for device in device_list:
if not wp_device and device['type_code'] == 'WP':
wp_device = device['id']
if device['id'] == self.account['device_id']:
found_device = True
break
if not found_device:
if wp_device:
LOG('device not found, using {}'.format(wp_device))
self.account['device_id'] = wp_device
else:
LOG('device not found, registering new device')
self.account['device_id'] = self.new_device_id()
self.cache.save_file('device_id.conf', self.account['device_id'])
LOG('device_id: {}'. format(self.account['device_id'])) LOG('device_id: {}'. format(self.account['device_id']))
# Tokens # Tokens
content = self.cache.load('tokens.json', 3) content = self.cache.load('tokens.json', 60)
if content: if content:
data = json.loads(content) data = json.loads(content)
else: else:
@@ -295,16 +283,11 @@ class Movistar(object):
self.cache.save_file('device_id.conf', self.account['device_id']) self.cache.save_file('device_id.conf', self.account['device_id'])
self.cache.remove_file('tokens.json') self.cache.remove_file('tokens.json')
def get_devices(self, use_cache=True): def get_devices(self):
content = self.cache.load('devices.json', 3) headers = self.net.headers.copy()
if use_cache and content: headers['Authorization'] = 'Bearer ' + self.account['access_token']
data = json.loads(content) url = self.endpoints['obtenerdipositivos'].format(ACCOUNTNUMBER=self.account['id'])
else: data = self.net.load_data(url, headers)
headers = self.net.headers.copy()
headers['Authorization'] = 'Bearer ' + self.account['access_token']
url = self.endpoints['obtenerdipositivos'].format(ACCOUNTNUMBER=self.account['id'])
data = self.net.load_data(url, headers)
self.cache.save_file('devices.json', json.dumps(data, ensure_ascii=False))
#print_json(data) #print_json(data)
if not isinstance(data, list): return [] if not isinstance(data, list): return []
res = [] res = []
@@ -403,13 +386,37 @@ class Movistar(object):
data = self.net.post_data(url, None, headers) data = self.net.post_data(url, None, headers)
return data.get('access_token') return data.get('access_token')
def get_session_token(self):
data = {"accountNumber": self.account['id'],
"sessionUserProfile": self.account['profile_id'],
"streamMiscellanea":"HTTPS",
"deviceType":"WP_OTT",
"deviceManufacturerProduct":"Firefox",
"streamDRM":"Widevine",
"streamFormat":"DASH",
}
headers = self.net.headers.copy()
headers['Content-Type'] = 'application/json'
headers['Authorization'] = 'Bearer ' + self.account['access_token']
url = self.endpoints['renovacion_hztoken'].format(deviceType='webplayer', DEVICEID=self.account['device_id'])
data = self.net.post_data(url, json.dumps(data), headers)
return data.get('homeZoneID')
def get_ssp_token(self):
headers = self.net.headers.copy()
headers['Content-Type'] = 'application/json'
headers['Authorization'] = 'Bearer ' + self.account['access_token']
url = self.endpoints['renovacion_ssptoken'].format(deviceType='webplayer', ACCOUNTNUMBER=self.account['id'], DEVICEID=self.account['device_id'])
data = self.net.post_data(url, '', headers)
return data.get('access_token')
def get_profiles(self): def get_profiles(self):
headers = self.net.headers.copy() headers = self.net.headers.copy()
headers['X-HZId'] = self.account['session_token'] headers['X-HZId'] = self.account['session_token']
url = self.endpoints['listaperfiles'] url = self.endpoints['listaperfiles']
data = self.net.load_data(url, headers=headers) data = self.net.load_data(url, headers=headers)
res = [] res = []
for d in data['items']: for d in data.get('items', []):
p = {} p = {}
p['id'] = d['id'] p['id'] = d['id']
p['name'] = d['name'] p['name'] = d['name']
+6 -6
View File
@@ -69,6 +69,8 @@ def play(params):
session_opened = False session_opened = False
if addon.getSettingBool('open_session') or stype == 'vod': if addon.getSettingBool('open_session') or stype == 'vod':
hz_token = m.get_session_token()
if hz_token: session_token = hz_token
d = m.open_session(params['session_request'], session_token) d = m.open_session(params['session_request'], session_token)
session_opened = True session_opened = True
LOG('Open session: d: {}'.format(d)) LOG('Open session: d: {}'.format(d))
@@ -105,8 +107,8 @@ def play(params):
headers += '&Referer=https://ver.movistarplus.es/' headers += '&Referer=https://ver.movistarplus.es/'
headers += '&Origin=https://ver.movistarplus.es&Connection=keep-alive' headers += '&Origin=https://ver.movistarplus.es&Connection=keep-alive'
headers += '&Host=wv-ottlic-f3.imagenio.telefonica.net' headers += '&Host=wv-ottlic-f3.imagenio.telefonica.net'
manifest_headers = 'User-Agent=Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0' manifest_headers = 'User-Agent=Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0'
if stype == 'tv': if stype == 'tv':
cdn_token = m.get_cdntoken() cdn_token = m.get_cdntoken()
#LOG('cdn_token: {}'.format(cdn_token)) #LOG('cdn_token: {}'.format(cdn_token))
@@ -144,10 +146,8 @@ def play(params):
else: else:
play_item.setProperty('inputstream.adaptive.license_key', '{}|{}&nv-authorizations={}|R{{SSM}}|'.format(license_url, headers, token)) play_item.setProperty('inputstream.adaptive.license_key', '{}|{}&nv-authorizations={}|R{{SSM}}|'.format(license_url, headers, token))
if kodi_version < 20: play_item.setProperty('inputstream.adaptive.stream_headers', manifest_headers)
play_item.setProperty('inputstream.adaptive.stream_headers', manifest_headers) play_item.setProperty('inputstream.adaptive.manifest_headers', manifest_headers)
else:
play_item.setProperty('inputstream.adaptive.manifest_headers', manifest_headers)
play_item.setProperty('inputstream.adaptive.server_certificate', certificate) play_item.setProperty('inputstream.adaptive.server_certificate', certificate)
#play_item.setProperty('inputstream.adaptive.license_flags', 'persistent_storage') #play_item.setProperty('inputstream.adaptive.license_flags', 'persistent_storage')
@@ -351,7 +351,7 @@ def add_videos(category, ctype, videos, ref=None, url_next=None, url_prev=None,
def list_devices(params): def list_devices(params):
LOG('list_devices: params: {}'.format(params)) LOG('list_devices: params: {}'.format(params))
devices = m.get_devices(False) devices = m.get_devices()
if 'id' in params: if 'id' in params:
if params['name'] == 'select': if params['name'] == 'select':
+3 -1
View File
@@ -143,9 +143,11 @@ class RequestHandler(BaseHTTPRequestHandler):
else: else:
self.send_response(404) self.send_response(404)
self.end_headers() self.end_headers()
except Exception: except Exception as e:
self.send_response(500) self.send_response(500)
self.end_headers() self.end_headers()
LOG('Exception error: {}'.format(str(e)))
def do_POST(self): def do_POST(self):
"""Handle http post requests, used for license""" """Handle http post requests, used for license"""