diff --git a/Makefile b/Makefile index fb3dcc0..bf1cf7d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VERSION = $(shell ./get_version.py) -OUTPUT_DIR = plugin.video.movistarplus-$(VERSION) +OUTPUT_DIR = plugin.video.kodimovplus-$(VERSION) OUTPUT_FILE = $(OUTPUT_DIR).zip install: diff --git a/README.md b/README.md index beb79b2..46238dd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,18 @@ +# KodiMov+ + +Fork of [Paco8's Movistar+ add-on](https://github.com/Paco8/plugin.video.movistarplus) (1.0.0) for Kodi, id `plugin.video.kodimovplus`. Installs from the xocko Kodi repository: +`https://git.anosanube.ovh/xocko/kodi-repo/raw/branch/main/repository.xocko.zip` + +What it adds: +- **Login from the Movistar home network**, no password. The home-network login gives a token for Movistar's new servers, which is traded once for a classic token; the classic servers renew it every 10 days. It needs the account number (taken from an existing login, or set in the settings) and an already registered device. +- **Takes over the login of plugin.video.movistarplus** on first run (same registered device, so no new device is added to the account). +- **Hides channels it can't play**: Movistar marks football and premium sports with `QMWatermark`; LALIGA and Liga de Campeones refuse their manifest, while M+ Deportes, DAZN and DAZN Baloncesto play and are kept (`resources/lib/kodimov.py`). +- **Extra free channels** in the TV guide list: TVG2 (10) and TeleVigo (155). +- **The TV guide list stays current**: re-exported every 6 hours, numbered with Movistar's own dial numbers. +- Its own proxy port (57031), so it can run next to the original. + +--- + ![GitHub release (latest by date)](https://img.shields.io/github/v/release/Paco8/plugin.video.movistarplus) ![GitHub all releases](https://img.shields.io/github/downloads/Paco8/plugin.video.movistarplus/total) diff --git a/__pycache__/service.cpython-315.pyc b/__pycache__/service.cpython-315.pyc new file mode 100644 index 0000000..8ac43a4 Binary files /dev/null and b/__pycache__/service.cpython-315.pyc differ diff --git a/addon.xml b/addon.xml index 2ae2f30..dcc4869 100644 --- a/addon.xml +++ b/addon.xml @@ -1,8 +1,8 @@ - + @@ -17,16 +17,17 @@ - Movistar+ - Movistar+ - Watch live channels, recordings and video on demand content from Movistar+ in Kodi. Requires a subscription. - Vea canales en directo, grabaciones, U7D y TV a la carta de Movistar+ en Kodi. Se necesita estar abonado. + Movistar+ for Kodi, with automatic login from the Movistar home network + Movistar+ para Kodi, con inicio de sesión automático desde la red de Movistar + Fork of Paco8's Movistar+ add-on (plugin.video.movistarplus). Logs in by itself from the Movistar home network, keeps the channel list and numbers up to date, hides the channels that need stronger DRM than Kodi has, and adds free Galician channels (TVG2, TeleVigo) to the TV guide. Requires a Movistar+ subscription. + Fork del addon Movistar+ de Paco8 (plugin.video.movistarplus). Inicia sesión solo desde la red de Movistar, mantiene la lista y los números de los canales al día, oculta los canales que necesitan una protección que Kodi no tiene y añade canales gallegos gratuitos (TVG2, TeleVigo) a la guía. Se necesita estar abonado a Movistar+. + 1.0.0+kodimov.1: first KodiMov+ release, based on Movistar+ 1.0.0. This addon is not officially commissioned/supported by Movistar+. All product names, logos, and trademarks mentioned in this project are property of their respective owners. Este addon no ha sido realizado ni apoyado por Movistar+. Todos los nombres de productos, logotipos y marcas registradas mencionados en este proyecto son propiedad de sus respectivos dueños. all LGPL-2.1-or-later - - + https://git.anosanube.ovh/xocko/kodimovplus + https://git.anosanube.ovh/xocko/kodimovplus icon.png resources/fanart.png diff --git a/resources/__pycache__/__init__.cpython-315.pyc b/resources/__pycache__/__init__.cpython-315.pyc new file mode 100644 index 0000000..3509baa Binary files /dev/null and b/resources/__pycache__/__init__.cpython-315.pyc differ diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 4647b9d..d079369 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -621,3 +621,35 @@ msgstr "" msgctxt "#30451" msgid "If you find this addon useful you can buy the developer a coffee:" msgstr "" + +msgctxt "#30501" +msgid "Log in from the Movistar home network" +msgstr "" + +msgctxt "#30502" +msgid "Movistar account number (e.g. 12345678901234-TEF)" +msgstr "" + +msgctxt "#30503" +msgid "Logged in from the Movistar network" +msgstr "" + +msgctxt "#30504" +msgid "Network login failed: {}" +msgstr "" + +msgctxt "#30505" +msgid "Log in automatically from the Movistar home network" +msgstr "" + +msgctxt "#30506" +msgid "Hide channels this add-on can't play (LALIGA, Liga de Campeones)" +msgstr "" + +msgctxt "#30507" +msgid "Add free Galician channels (TVG2, TeleVigo) to the TV guide" +msgstr "" + +msgctxt "#30508" +msgid "Keep the TV guide channel list up to date" +msgstr "" diff --git a/resources/language/resource.language.es_es/strings.po b/resources/language/resource.language.es_es/strings.po index 968b474..855de1d 100644 --- a/resources/language/resource.language.es_es/strings.po +++ b/resources/language/resource.language.es_es/strings.po @@ -585,6 +585,38 @@ msgctxt "#30451" msgid "If you find this addon useful you can buy the developer a coffee:" msgstr "Si este addon es útil para ti puedes invitar al programador a un café:" +msgctxt "#30501" +msgid "Log in from the Movistar home network" +msgstr "Iniciar sesión desde la red de Movistar" + +msgctxt "#30502" +msgid "Movistar account number (e.g. 12345678901234-TEF)" +msgstr "Número de cuenta de Movistar (p. ej. 12345678901234-TEF)" + +msgctxt "#30503" +msgid "Logged in from the Movistar network" +msgstr "Sesión iniciada desde la red de Movistar" + +msgctxt "#30504" +msgid "Network login failed: {}" +msgstr "Falló el inicio de sesión por red: {}" + +msgctxt "#30505" +msgid "Log in automatically from the Movistar home network" +msgstr "Iniciar sesión automáticamente desde la red de Movistar" + +msgctxt "#30506" +msgid "Hide channels this add-on can't play (LALIGA, Liga de Campeones)" +msgstr "Ocultar los canales que no se pueden reproducir (LALIGA, Liga de Campeones)" + +msgctxt "#30507" +msgid "Add free Galician channels (TVG2, TeleVigo) to the TV guide" +msgstr "Añadir canales gallegos gratuitos (TVG2, TeleVigo) a la guía" + +msgctxt "#30508" +msgid "Keep the TV guide channel list up to date" +msgstr "Mantener al día la lista de canales de la guía" + #~ msgctxt "#30040" #~ msgid "Use only for these languages (e.g.: es en pt):" #~ msgstr "Usar solo para estos idiomas (ej: es en pt):" diff --git a/resources/lib/__pycache__/__init__.cpython-315.pyc b/resources/lib/__pycache__/__init__.cpython-315.pyc new file mode 100644 index 0000000..40a3f57 Binary files /dev/null and b/resources/lib/__pycache__/__init__.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/addon.cpython-315.pyc b/resources/lib/__pycache__/addon.cpython-315.pyc new file mode 100644 index 0000000..c47e2c2 Binary files /dev/null and b/resources/lib/__pycache__/addon.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/b64.cpython-315.pyc b/resources/lib/__pycache__/b64.cpython-315.pyc new file mode 100644 index 0000000..865dfc6 Binary files /dev/null and b/resources/lib/__pycache__/b64.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/cache.cpython-315.pyc b/resources/lib/__pycache__/cache.cpython-315.pyc new file mode 100644 index 0000000..fa7dfe3 Binary files /dev/null and b/resources/lib/__pycache__/cache.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/customdialog.cpython-315.pyc b/resources/lib/__pycache__/customdialog.cpython-315.pyc new file mode 100644 index 0000000..15ed9bf Binary files /dev/null and b/resources/lib/__pycache__/customdialog.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/endpoints.cpython-315.pyc b/resources/lib/__pycache__/endpoints.cpython-315.pyc new file mode 100644 index 0000000..4b44577 Binary files /dev/null and b/resources/lib/__pycache__/endpoints.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/gui.cpython-315.pyc b/resources/lib/__pycache__/gui.cpython-315.pyc new file mode 100644 index 0000000..6611e80 Binary files /dev/null and b/resources/lib/__pycache__/gui.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/iptv.cpython-315.pyc b/resources/lib/__pycache__/iptv.cpython-315.pyc new file mode 100644 index 0000000..1fb37eb Binary files /dev/null and b/resources/lib/__pycache__/iptv.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/iptvmanager.cpython-315.pyc b/resources/lib/__pycache__/iptvmanager.cpython-315.pyc new file mode 100644 index 0000000..9f3e456 Binary files /dev/null and b/resources/lib/__pycache__/iptvmanager.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/kodimov.cpython-315.pyc b/resources/lib/__pycache__/kodimov.cpython-315.pyc new file mode 100644 index 0000000..74fa591 Binary files /dev/null and b/resources/lib/__pycache__/kodimov.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/log.cpython-315.pyc b/resources/lib/__pycache__/log.cpython-315.pyc new file mode 100644 index 0000000..af79b09 Binary files /dev/null and b/resources/lib/__pycache__/log.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/movistar.cpython-315.pyc b/resources/lib/__pycache__/movistar.cpython-315.pyc new file mode 100644 index 0000000..bfa58e1 Binary files /dev/null and b/resources/lib/__pycache__/movistar.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/mysession.cpython-315.pyc b/resources/lib/__pycache__/mysession.cpython-315.pyc new file mode 100644 index 0000000..7061350 Binary files /dev/null and b/resources/lib/__pycache__/mysession.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/network.cpython-315.pyc b/resources/lib/__pycache__/network.cpython-315.pyc new file mode 100644 index 0000000..5f3dd1c Binary files /dev/null and b/resources/lib/__pycache__/network.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/player.cpython-315.pyc b/resources/lib/__pycache__/player.cpython-315.pyc new file mode 100644 index 0000000..a97df13 Binary files /dev/null and b/resources/lib/__pycache__/player.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/plugin.cpython-315.pyc b/resources/lib/__pycache__/plugin.cpython-315.pyc new file mode 100644 index 0000000..7ee219e Binary files /dev/null and b/resources/lib/__pycache__/plugin.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/proxy.cpython-315.pyc b/resources/lib/__pycache__/proxy.cpython-315.pyc new file mode 100644 index 0000000..3c7a847 Binary files /dev/null and b/resources/lib/__pycache__/proxy.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/signature.cpython-315.pyc b/resources/lib/__pycache__/signature.cpython-315.pyc new file mode 100644 index 0000000..92dd750 Binary files /dev/null and b/resources/lib/__pycache__/signature.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/timeconv.cpython-315.pyc b/resources/lib/__pycache__/timeconv.cpython-315.pyc new file mode 100644 index 0000000..69a8561 Binary files /dev/null and b/resources/lib/__pycache__/timeconv.cpython-315.pyc differ diff --git a/resources/lib/__pycache__/useragent.cpython-315.pyc b/resources/lib/__pycache__/useragent.cpython-315.pyc new file mode 100644 index 0000000..b8099b0 Binary files /dev/null and b/resources/lib/__pycache__/useragent.cpython-315.pyc differ diff --git a/resources/lib/kodimov.py b/resources/lib/kodimov.py new file mode 100644 index 0000000..287888c --- /dev/null +++ b/resources/lib/kodimov.py @@ -0,0 +1,170 @@ +# encoding: utf-8 +# +# SPDX-License-Identifier: LGPL-2.1-or-later +# +# KodiMov+ additions to the Movistar+ add-on: +# - takes over the login of plugin.video.movistarplus on first run +# - logs in from the Movistar home network without a password +# - hides channels this add-on can't play +# - extra free channels for the TV guide + +from __future__ import unicode_literals, absolute_import, division + +import io +import json +import os +import shutil +import time + +from .log import LOG + +ORIGINAL_ADDON = 'plugin.video.movistarplus' +CLASSIC_ISSUER = 'http://www.movistarplus.es' + +# Movistar marks the football and premium sports channels with QMWatermark. +# The LALIGA and Liga de Campeones ones refuse their manifest to this add-on; +# these play fine (tested 2026-11-07 on a Raspberry Pi 5, LibreELEC 12.2). +WATERMARKED_BUT_PLAYABLE = { + 'CPDEP', 'ARTHUR', 'USOP2', 'USOP3', 'USOP11', 'MULTI8', # M+ Deportes 1-6 + 'M1SD', 'M2SD', 'DAZN3', 'DAZN4', # DAZN 1-4 + 'DAZBA', 'DAZB2', 'DAZB3', # DAZN Baloncesto 1-3 +} + +# Free channels that Movistar+ doesn't carry. 'chno' must not clash with a +# Movistar dial number. +EXTRA_CHANNELS = [ + {'id': 'TVG2', 'name': 'TVG2', 'chno': 10, 'group': 'Galicia', + 'logo': 'https://i.imgur.com/yFy6gxg.png', + 'url': 'https://crtvg-tvg2.flumotion.cloud/playlist.m3u8'}, + {'id': 'TeleVigo', 'name': 'TeleVigo', 'chno': 155, 'group': 'Galicia', + 'logo': 'https://i.imgur.com/4iVmlFa.png', + 'url': 'https://cloud.fastchannel.es/mic/manifiest/hls/televigo/televigo.m3u8'}, +] + +AUTOLOGIN_URL = 'https://soter-pf.svp.video.telefonicaservices.com/service/login/autologin?deviceId={device}&deviceType=webplayer&_={ts}' +SOTER_INITDATA_URL = 'https://soter-pf.sve.video.telefonicaservices.com/service/login/initData?legacy=true' + + +def is_playable(channel): + return not channel.get('watermark') or channel['id'] in WATERMARKED_BUT_PLAYABLE + + +def migrate_from_original(config_directory): + """Copies the login of plugin.video.movistarplus (tokens, registered device, + credentials) the first time KodiMov+ runs, so no new device is added to the + Movistar account and no password is needed.""" + config_directory = config_directory.rstrip('/\\') + if os.path.exists(os.path.join(config_directory, 'account.txt')): return False + if any(d.startswith('account_') for d in os.listdir(config_directory)): return False + source = os.path.join(os.path.dirname(config_directory), ORIGINAL_ADDON) + if not os.path.isdir(source): return False + copied = False + for d in os.listdir(source): + src = os.path.join(source, d) + if d.startswith('account_') and os.path.isdir(src): + shutil.copytree(src, os.path.join(config_directory, d), ignore=shutil.ignore_patterns('cache')) + copied = True + if copied and os.path.exists(os.path.join(source, 'account.txt')): + shutil.copy(os.path.join(source, 'account.txt'), config_directory) + LOG('migrate_from_original: {}'.format('copied login from ' + ORIGINAL_ADDON if copied else 'nothing to copy')) + return copied + + +def _read_json(cache, filename): + content = cache.load_file(filename) + try: + return json.loads(content) if content else None + except ValueError: + return None + + +def find_account_number(m, setting=''): + data = _read_json(m.cache, 'account.json') + try: + return data['ofertas'][0]['accountNumber'] + except (TypeError, KeyError, IndexError): + pass + data = _read_json(m.cache, 'tokens.json') + if isinstance(data, dict) and data.get('accountNumber'): + return data['accountNumber'] + return (setting or '').strip() + + +def network_login(m, account_number): + """Password-less login from the Movistar home network. + 1. autologin (only reachable inside Movistar's network) gives a 5-minute + token for the new servers; + 2. their initData trades it for a legacyAccessToken, which the classic + servers this add-on uses accept (and renew for 10 days at a time). + Returns (success, reason).""" + try: + from urllib.parse import urlsplit + except ImportError: + from urlparse import urlsplit + from .signature import get_auth + + device_id = (m.cache.load_file('device_id.conf') or '').strip().strip('"') + if not account_number: return False, 'no account number' + if not device_id: return False, 'no registered device' + + headers = m.net.headers.copy() + headers['Content-Type'] = 'application/json' + url = AUTOLOGIN_URL.format(device=device_id, ts=int(time.time() * 1000)) + try: + r = m.net.session.get(url, headers=headers, allow_redirects=False, timeout=(4, 10)) + location = r.headers.get('Location', '') + if r.status_code in (301, 302, 303, 307, 308) and location: + if not urlsplit(location).netloc.endswith('.telefonicaservices.com'): + return False, 'unexpected redirect' + h2 = headers.copy() + h2['Origin'] = 'null' + r = m.net.session.get(location, headers=h2, allow_redirects=False, timeout=(4, 10)) + token = r.json().get('access_token') + except Exception as e: + LOG('network_login: autologin failed: {}'.format(e)) + return False, 'not on the Movistar network' + if not token: return False, 'autologin refused' + + body = {'accountNumber': account_number, 'sessionUserProfile': 0, 'isKidProfile': False, + 'deviceId': device_id, 'streamMiscellanea': 'HTTPS', 'deviceManufacturerProduct': 'Firefox', + 'streamDRM': 'Widevine', 'streamFormat': 'DASH'} + data = None + for attempt in range(4): + h = headers.copy() + h['Authorization'] = get_auth('post', SOTER_INITDATA_URL, token) + try: + r = m.net.session.post(SOTER_INITDATA_URL, data=json.dumps(body), headers=h, timeout=(4, 15)) + data = r.json() + break + except Exception: + # The new servers sometimes answer with an HTML error page; retry. + LOG('network_login: initData attempt {} failed ({})'.format(attempt + 1, getattr(r, 'status_code', '?'))) + time.sleep(3) + legacy = data.get('legacyAccessToken') if isinstance(data, dict) else None + props = m.get_token_properties(legacy) if legacy else None + if not props or props.get('iss') != CLASSIC_ISSUER or props.get('exp', 0) < time.time(): + return False, 'initData refused' + m.save_key_file({'access_token': legacy, 'token_type': 'bearer'}) + m.cache.save_file('access_token.conf', legacy) + LOG('network_login: OK') + return True, '' + + +def extra_channels_m3u8(): + items = [] + for c in EXTRA_CHANNELS: + items.append('#EXTINF:-1 tvg-name="{name}" tvg-id="{id}" tvg-logo="{logo}" tvg-chno="{chno}" group-title="{group}",{name}\n{url}\n\n'.format(**c)) + return ''.join(items) + + +def write_if_changed(filename, content): + try: + with io.open(filename, 'r', encoding='utf-8', newline='') as f: + if f.read() == content: return False + except (IOError, OSError): + pass + tmp = filename + '.tmp' + with io.open(tmp, 'w', encoding='utf-8', newline='') as f: + f.write(content) + os.replace(tmp, filename) if hasattr(os, 'replace') else shutil.move(tmp, filename) + return True diff --git a/resources/lib/movistar.py b/resources/lib/movistar.py index 63b1915..9b9b6e1 100644 --- a/resources/lib/movistar.py +++ b/resources/lib/movistar.py @@ -22,6 +22,7 @@ from .network import Network from .cache import Cache from .timeconv import * from .useragent import useragent +from . import kodimov class Movistar(object): account = {'username': '', 'password': '', @@ -37,6 +38,8 @@ class Movistar(object): 'demarcation': 0} add_extra_info = True + hide_unplayable = True + add_extra_channels = True #dplayer = 'webplayer' #device_code = 'WP_OTT' #manufacturer = 'Firefox' @@ -45,9 +48,14 @@ class Movistar(object): manufacturer = 'LG' account_dir = 'account_1' - def __init__(self, config_directory, reuse_devices=False): + def __init__(self, config_directory, reuse_devices=False, network_login=False, account_number=''): self.logged = False self.expired_access_token = False + self.network_login_result = None + try: + kodimov.migrate_from_original(config_directory) + except Exception as e: + LOG('migrate_from_original failed: {}'.format(e)) # Network headers = { @@ -111,6 +119,9 @@ class Movistar(object): #LOG('access_token: {}'.format(self.account['access_token'])) LOG('expired_access_token: {}'.format(self.expired_access_token)) + if not self.account['access_token'] and network_login: + self.try_network_login(account_number) + if not self.account['access_token']: return # Account @@ -209,6 +220,21 @@ class Movistar(object): data = self.cache.load_file('searchs.json') self.search_list = json.loads(data) if data else [] + def try_network_login(self, account_number='', force=False): + # At most one attempt every 10 minutes, unless asked from the menu. + stamp = self.cache.config_directory + 'network_login.stamp' + if not force and os.path.exists(stamp) and time.time() - os.path.getmtime(stamp) < 600: + return False + self.cache.save_file('network_login.stamp', str(int(time.time()))) + success, reason = kodimov.network_login(self, kodimov.find_account_number(self, account_number)) + LOG('network login: {} {}'.format(success, reason)) + self.network_login_result = (success, reason) + if success: + self.account['access_token'] = self.cache.load_file('access_token.conf') + self.expired_access_token = False + self.cache.remove_file('tokens.json') + return success + def get_token(self): data = {"accountNumber": self.account['id'], "userProfile": self.account['profile_id'], @@ -666,6 +692,7 @@ class Movistar(object): t['subscribed'] = self.is_subscribed_channel(c.get('tvProducts', [])) t['info']['playcount'] = 1 # Set as watched t['uid'] = c.get('Uid') + t['watermark'] = bool(c.get('QMWatermark')) if False and 'links' in c: for l in c['links']: if l['rel'] == 'watermarks': @@ -684,6 +711,8 @@ class Movistar(object): res.append(t) + if self.hide_unplayable: + res = [t for t in res if kodimov.is_playable(t)] return res def get_channels_with_epg(self): @@ -1375,7 +1404,7 @@ class Movistar(object): t['logo'] = c['art']['icon'] t['preset'] = c['dial'] args = urlencode({'action': 'play', 'stype': 'tv', 'id': c['id'], 'url': c['url'], 'session_request': c['session_request']}) - t['stream'] = 'plugin://plugin.video.movistarplus/?' + args + t['stream'] = 'plugin://plugin.video.kodimovplus/?' + args if 'cas_id' in c: t['cas_id'] = c['cas_id'] res.append(t) return res @@ -1390,9 +1419,10 @@ class Movistar(object): item = '#EXTINF:-1 tvg-name="{name}" tvg-id="{id}" tvg-logo="{logo}" tvg-chno="{preset}" {catchup} group-title="Movistar+",{name}\n{stream}\n\n'.format( name=t['name'], id=t['id'], logo=t['logo'], preset=t['preset'], stream=url, catchup='catchup="default" catchup-source="{catchup-id}" catchup-days="7"') items.append(item) - res = '#EXTM3U\n## Movistar+\n{}'.format(''.join(items)) - with io.open(filename, 'w', encoding='utf-8', newline='') as handle: - handle.write(res) + if self.add_extra_channels: + items.append(kodimov.extra_channels_m3u8()) + res = '#EXTM3U\n## KodiMov+\n{}'.format(''.join(items)) + return kodimov.write_if_changed(filename, res) def export_epg(self, date=None, duration=2): if sys.version_info[0] >= 3: @@ -1419,7 +1449,7 @@ class Movistar(object): url = 'https://grmovistar.imagenio.telefonica.net/asfe/rest/tvMediaURLs?tvProgram.id='+ program_id +'&svc=startover' session_request = '{"contentID":' + program_id +',"streamType":"CUTV"}' args = urlencode({'action': 'play', 'stype': 'u7d', 'id': program_id, 'url': url, 'session_request': session_request}) - t['stream'] = 'plugin://plugin.video.movistarplus/?' + args + t['stream'] = 'plugin://plugin.video.kodimovplus/?' + args if False and self.add_extra_info and id in ['HOLLYW', 'TCM', 'AMC', 'MV3', 'MV2', 'CPSER', 'FOXGE', 'TNT']: i = {'id': e['id'], 'show_id': e['show_id']} diff --git a/resources/lib/plugin.py b/resources/lib/plugin.py index 508bbd0..c7691a9 100644 --- a/resources/lib/plugin.py +++ b/resources/lib/plugin.py @@ -662,6 +662,20 @@ def login(): else: show_notification(addon.getLocalizedString(30166)) # Failed +def network_login(): + account_number = addon.getSetting('account_number') + if not account_number and not m.cache.load_file('account.json') and not m.cache.load_file('tokens.json'): + account_number = input_window(addon.getLocalizedString(30502)) # Account number + if not account_number: return + addon.setSetting('account_number', account_number) + # Keeps device_id.conf: clearing the session would register a new device. + if m.try_network_login(account_number, force=True): + show_notification(addon.getLocalizedString(30503), xbmcgui.NOTIFICATION_INFO) # Logged in + xbmc.executebuiltin('Container.Refresh') + else: + reason = (m.network_login_result or (False, ''))[1] + show_notification(addon.getLocalizedString(30504).format(reason)) # Failed + def login_with_key(): filename = xbmcgui.Dialog().browseSingle(1, addon.getLocalizedString(30182), '', '.key') if filename: @@ -686,6 +700,7 @@ def export_credentials(): def select_account(id, name): m.switch_account(id) open_folder(name) + add_menu_option(addon.getLocalizedString(30501), get_url(action='network_login')) # Login from home network add_menu_option(addon.getLocalizedString(30183), get_url(action='login')) # Login with username if addon.getSettingBool('enable_key_login'): add_menu_option(addon.getLocalizedString(30181), get_url(action='login_with_key')) # Login with key @@ -750,11 +765,17 @@ def create_iptv_settings(): if os.path.exists(filename): res = xbmcgui.Dialog().yesno(addon.getLocalizedString(30322), addon.getLocalizedString(30323)) if res == False: return - save_iptv_settings(filename, 'Movistarplus', 'movistarplus', epg_url) + save_iptv_settings(filename, 'KodiMov+', 'kodimovplus', epg_url) export_epg_now() except: show_notification(addon.getLocalizedString(30324)) +def export_channels_now(): + if not m.logged: return + channels_filename = os.path.join(profile_dir, 'channels.m3u8') + if m.export_channels_to_m3u8(channels_filename, addon.getSettingBool('only_subscribed')): + LOG('export_channels_now: channel list changed') + def export_epg_now(): def report_progress(message): show_notification(addon.getLocalizedString(30314).format(message), xbmcgui.NOTIFICATION_INFO) @@ -816,6 +837,10 @@ def router(paramstring): login_with_key() elif params['action'] == 'login': login() + elif params['action'] == 'network_login': + network_login() + elif params['action'] == 'export_channels_now': + export_channels_now() elif params['action'] == 'export_key': export_key() elif params['action'] == 'export_credentials': @@ -880,8 +905,10 @@ def router(paramstring): add_menu_option(addon.getLocalizedString(30112), get_url(action='search'), icon='search.png') # Search add_menu_option(addon.getLocalizedString(30180), get_url(action='profiles'), icon='profiles.png') # Profiles add_menu_option(addon.getLocalizedString(30108), get_url(action='devices'), icon='devices.png') # Devices - elif m.expired_access_token: - show_notification(addon.getLocalizedString(30208)) + else: + if m.expired_access_token: + show_notification(addon.getLocalizedString(30208)) + add_menu_option(addon.getLocalizedString(30501), get_url(action='network_login'), icon='account.png') # Login from home network add_menu_option(addon.getLocalizedString(30160), get_url(action='accounts'), icon='account.png') # Accounts add_menu_option(addon.getLocalizedString(30450), get_url(action='show_donation_dialog'), icon='qr.png') # Donation @@ -902,8 +929,12 @@ def run(): reuse_devices = addon.getSettingBool('reuse_devices') LOG('profile_dir: {}'.format(profile_dir)) LOG('reuse_devices: {}'.format(reuse_devices)) - m = Movistar(profile_dir, reuse_devices=reuse_devices) + m = Movistar(profile_dir, reuse_devices=reuse_devices, + network_login=addon.getSettingBool('network_login'), + account_number=addon.getSetting('account_number')) m.add_extra_info = addon.getSettingBool('add_extra_info') + m.hide_unplayable = addon.getSettingBool('hide_unplayable') + m.add_extra_channels = addon.getSettingBool('extra_channels') if addon.getSettingBool('uhd'): m.quality = 'UHD' diff --git a/resources/lib/proxy.py b/resources/lib/proxy.py index 0d9545c..df8b198 100644 --- a/resources/lib/proxy.py +++ b/resources/lib/proxy.py @@ -78,7 +78,9 @@ def mvs(): if not mvs_o: from .movistar import Movistar reuse_devices = addon.getSettingBool('reuse_devices') - mvs_o = Movistar(profile_dir, reuse_devices) + mvs_o = Movistar(profile_dir, reuse_devices, + network_login=addon.getSettingBool('network_login'), + account_number=addon.getSetting('account_number')) return mvs_o @@ -263,7 +265,7 @@ class RequestHandler(BaseHTTPRequestHandler): HOST = '127.0.0.1' -PORT = 57011 +PORT = 57031 class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): daemon_threads = True diff --git a/resources/lib/signature.py b/resources/lib/signature.py new file mode 100644 index 0000000..452a2b0 --- /dev/null +++ b/resources/lib/signature.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# encoding: utf-8 +# +# SPDX-License-Identifier: LGPL-2.1-or-later + +from __future__ import unicode_literals, absolute_import, division + +import hmac +import hashlib +import time +import random +import string +from urllib.parse import urlparse, urlsplit, parse_qs, urlencode, quote, unquote +from .b64 import encode_base64, decode_base64 +from .log import LOG + +def generate_nonce(length=24): + characters = string.ascii_lowercase + string.digits + nonce = ''.join(random.choice(characters) for _ in range(length)) + return encode_base64(nonce) + +def create_signature(method, url, token, scheme): + consumer_key = 'web_1.0.0' + consumer_secret = 'Rk1Qc2RaREJ0M1h1MkUwRWtJRmlxWGtpOVpOZFlGN3I=' + + nonce = generate_nonce() + #print('nonce', nonce) + + timestamp = int(time.time()) + + parsed_url = urlsplit(url) + path = parsed_url.netloc + parsed_url.path + query = parse_qs(parsed_url.query, keep_blank_values=True) + + options = { scheme: token, 'consumer_key': consumer_key, 'nonce': nonce, + 'signature_method': 'HMAC-SHA1', 'version': '1.0', 'timestamp': timestamp} + for k, v in query.items(): + options[k] = quote(v[0]) + + query_string = "&".join("{}={}".format(key, value) for key, value in sorted(options.items())) + #print(query_string) + + text = '{}&{}&{}'.format(method.upper(), quote(path, safe=''), quote(query_string, safe='')) + #print(text) + + key = decode_base64(consumer_secret.encode('utf-8')).encode('utf-8') + hashed = hmac.new(key, text.encode('utf-8'), hashlib.sha1).digest() + signature = encode_base64(hashed) + + res = 'consumer_key="{}",nonce="{}",signature_method="HMAC-SHA1",signature="{}",timestamp="{}",version="1.0"'.format(consumer_key, nonce, signature, timestamp) + return encode_base64(res) + +def get_auth(method, url, token, scheme='Bearer'): + signature = create_signature(method, url, token, scheme) + return 'OPPlus {}={},Signature={}'.format(scheme, token, signature) diff --git a/resources/settings.xml b/resources/settings.xml index 3719206..44293c7 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -1,5 +1,10 @@ + + + + + @@ -11,7 +16,7 @@ @@ -34,8 +39,8 @@ - - + + --> @@ -47,7 +52,7 @@ - + + - + diff --git a/resources/skins/default/1080i/customdialog.xml b/resources/skins/default/1080i/customdialog.xml index 2fdd7a3..c45d43d 100644 --- a/resources/skins/default/1080i/customdialog.xml +++ b/resources/skins/default/1080i/customdialog.xml @@ -43,7 +43,7 @@ 1030 70 font20_title - + center center FF000000 diff --git a/service.py b/service.py index fe89b5e..9e29564 100644 --- a/service.py +++ b/service.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import os +import time import xbmc import xbmcgui from resources.lib.proxy import Proxy @@ -29,7 +30,7 @@ def export_epg(): LOG('channels_needs_update: {} epg_needs_update: {}'.format(channels_needs_update, epg_needs_update)) if channels_needs_update or epg_needs_update: - xbmc.executebuiltin('RunPlugin(plugin://plugin.video.movistarplus/?action=export_epg_now)') + xbmc.executebuiltin('RunPlugin(plugin://plugin.video.kodimovplus/?action=export_epg_now)') if __name__ == '__main__': LOG('Service started') @@ -43,9 +44,16 @@ if __name__ == '__main__': except: pass + # Refreshes the TV guide channel list (new channels, new numbers) every + # 6 hours. Opening the add-on also renews the 10-day Movistar login. + next_export = time.time() + 60 monitor = xbmc.Monitor() while not monitor.abortRequested(): if monitor.waitForAbort(1): break + if time.time() >= next_export: + next_export = time.time() + 6 * 3600 + if addon.getSettingBool('export_channels') and not addon.getSettingBool('export_epg'): + xbmc.executebuiltin('RunPlugin(plugin://plugin.video.kodimovplus/?action=export_channels_now)') proxy.stop()