def process_vod_season(data, mediagroupid=None): items = [] if sys.version_info >= (3, 0): data['mediaItems'] = list(data['mediaItems']) for row in data['mediaItems']: context = [] label = '' description = '' program_image_large = '' duration = 0 if not check_key(row, 'title') or not check_key(row, 'id'): continue if check_key(row, 'description'): description = row['description'] if check_key(row, 'earliestBroadcastStartTime'): startsplit = int(row['earliestBroadcastStartTime']) // 1000 startT = datetime.datetime.fromtimestamp(startsplit) startT = convert_datetime_timezone(startT, "UTC", "UTC") if xbmc.getLanguage(xbmc.ISO_639_1) == 'nl': label = date_to_nl_dag(startT) + startT.strftime(" %d ") + date_to_nl_maand(startT) + startT.strftime(" %Y %H:%M ") + row['title'] else: label = (startT.strftime("%A %d %B %Y %H:%M ") + row['title']).capitalize() else: label = row['title'] if check_key(row, 'duration'): duration = int(row['duration']) if check_key(row, 'images'): program_image_large = get_image("boxart", row['images']) if check_key(row, 'videoStreams'): urldata = get_play_url(content=row['videoStreams']) if urldata and check_key(urldata, 'play_url') and check_key(urldata, 'locator'): if mediagroupid: context.append((_.ADD_TO_WATCHLIST, 'RunPlugin({context_url})'.format(context_url=plugin.url_for(func_or_url=add_to_watchlist, id=mediagroupid, type='group')), )) items.append(plugin.Item( label = label, info = { 'plot': description, 'duration': duration, 'mediatype': 'video', }, art = {'thumb': program_image_large}, path = plugin.url_for(func_or_url=play_video, type='vod', id=row['id'], duration=duration, _is_live=False), playable = True, context = context )) return items
def get_live_channels(addon=False): global backend, query_channel channels = [] rows = load_file(file='channels.json', isJSON=True) if rows: if addon == True: query_addons = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "id": 1, "method": "Addons.GetAddons", "params": {"type": "xbmc.pvrclient"}}')) addons = query_addons['result']['addons'] backend = addons[0]['addonid'] query_channel = json.loads(xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "PVR.GetChannels", "params": {"channelgroupid": "alltv", "properties" :["uniqueid"]},"id": 1}')) for row in rows: channeldata = api.get_channel_data(row=row) urldata = get_play_url(content=channeldata['stream']) if urldata and check_key(urldata, 'play_url') and check_key(urldata, 'locator'): path = plugin.url_for(play_video, type='channel', id=urldata['play_url'], locator=urldata['locator'], _is_live=True) playable = True if addon == True and 'result' in query_channel: if 'channels' in query_channel['result']: pvrchannels = query_channel['result']['channels'] for channel in pvrchannels: if channel['label'] == channeldata['label']: channel_uid = channel['uniqueid'] path = plugin.url_for(switchChannel, channel_uid=channel_uid) playable = False break channels.append({ 'label': channeldata['label'], 'channel': channeldata['channel_id'], 'chno': channeldata['channel_number'], 'description': channeldata['description'], 'image': channeldata['station_image_large'], 'path': path, 'playable': playable, }) channels[:] = sorted(channels, key=_sort_live) return channels
def get_channels_for_user(self, location): channels_url = '{channelsurl}?byLocationId={location}&includeInvisible=true&personalised=true'.format( channelsurl=settings.get('_channels_url'), location=location) data = self.download(url=channels_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False) if data and check_key(data, 'entryCount') and check_key( data, 'channels'): settings.setInt(key='_channels_age', value=time.time()) write_file(file="channels.json", data=data['channels'], isJSON=True) playlist = u'#EXTM3U\n' for row in sorted( data['channels'], key=lambda r: float(r.get('channelNumber', 'inf'))): channeldata = self.get_channel_data(row=row) urldata = get_play_url(content=channeldata['stream']) if urldata and check_key(urldata, 'play_url') and check_key( urldata, 'locator'): path = 'plugin://{addonid}/?_=play_video&type=channel&id={play_url}&locator={locator}&_l=.pvr'.format( addonid=ADDON_ID, play_url=quote(urldata['play_url']), locator=quote(urldata['locator'])) playlist += u'#EXTINF:-1 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="TV" radio="false",{name}\n{path}\n'.format( id=channeldata['channel_id'], channel=channeldata['channel_number'], name=channeldata['label'], logo=channeldata['station_image_large'], path=path) write_file(file="tv.m3u8", data=playlist, isJSON=False) combine_playlist()
def check_entitlements(**kwargs): if plugin.logged_in: user_agent = settings.get(key='_user_agent') media_groups_url = '{mediagroups_url}/lgi-nl-vod-myprime-movies?byHasCurrentVod=true&range=1-1&sort=playCount7%7Cdesc'.format(mediagroups_url=settings.get('_mediagroupsfeeds_url')) data = api.download(url=media_groups_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False) if not data or not check_key(data, 'entryCount'): gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS) settings.setBool(key='showMoviesSeries', value=False) return media_item_url = '{mediaitem_url}/{mediaitem_id}'.format(mediaitem_url=settings.get(key='_mediaitems_url'), mediaitem_id=data['mediaGroups'][0]['id']) data = api.download(url=media_item_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False) if not data or not check_key(data, 'videoStreams'): gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS) settings.setBool(key='showMoviesSeries', value=False) return urldata = get_play_url(content=data['videoStreams']) if not urldata or not check_key(urldata, 'play_url') or not check_key(urldata, 'locator'): gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS) settings.setBool(key='showMoviesSeries', value=False) return token = api.get_play_token(locator=urldata['locator'], force=True) if not token or not len(token) > 0: gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS) settings.setBool(key='showMoviesSeries', value=False) return gui.ok(message=_.YES_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS) settings.setBool(key='showMoviesSeries', value=True) return
def api_play_url(type, channel=None, id=None, video_data=None, from_beginning=0, pvr=0): playdata = { 'path': '', 'license': '', 'token': '', 'locator': '', 'type': '', 'alt_path': '', 'alt_license': '', 'alt_locator': '' } if not api_get_session(): return playdata from_beginning = int(from_beginning) pvr = int(pvr) profile_settings = load_profile(profile_id=1) if type == "channel": id = channel alt_path = '' alt_license = '' alt_locator = '' info = {} base_listing_url = CONST_API_URLS[int( profile_settings['v3'])]['listings_url'] urldata = None urldata2 = None path = None locator = None if not type or not len(unicode(type)) > 0 or not id or not len( unicode(id)) > 0: return playdata if type == 'channel': data = api_get_channels() try: split = data[id]['assetid'].rsplit('&%%&', 1) if len(split) == 2: urldata = {'play_url': split[0], 'locator': split[1]} else: return playdata except: return playdata listing_url = '{listings_url}?byEndTime={time}~&byStationId={channel}&range=1-1&sort=startTime'.format( listings_url=base_listing_url, time=int(time.time() * 1000), channel=id) download = api_download(url=listing_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key(data, 'listings'): for row in data['listings']: if check_key(row, 'program'): info = row['program'] elif type == 'program': listings_url = "{listings_url}/{id}".format( listings_url=base_listing_url, id=id) download = api_download(url=listings_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if not code or not code == 200 or not data or not check_key( data, 'program'): return playdata info = data['program'] elif type == 'vod': mediaitems_url = '{mediaitems_url}/{id}'.format( mediaitems_url=CONST_API_URLS[int( profile_settings['v3'])]['mediaitems_url'], id=id) download = api_download(url=mediaitems_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if not code or not code == 200 or not data: return playdata info = data if check_key(info, 'videoStreams'): urldata2 = get_play_url(content=info['videoStreams']) if not type == 'channel' and ( not urldata2 or not check_key(urldata2, 'play_url') or not check_key(urldata2, 'locator') or urldata2['play_url'] == 'http://Playout/using/Session/Service') and int( profile_settings['v3']) == 1: urldata2 = {} if type == 'program': playout_str = 'replay' elif type == 'vod': playout_str = 'vod' else: return playdata playout_url = '{base_url}/playout/{playout_str}/{id}?abrType=BR-AVC-DASH'.format( base_url=CONST_API_URLS[int(profile_settings['v3'])]['base_url'], playout_str=playout_str, id=id) download = api_download(url=playout_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if not code or not code == 200 or not data or not check_key( data, 'url') or not check_key(data, 'contentLocator'): return playdata urldata2['play_url'] = data['url'] urldata2['locator'] = data['contentLocator'] if urldata and urldata2 and check_key(urldata, 'play_url') and check_key( urldata, 'locator') and check_key( urldata2, 'play_url') and check_key(urldata2, 'locator'): path = urldata['play_url'] locator = urldata['locator'] alt_path = urldata2['play_url'] alt_locator = urldata2['locator'] else: if urldata and check_key(urldata, 'play_url') and check_key( urldata, 'locator'): path = urldata['play_url'] locator = urldata['locator'] elif urldata2 and check_key(urldata2, 'play_url') and check_key( urldata2, 'locator'): path = urldata2['play_url'] locator = urldata2['locator'] if not locator or not len(unicode(locator)) > 0: return playdata license = CONST_API_URLS[int(profile_settings['v3'])]['widevine_url'] alt_license = CONST_API_URLS[int(profile_settings['v3'])]['widevine_url'] token = api_get_play_token(locator=locator, path=path, force=1) if not token or not len(unicode(token)) > 0: return playdata token = 'WIDEVINETOKEN' token_regex = re.search(r"(?<=;vxttoken=)(.*?)(?=/)", path) if token_regex and token_regex.group(1) and len(token_regex.group(1)) > 0: path = path.replace(token_regex.group(1), token) else: if 'sdash/' in path: spliturl = path.split('sdash/', 1) if len(spliturl) == 2: if int(profile_settings['v3']) == 1: path = '{urlpart1}sdash;vxttoken={token}/{urlpart2}'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) else: path = '{urlpart1}sdash;vxttoken={token}/{urlpart2}?device=Orion-Replay-DASH'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) else: spliturl = path.rsplit('/', 1) if len(spliturl) == 2: path = '{urlpart1};vxttoken={token}/{urlpart2}'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) playdata = { 'path': path, 'license': license, 'token': token, 'locator': locator, 'info': info, 'type': type, 'alt_path': alt_path, 'alt_license': alt_license, 'alt_locator': alt_license } return playdata
def play_video(type=None, id=None, locator=None, catchup=None, duration=0, **kwargs): properties = {} label = '' info = {} art = {} if not type or not len(type) > 0: return False if (catchup and len(catchup) > 0) or type=='program': if catchup and len(catchup) > 0: id = catchup properties['seekTime'] = 1 type = 'program' if not id or not len(id) > 0: return False if type == "program": listings_url = "{listings_url}/{id}".format(listings_url=settings.get(key='_listings_url'), id=id) data = api.download(url=listings_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False) if not data or not check_key(data, 'program') or not check_key(data['program'], 'videoStreams'): gui.ok(message=_.STREAM_NOT_AVAILABLE, heading=_.STREAM_NOT_FOUND) return False urldata = get_play_url(content=data['program']['videoStreams']) if not urldata or not check_key(urldata, 'play_url') or not check_key(urldata, 'locator'): gui.ok(message=_.STREAM_NOT_AVAILABLE, heading=_.STREAM_NOT_FOUND) return False playdata = api.play_url(type='program', path=urldata['play_url'], locator=urldata['locator']) if check_key(data['program'], 'duration'): duration = int(data['program']['duration']) elif check_key(data, 'startTime') and check_key(data, 'endTime'): duration = int(int(data['endTime']) - int(data['startTime'])) // 1000 label = data['program']['title'] info = { 'plot': data['program']['description'], 'duration': duration, 'mediatype': 'video'} art = {'thumb': get_image("boxart", data['program']['images'])} elif type == "vod": playdata = api.play_url(type='vod', path=id) elif type == "channel": if not locator or not len(locator) > 0: return False playdata = api.play_url(type='channel', path=id, locator=locator) if not check_key(playdata, 'path') or not check_key(playdata, 'license') or not check_key(playdata, 'token') or not check_key(playdata, 'locator'): return False user_agent = settings.get(key='_user_agent') creds = get_credentials() CDMHEADERS = { 'User-Agent': user_agent, 'X-Client-Id': settings.get(key='_client_id') + '||' + user_agent, 'X-OESP-Token': settings.get(key='_access_token'), 'X-OESP-Username': creds['username'], 'X-OESP-License-Token': settings.get(key='_drm_token'), 'X-OESP-DRM-SchemeIdUri': 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed', 'X-OESP-Content-Locator': playdata['locator'], } settings.setInt(key='_stream_duration', value=duration) listitem = plugin.Item( properties = properties, label = label, info = info, art = art, playable = True, path = playdata['path'], headers = CDMHEADERS, inputstream = inputstream.Widevine( license_key = playdata['license'], media_renewal_url = plugin.url_for(func_or_url=renew_token, id=playdata['path'], type=type, locator=playdata['locator']), media_renewal_time = 60, ), ) return listitem
def play_url(self, type, path=None, locator=None): playdata = {'path': '', 'license': '', 'token': '', 'locator': ''} if not type or not len(type) > 0: return playdata if type == 'vod': if not path or not len(path) > 0: return playdata mediaitems_url = '{mediaitems_url}/{path}'.format( mediaitems_url=settings.get(key='_mediaitems_url'), path=path) data = self.download(url=mediaitems_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False) if not data or not check_key(data, 'videoStreams'): return playdata urldata = get_play_url(content=data['videoStreams']) if urldata and check_key(urldata, 'play_url') and check_key( urldata, 'locator'): path = urldata['play_url'] locator = urldata['locator'] if not path or not locator or not len(path) > 0 or not len( locator) > 0: return playdata license = settings.get('_widevine_url') token = self.get_play_token(locator=locator, force=True) if not token or not len(token) > 0: gui.ok(message=_.NO_STREAM_AUTH, heading=_.PLAY_ERROR) return playdata token = 'WIDEVINETOKEN' token_regex = re.search(r"(?<=;vxttoken=)(.*?)(?=/)", path) if token_regex and token_regex.group(1) and len( token_regex.group(1)) > 0: path = path.replace(token_regex.group(1), token) else: if 'sdash/' in path: spliturl = path.split('sdash/', 1) if len(spliturl) == 2: path = '{urlpart1}sdash;vxttoken={token}/{urlpart2}?device=Orion-Replay-DASH'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) else: spliturl = path.rsplit('/', 1) if len(spliturl) == 2: path = '{urlpart1};vxttoken={token}/{urlpart2}'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) real_url = "{hostscheme}://{hostname}".format( hostscheme=urlparse(path).scheme, hostname=urlparse(path).hostname) proxy_url = "http://127.0.0.1:{proxy_port}".format( proxy_port=settings.get(key='_proxyserver_port')) settings.set(key='_stream_hostname', value=real_url) path = path.replace(real_url, proxy_url) playdata = { 'path': path, 'license': license, 'token': token, 'locator': locator } return playdata
def api_play_url(type, channel=None, id=None, video_data=None, test=False, from_beginning=0, pvr=0): playdata = { 'path': '', 'license': '', 'token': '', 'locator': '', 'type': '', 'alt_path': '', 'alt_license': '', 'alt_locator': '' } if not api_get_session(): return playdata from_beginning = int(from_beginning) pvr = int(pvr) profile_settings = load_profile(profile_id=1) if type == "channel": id = channel alt_path = '' alt_license = '' alt_locator = '' info = {} base_listing_url = profile_settings['listings_url'] urldata = None urldata2 = None path = None locator = None if not type or not len(unicode(type)) > 0 or not id or not len( unicode(id)) > 0: return playdata if not test: counter = 0 while not xbmc.Monitor().abortRequested() and counter < 5: profile_settings = load_profile(profile_id=1) if profile_settings['test_running'] == 0: break counter += 1 query = "UPDATE `vars` SET `last_playing`={last_playing} WHERE profile_id={profile_id}".format( last_playing=int(time.time()), profile_id=1) query_settings(query=query, return_result=False, return_insert=False, commit=True) if xbmc.Monitor().waitForAbort(1): break if xbmc.Monitor().abortRequested(): return playdata if type == 'channel': query = "SELECT assetid FROM `channels` WHERE id='{channel}'".format( channel=id) data = query_epg(query=query, return_result=True, return_insert=False, commit=False) if data: for row in data: split = row['assetid'].rsplit('&%%&', 1) if len(split) == 2: urldata = {'play_url': split[0], 'locator': split[1]} else: return playdata listing_url = '{listings_url}?byEndTime={time}~&byStationId={channel}&range=1-1&sort=startTime'.format( listings_url=base_listing_url, time=int(time.time() * 1000), channel=id) download = api_download(url=listing_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if code and code == 200 and data and check_key(data, 'listings'): for row in data['listings']: if check_key(row, 'program'): info = row['program'] elif type == 'program': listings_url = "{listings_url}/{id}".format( listings_url=base_listing_url, id=id) download = api_download(url=listings_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if not code or not code == 200 or not data or not check_key( data, 'program'): return playdata info = data['program'] elif type == 'vod': mediaitems_url = '{mediaitems_url}/{id}'.format( mediaitems_url=profile_settings['mediaitems_url'], id=id) download = api_download(url=mediaitems_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if not code or not code == 200 or not data: return playdata info = data if check_key(info, 'videoStreams'): urldata2 = get_play_url(content=info['videoStreams']) if not type == 'channel' and ( not urldata2 or not check_key(urldata2, 'play_url') or not check_key(urldata2, 'locator') or urldata2['play_url'] == 'http://Playout/using/Session/Service' ) and profile_settings['base_v3'] == 1: urldata2 = {} if type == 'program': playout_str = 'replay' elif type == 'vod': playout_str = 'vod' else: return playdata playout_url = '{base_url}/playout/{playout_str}/{id}?abrType=BR-AVC-DASH'.format( base_url=profile_settings['base_url'], playout_str=playout_str, id=id) download = api_download(url=playout_url, type='get', headers=api_get_headers(), data=None, json_data=False, return_json=True) data = download['data'] code = download['code'] if not code or not code == 200 or not data or not check_key( data, 'url') or not check_key(data, 'contentLocator'): return playdata urldata2['play_url'] = data['url'] urldata2['locator'] = data['contentLocator'] if urldata and urldata2 and check_key(urldata, 'play_url') and check_key( urldata, 'locator') and check_key( urldata2, 'play_url') and check_key(urldata2, 'locator'): path = urldata['play_url'] locator = urldata['locator'] alt_path = urldata2['play_url'] alt_locator = urldata2['locator'] else: if urldata and check_key(urldata, 'play_url') and check_key( urldata, 'locator'): path = urldata['play_url'] locator = urldata['locator'] elif urldata2 and check_key(urldata2, 'play_url') and check_key( urldata2, 'locator'): path = urldata2['play_url'] locator = urldata2['locator'] if not locator or not len(unicode(locator)) > 0: return playdata license = profile_settings['widevine_url'] alt_license = profile_settings['widevine_url'] if xbmc.Monitor().abortRequested(): return playdata token = api_get_play_token(locator=locator, path=path, force=1) if not token or not len(unicode(token)) > 0: if not test: gui.ok(message=_.NO_STREAM_AUTH, heading=_.PLAY_ERROR) return playdata if not test: token = 'WIDEVINETOKEN' token_regex = re.search(r"(?<=;vxttoken=)(.*?)(?=/)", path) if token_regex and token_regex.group(1) and len(token_regex.group(1)) > 0: path = path.replace(token_regex.group(1), token) else: if 'sdash/' in path: spliturl = path.split('sdash/', 1) if len(spliturl) == 2: if profile_settings['base_v3'] == 1: path = '{urlpart1}sdash;vxttoken={token}/{urlpart2}'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) else: path = '{urlpart1}sdash;vxttoken={token}/{urlpart2}?device=Orion-Replay-DASH'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) else: spliturl = path.rsplit('/', 1) if len(spliturl) == 2: path = '{urlpart1};vxttoken={token}/{urlpart2}'.format( urlpart1=spliturl[0], token=token, urlpart2=spliturl[1]) playdata = { 'path': path, 'license': license, 'token': token, 'locator': locator, 'info': info, 'type': type, 'alt_path': alt_path, 'alt_license': alt_license, 'alt_locator': alt_license } return playdata