def enigma_epg_information(e2servicereference): #Check the current settings SettingHost = var.addon.getSetting('host') if SettingHost.endswith('.') or SettingHost.endswith('0') or not SettingHost[-1].isdigit(): notificationIcon = func.path_resources('resources/skins/default/media/common/settings.png') xbmcgui.Dialog().notification(var.addonname, 'Please check the ip address.', notificationIcon, 2500, False) return RequestUrl = 'http://' + SettingHost + '/web/epgservicenow?sRef=' + hybrid.urllib_quote(e2servicereference) DownloadDataHttp = hybrid.urllib_urlopen(RequestUrl) DownloadDataString = DownloadDataHttp.read() DownloadDataXml = ET.ElementTree(ET.fromstring(DownloadDataString)) return DownloadDataXml
def download_search_program(programName): #Check if user is logged in if var.ApiLoggedIn == False: apilogin.ApiLogin(False) try: DownloadHeaders = { "User-Agent": var.addon.getSetting('CustomUserAgent'), "Cookie": var.ApiLoginCookie, "X-Xsrf-Token": var.ApiLoginToken } programName = hybrid.urllib_quote(programName) DownloadRequest = hybrid.urllib_request( path.search_program(programName), headers=DownloadHeaders) DownloadDataHttp = hybrid.urllib_urlopen(DownloadRequest) DownloadDataJson = json.load(DownloadDataHttp) #Check if connection is successful if DownloadDataJson['resultCode'] and DownloadDataJson[ 'errorDescription']: resultCode = DownloadDataJson['resultCode'] resultMessage = DownloadDataJson['message'] if resultCode == 'KO': var.ApiLoggedIn = False notificationIcon = path.resources( 'resources/skins/default/media/common/search.png') xbmcgui.Dialog().notification( var.addonname, 'Zoek download mislukt: ' + resultMessage, notificationIcon, 2500, False) return None return DownloadDataJson except: notificationIcon = path.resources( 'resources/skins/default/media/common/search.png') xbmcgui.Dialog().notification(var.addonname, 'Zoek download mislukt.', notificationIcon, 2500, False) return None
def list_update_recordings(self, forceUpdate): if var.busy_recordings == True: notificationIcon = func.path_resources( 'resources/skins/default/media/common/refresh.png') xbmcgui.Dialog().notification(var.addonname, 'Already refreshing.', notificationIcon, 2500, False) return var.busy_recordings = True listcontainer = self.getControl(1001) #Check if update is needed if not forceUpdate: if listcontainer.size() > 0: var.busy_recordings = False return #Clear recordings from the list listcontainer.reset() #Update the load status func.updateLabelText(self, 1, 'Loading recordings') #Get recordings from enigma try: list_items = enigma.enigma_list_recordings() except: func.updateLabelText(self, 1, 'Load failed') var.busy_recordings = False return #Update the load status func.updateLabelText(self, 1, 'Checking recordings') #Check recordings list if list_items == None: func.updateLabelText(self, 1, 'No recordings') var.busy_recordings = False return #List enigma recordings ChannelNumber = 0 controls = list_items.findall('e2movie') for control in controls: e2title = control.find('e2title').text e2title = hybrid.urllib_unquote(e2title) e2filename = control.find('e2filename').text e2filename = hybrid.urllib_quote(e2filename) e2servicename = control.find('e2servicename').text if func.string_isnullorempty(e2servicename): e2servicename = 'Unknown' e2description = control.find('e2description').text if func.string_isnullorempty(e2description): e2description = 'Unknown' e2descriptionextended = control.find('e2descriptionextended').text if func.string_isnullorempty(e2descriptionextended): e2descriptionextended = 'Unknown' e2time = int(control.find('e2time').text) e2length = control.find('e2length').text + 'min' ChannelNumber += 1 ChannelName = '[COLOR grey]' + str( ChannelNumber) + '[/COLOR] ' + e2title #Get the recording time ProgramRecordedDateTime = time.localtime(e2time) ProgramRecordedDate = time.strftime("%a %d %b %Y", ProgramRecordedDateTime) ProgramRecordedTime = time.strftime("%H:%M", ProgramRecordedDateTime) ProgramRecordedString = e2servicename + ' on ' + ProgramRecordedDate + ' at ' + ProgramRecordedTime + ' duration ' + e2length #Set the recording description ProgramDescription = '[COLOR dimgrey]' + ProgramRecordedString + '[/COLOR]\n\n' + e2descriptionextended + '\n\n[COLOR dimgrey]' + e2description + '[/COLOR]' listitem = xbmcgui.ListItem() listitem.setProperty('ChannelNumber', str(ChannelNumber)) listitem.setProperty('ChannelName', ChannelName) listitem.setProperty('ProgramNameNow', ProgramRecordedString) listitem.setProperty('ProgramDescription', ProgramDescription) listitem.setProperty('e2title', e2title) listitem.setProperty('e2filename', e2filename) listitem.setInfo('video', {'Genre': 'Recording'}) listcontainer.addItem(listitem) #Update the total list count total_items = listcontainer.size() func.updateLabelText(self, 1, str(total_items) + ' recordings') #Focus on the item list if total_items > 0: self.setFocus(listcontainer) xbmc.sleep(200) var.busy_recordings = False
def play_stream_recorded(listItem, Windowed): #Check if user is logged in if var.ApiLoggedIn == False: apilogin.ApiLogin(False) #Download the program stream url try: DownloadHeaders = { "User-Agent": var.addon.getSetting('CustomUserAgent'), "Cookie": var.ApiLoginCookie, "X-Xsrf-Token": var.ApiLoginToken } #Get and set the stream asset id ProgramAssetId = listItem.getProperty('ProgramAssetId') ProgramRecordEventId = listItem.getProperty('ProgramRecordEventId') #Check the set stream asset id if func.string_isnullorempty( ProgramAssetId) or func.string_isnullorempty( ProgramRecordEventId): notificationIcon = path.resources( 'resources/skins/default/media/common/recorddone.png') xbmcgui.Dialog().notification( var.addonname, 'Opname is niet speelbaar, wegens stream rechten.', notificationIcon, 2500, False) return DownloadRequest = hybrid.urllib_request(path.stream_url_recording( ProgramRecordEventId, ProgramAssetId), headers=DownloadHeaders) DownloadDataHttp = hybrid.urllib_urlopen(DownloadRequest) DownloadDataJson = json.load(DownloadDataHttp) except: notificationIcon = path.resources( 'resources/skins/default/media/common/recorddone.png') xbmcgui.Dialog().notification(var.addonname, 'Opname is niet gevonden.', notificationIcon, 2500, False) return #Check if connection is successful if DownloadDataJson['resultCode'] and DownloadDataJson['errorDescription']: resultCode = DownloadDataJson['resultCode'] resultMessage = DownloadDataJson['message'] if resultCode == 'KO': var.ApiLoggedIn = False notificationIcon = path.resources( 'resources/skins/default/media/common/recorddone.png') xbmcgui.Dialog().notification( var.addonname, 'Opname is niet beschikbaar: ' + resultMessage, notificationIcon, 2500, False) return #Check the target resolution if var.addon.getSetting('StreamResolution') == '2160p': targetResolution = '10000000' elif var.addon.getSetting('StreamResolution') == '1080p': targetResolution = '6000000' elif var.addon.getSetting('StreamResolution') == '720p': targetResolution = '4000000' elif var.addon.getSetting('StreamResolution') == '576p': targetResolution = '2500000' elif var.addon.getSetting('StreamResolution') == '432p': targetResolution = '1600000' elif var.addon.getSetting('StreamResolution') == '360p': targetResolution = '1200000' #Set stream headers dictionary StreamHeadersDict = {"User-Agent": var.addon.getSetting('CustomUserAgent')} #Create stream headers string StreamHeaders = '' for name, value in StreamHeadersDict.items(): StreamHeaders += '&' + name + '=' + hybrid.urllib_quote(value) StreamHeaders = StreamHeaders.replace('&', '', 1) #Get and adjust the stream url try: StreamUrl = DownloadDataJson['resultObj']['src']['sources']['src'] StreamUrl = StreamUrl.replace('&max_bitrate=1200000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=1600000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=2500000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=4000000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=6000000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=10000000', '&max_bitrate=' + targetResolution) StreamUrl += '&drm=clear' except: notificationIcon = path.resources( 'resources/skins/default/media/common/recorddone.png') xbmcgui.Dialog().notification(var.addonname, 'Stream is niet beschikbaar.', notificationIcon, 2500, False) return #Set input adaptive stream listItem.setProperty(hybrid.inputstreamname, 'inputstream.adaptive') listItem.setProperty('inputstream.adaptive.manifest_type', 'mpd') listItem.setProperty('inputstream.adaptive.stream_headers', StreamHeaders) #Get and set stream license key try: AdaptiveLicenseUrl = DownloadDataJson['resultObj']['src']['sources'][ 'contentProtection']['widevine']['licenseAcquisitionURL'] AdaptivePostData = 'R{SSM}' AdaptiveResponse = '' listItem.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') listItem.setProperty( 'inputstream.adaptive.license_key', AdaptiveLicenseUrl + "|" + StreamHeaders + "|" + AdaptivePostData + "|" + AdaptiveResponse) except: pass #Update the list item name label listItem.setLabel(listItem.getProperty('ProgramName')) #Set stream start offset in seconds listItem.setProperty('StartOffset', '120') #Set internet stream property listItem.setProperty("get_stream_details_from_player", 'true') #Start playing the media var.PlayerCustom.PlayCustom(StreamUrl, listItem, Windowed, False)
def play_stream_television(listItem, Windowed): #Get channel settings and variables NewAssetId = listItem.getProperty('AssetId') NewChannelId = listItem.getProperty('ChannelId') NewExternalId = listItem.getProperty('ExternalId') NewChannelName = listItem.getProperty('ChannelName') CurrentAssetId = var.addon.getSetting('CurrentAssetId') CurrentChannelId = var.addon.getSetting('CurrentChannelId') CurrentExternalId = var.addon.getSetting('CurrentExternalId') CurrentChannelName = var.addon.getSetting('CurrentChannelName') #Allow longer back seeking DateTimeUtc = datetime.utcnow() - timedelta( minutes=int(var.addon.getSetting('StreamSeekMinutes'))) StartString = '&time=' + str(func.datetime_to_ticks(DateTimeUtc)) #Check if user is logged in if var.ApiLoggedIn == False: apilogin.ApiLogin(False) #Download the television stream url try: DownloadHeaders = { "User-Agent": var.addon.getSetting('CustomUserAgent'), "Cookie": var.ApiLoginCookie, "X-Xsrf-Token": var.ApiLoginToken } RequestUrl = path.stream_url_tv(NewChannelId, NewAssetId) + StartString DownloadRequest = hybrid.urllib_request(RequestUrl, headers=DownloadHeaders) DownloadDataHttp = hybrid.urllib_urlopen(DownloadRequest) DownloadDataJson = json.load(DownloadDataHttp) except: notificationIcon = path.resources( 'resources/skins/default/media/common/television.png') xbmcgui.Dialog().notification(var.addonname, 'Zender is niet gevonden.', notificationIcon, 2500, False) return #Check if connection is successful if DownloadDataJson['resultCode'] and DownloadDataJson['errorDescription']: resultCode = DownloadDataJson['resultCode'] resultMessage = DownloadDataJson['message'] if resultCode == 'KO': var.ApiLoggedIn = False notificationIcon = path.resources( 'resources/skins/default/media/common/television.png') xbmcgui.Dialog().notification( var.addonname, 'Zender is niet beschikbaar: ' + resultMessage, notificationIcon, 2500, False) return #Check the target resolution if var.addon.getSetting('StreamResolution') == '2160p': targetResolution = '10000000' elif var.addon.getSetting('StreamResolution') == '1080p': targetResolution = '6000000' elif var.addon.getSetting('StreamResolution') == '720p': targetResolution = '4000000' elif var.addon.getSetting('StreamResolution') == '576p': targetResolution = '2500000' elif var.addon.getSetting('StreamResolution') == '432p': targetResolution = '1600000' elif var.addon.getSetting('StreamResolution') == '360p': targetResolution = '1200000' #Set stream headers dictionary StreamHeadersDict = {"User-Agent": var.addon.getSetting('CustomUserAgent')} #Create stream headers string StreamHeaders = '' for name, value in StreamHeadersDict.items(): StreamHeaders += '&' + name + '=' + hybrid.urllib_quote(value) StreamHeaders = StreamHeaders.replace('&', '', 1) #Get and adjust the stream url try: StreamUrl = DownloadDataJson['resultObj']['src']['sources']['src'] StreamUrl = StreamUrl.replace('&max_bitrate=1200000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=1600000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=2500000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=4000000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=6000000', '&max_bitrate=' + targetResolution) StreamUrl = StreamUrl.replace('&max_bitrate=10000000', '&max_bitrate=' + targetResolution) StreamUrl += '&drm=clear' except: notificationIcon = path.resources( 'resources/skins/default/media/common/television.png') xbmcgui.Dialog().notification(var.addonname, 'Stream is niet beschikbaar.', notificationIcon, 2500, False) return #Update channel settings and variables if CurrentChannelId != NewChannelId: var.addon.setSetting('LastAssetId', CurrentAssetId) var.addon.setSetting('LastChannelId', CurrentChannelId) var.addon.setSetting('LastExternalId', CurrentExternalId) var.addon.setSetting('LastChannelName', CurrentChannelName) var.addon.setSetting('CurrentAssetId', NewAssetId) var.addon.setSetting('CurrentChannelId', NewChannelId) var.addon.setSetting('CurrentExternalId', NewExternalId) var.addon.setSetting('CurrentChannelName', NewChannelName) #Set input adaptive stream listItem.setProperty(hybrid.inputstreamname, 'inputstream.adaptive') listItem.setProperty('inputstream.adaptive.manifest_type', 'mpd') listItem.setProperty('inputstream.adaptive.stream_headers', StreamHeaders) listItem.setProperty('inputstream.adaptive.manifest_update_parameter', 'full') #Get and set stream license key try: AdaptiveLicenseUrl = DownloadDataJson['resultObj']['src']['sources'][ 'contentProtection']['widevine']['licenseAcquisitionURL'] AdaptivePostData = 'R{SSM}' AdaptiveResponse = '' listItem.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha') listItem.setProperty( 'inputstream.adaptive.license_key', AdaptiveLicenseUrl + "|" + StreamHeaders + "|" + AdaptivePostData + "|" + AdaptiveResponse) except: pass #Update the list item name label listItem.setLabel(NewChannelName) #Set internet stream property listItem.setProperty("get_stream_details_from_player", 'true') #Start playing the media var.PlayerCustom.PlayCustom(StreamUrl, listItem, Windowed, True)