diff --git a/addon.xml b/addon.xml index dc1b0f5..8acd5de 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ diff --git a/resources/lib/endpoints.py b/resources/lib/endpoints.py index fe8a30e..1d71202 100644 --- a/resources/lib/endpoints.py +++ b/resources/lib/endpoints.py @@ -32,5 +32,6 @@ endpoints = { "setUpStream": "https://alkasvaspub.imagenio.telefonica.net/asvas/ccs/{PID}/{deviceCode}/{PLAYREADYID}/Session", "tearDownStream": "https://alkasvaspub.imagenio.telefonica.net/asvas/ccs/{PID}/{deviceCode}/{PLAYREADYID}/Session/{SessionID}", "token": "https://auth.dof6.com/auth/oauth2/token?deviceClass={deviceType}", - "ultimasreproducciones": "https://perso.dof6.com/movistarplus/{deviceType}/users/{DIGITALPLUSUSERIDC}/viewings?profile={PROFILE}&container=trackedseries&mediaType=FOTOH&idsOnly={idsOnly}&accountNumber={ACCOUNTNUMBER}&version=8&start={start}&end={end}&mdrm={mdrm}&tlsstream=true&demarcation={demarcation}" + "ultimasreproducciones": "https://perso.dof6.com/movistarplus/{deviceType}/users/{DIGITALPLUSUSERIDC}/viewings?profile={PROFILE}&container=trackedseries&mediaType=FOTOH&idsOnly={idsOnly}&accountNumber={ACCOUNTNUMBER}&version=8&start={start}&end={end}&mdrm={mdrm}&tlsstream=true&demarcation={demarcation}", + "watermarks": "https://ottcache.dof6.com/movistarplus/{deviceType}/channels/{uid}/watermarks?profile={profile}&mdrm=true" } diff --git a/resources/lib/movistar.py b/resources/lib/movistar.py index dbb281f..bd59508 100644 --- a/resources/lib/movistar.py +++ b/resources/lib/movistar.py @@ -661,6 +661,11 @@ class Movistar(object): t['session_request'] = '{"contentID":"'+ t['id'] +'", "streamType":"CHN"}' t['subscribed'] = self.is_subscribed_channel(c.get('tvProducts', [])) t['info']['playcount'] = 1 # Set as watched + t['uid'] = c.get('Uid') + if False and 'links' in c: + for l in c['links']: + if l['rel'] == 'watermarks': + t['watermark_url'] = l['href'] # epg #if add_epg_info: # program = c['Pases'][0] @@ -1378,8 +1383,8 @@ class Movistar(object): if only_subscribed and not t['subscribed']: continue url = t['stream'] if 'cas_id' in t: url += '&cas_id=' + t['cas_id'] - item = '#EXTINF:-1 tvg-name="{name}" tvg-id="{id}" tvg-logo="{logo}" tvg-chno="{preset}" group-title="Movistar+",{name}\n{stream}\n\n'.format( - name=t['name'], id=t['id'], logo=t['logo'], preset=t['preset'], stream=url) + 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: @@ -1479,7 +1484,7 @@ class Movistar(object): if url: url = url.replace('&', '&') res.append('\n' + ' {}\n'.format(html_escape(e['title'])) + ' {}\n'.format(html_escape(e['subtitle']))) @@ -1589,3 +1594,21 @@ class Movistar(object): content = unicode(content, 'utf-8') with io.open(filename, 'w', encoding='utf-8') as handle: handle.write(content) + + def get_watermarks(self, uid, test=False): + if test: + now = datetime.utcnow() + watermarks = [] + start = now + timedelta(seconds=20) + for i in range(5): + stop = start + timedelta(seconds=18) + watermarks.append({ + 'start': start.strftime('%Y-%m-%dT%H:%M:%SZ'), + 'stop': stop.strftime('%Y-%m-%dT%H:%M:%SZ') + }) + start = start + timedelta(minutes=1) + return watermarks + else: + url = self.endpoints['watermarks'].format(deviceType='webplayer', uid=uid, profile='OTT') + data = self.net.load_data(url) + return data.get('watermarks', []) diff --git a/resources/lib/plugin.py b/resources/lib/plugin.py index b45c848..508bbd0 100644 --- a/resources/lib/plugin.py +++ b/resources/lib/plugin.py @@ -8,6 +8,8 @@ import sys import json import io import os.path +from datetime import datetime, timedelta +from .timeconv import isodate2date import xbmc import xbmcgui @@ -96,13 +98,12 @@ def play(params): # url = url.replace('DASH_WPC_WIDEVINE', 'DASH_TV_WIDEVINE') # U7D from start and end times - if stype == 'tv' and all(param in params for param in ['cas_id', 'start_time', 'end_time']): - from datetime import datetime - start = datetime.utcfromtimestamp(int(params['start_time'])) - end = datetime.utcfromtimestamp(int(params['end_time'])) - catchup_url = 'https://stover-wp0.cdn.telefonica.com/{cas_id}/vxfmt=dp/Manifest.mpd?device_profile=DASH_TV_WIDEVINE&start_time={start_time}&end_time={end_time}' - url = catchup_url.format(cas_id=params['cas_id'], start_time=start.strftime('%Y-%m-%dT%H:%M:%SZ'), end_time=end.strftime('%Y-%m-%dT%H:%M:%SZ')) - LOG('url from capchup: {}'.format(url)) + #if stype == 'tv' and all(param in params for param in ['cas_id', 'start_time', 'end_time']): + # start = datetime.utcfromtimestamp(int(params['start_time'])) + # end = datetime.utcfromtimestamp(int(params['end_time'])) + # catchup_url = 'https://stover-wp0.cdn.telefonica.com/{cas_id}/vxfmt=dp/Manifest.mpd?device_profile=DASH_TV_WIDEVINE&start_time={start_time}&end_time={end_time}' + # url = catchup_url.format(cas_id=params['cas_id'], start_time=start.strftime('%Y-%m-%dT%H:%M:%SZ'), end_time=end.strftime('%Y-%m-%dT%H:%M:%SZ')) + # LOG('url from capchup: {}'.format(url)) # Read the proxy address @@ -126,7 +127,14 @@ def play(params): cdn_token = m.cache.load('cdn.conf', 60) if not cdn_token: cdn_token = m.get_cdntoken() - m.cache.save_file('cdn.conf', cdn_token) + if not cdn_token: + time.sleep(2) + cdn_token = m.get_cdntoken() + if cdn_token: + m.cache.save_file('cdn.conf', cdn_token) + else: + show_notification('Ha pasado algo') + return #LOG('cdn_token: {}'.format(cdn_token)) manifest_headers += '&x-tcdn-token=' + cdn_token @@ -239,32 +247,39 @@ def play(params): xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item) LOG('**** session_opened: {}'.format(session_opened)) - is_sport_channel = (stype == 'tv' and channel_id in ['MLIGA', 'DAZNLI', 'MLIG1', 'CHAPIO', 'CHAP1', 'CHAP2', 'MLIGUH', 'CHAUHD', 'CHUHD1']) - if session_opened or is_sport_channel: - if is_sport_channel: - last_time = 0 #time.time() - window = xbmcgui.Window(12005) - label = xbmcgui.ControlLabel(0, 0, 400, 20, m.account['id'], textColor='0xFFFFFFFF', alignment=6) + watermarks = [] + if stype == 'tv' and 'uid' in params: + watermarks = m.get_watermarks(params['uid']) + LOG('watermarks: {}'.format(watermarks)) + + if session_opened or watermarks: + window = xbmcgui.Window(12005) + label = xbmcgui.ControlLabel(0, 0, 400, 20, m.account['id'], textColor='0xFFFFFFFF', alignment=6) from .player import MyPlayer player = MyPlayer() monitor = xbmc.Monitor() while not monitor.abortRequested() and player.running: monitor.waitForAbort(10) #LOG('**** waiting') - if is_sport_channel and player.isPlaying(): - now = time.time() - if now - last_time >= 15*60: - last_time = now - #show_notification(m.account['id'], xbmcgui.NOTIFICATION_INFO) - w = window.getWidth() - h = window.getHeight() - #LOG('window h: {} w: {}'.format(h, w)) - pos_x = w-label.getWidth()-60 - pos_y = h-200 - label.setPosition(pos_x, pos_y) - window.addControl(label) - time.sleep(20) - window.removeControl(label) + if player.isPlaying() and watermarks: + now = isodate2date(datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')) + for wm in list(watermarks): + start = isodate2date(wm['start']) + stop = isodate2date(wm['stop']) + if now >= start: + watermarks.remove(wm) + if now < stop: + duration = (stop - start).total_seconds() + #show_notification(m.account['id'], xbmcgui.NOTIFICATION_INFO) + w = window.getWidth() + h = window.getHeight() + #LOG('window h: {} w: {}'.format(h, w)) + pos_x = w-label.getWidth()-60 + pos_y = h-200 + label.setPosition(pos_x, pos_y) + window.addControl(label) + time.sleep(duration) + window.removeControl(label) if session_opened: d = m.delete_session() LOG('Delete session: d: {}'.format(d)) @@ -383,6 +398,7 @@ def add_videos(category, ctype, videos, ref=None, url_next=None, url_prev=None, url = get_url(action='play', id=t['id'], url=t['url'], session_request=t['session_request'], stype=t['stream_type']) if 'show_id' in t: url += '&show_id={}'.format(t['show_id']) + if 'uid' in t: url += '&uid={}'.format(t['uid']) xbmcplugin.addDirectoryItem(_handle, url, list_item, False) elif t['type'] == 'series': list_item = xbmcgui.ListItem(label = title_name) @@ -480,7 +496,6 @@ def list_profiles(params): def list_epg(params): LOG('list_epg: {}'.format(params)) - from datetime import datetime, timedelta from .timeconv import my_strftime if 'id' in params: if not 'date' in params: @@ -725,7 +740,7 @@ def create_iptv_settings(): show_notification(addon.getLocalizedString(30319), xbmcgui.NOTIFICATION_INFO) output_file = 'instance-settings-91.xml' if kodi_version > 19 else 'settings.xml' epg_url = None - if addon.getSettingBool('use_external_epg'): + if False: #addon.getSettingBool('use_external_epg'): epg_url = addon.getSetting('epg_url') try: pvr_addon = xbmcaddon.Addon('pvr.iptvsimple') @@ -752,7 +767,7 @@ def export_epg_now(): show_notification(addon.getLocalizedString(30310), xbmcgui.NOTIFICATION_INFO) m.export_channels_to_m3u8(channels_filename, only_subscribed) - if not addon.getSettingBool('use_external_epg'): + if True: #not addon.getSettingBool('use_external_epg'): show_notification(addon.getLocalizedString(30311), xbmcgui.NOTIFICATION_INFO) m.export_epg_to_xml(epg_filename, addon.getSettingInt('export_days'), report_progress, only_subscribed) diff --git a/resources/settings.xml b/resources/settings.xml index fe33d58..3719206 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -50,9 +50,11 @@ +