#import xbmcplugin #import xbmcgui import sys import urllib import subprocess import re import json #from livestreamer import Livestreamer, StreamError, PluginError, NoPluginError #import requests #import pprint #TVxAId = int(sys.argv[1]) def createMenu(selectedValue): global menuLevel, selectedValueStepBack isFolderVal = 0 title = url = ''; jsonString = { "South America": [{ "Venezuela": [{ "name": "TRT", "link": "http://localhost:8080/youtube.php?id=FMISuJEzumE", "thumb": "https://lh4.googleusercontent.com/-qa5bLiu3HJ4/UYUDzsaUQcI/AAAAAAAAB0M/OVNxFkOnSy0/s400/logo%2520de%2520TRT%2520-%25201990s.png" }, { "name": "Life & Design TV", "link": "http://hlslive.lcdn.une.net.co/v1/AUTH_HLSLIVE/LDTV/tu1_manifest.m3u8", "thumb": "https://lh4.googleusercontent.com/-qa5bLiu3HJ4/UYUDzsaUQcI/AAAAAAAAB0M/OVNxFkOnSy0/s400/logo%2520de%2520TRT%2520-%25201990s.png" }, { "name": "Foro TV Mx", "link": "http://185417-f.akamaihd.net/i/n0tf0r0_1@81283/index_1200_av-p.m3u8?sd=10&rebase=on", "thumb": "" }, { "name": "TD+ Costa Rica", "link": "http://stream-09.vty.dailymotion.com/46/dm/1/x18w5up/live.isml/events(live-1480778102)/live-audio=128000-video=1200000.m3u8", "thumb": "" }, { "name": "La Red Chile", "link": "http://d28d7tc1ojykcy.cloudfront.net/lared/smil:lared.smil/playlist.m3u8", "thumb": "" }, { "name": "Pinguino TV Chile", "link": "rtsp://streaming.elpinguino.com:1935/live/pinguinotv", "thumb": "" }, { "name": "DW Latino", "link": "http://dwstream3-lh.akamaihd.net/i/dwstream3_live@124409/master.m3u8", "thumb": "" }, { "name": "PAT Bolivia", "link": "http://192.99.46.56:1935/patbolivia/patlapaz/playlist.m3u8", "thumb": "" }], "Cuba": [{ "name": "Cubavision", "link": "rtmp://195.154.174.31/fidelistaporsiempre playpath=cubavision swfUrl=http://releases.flowplayer.org/swf/flowplayer-3.2.18.swf pageUrl=http://www.fidelista-por-siempre.org/CubaVision-en-Vivo.aspx", "thumb": "" }] }], "North America": [{ "USA": [{ "name": "ABC News", "link": "test ABC NEWS", "thumb": "" }] }] } iconimage = "DefaultFolder.png" #RARC bring from JSON #xbmcplugin.setContent(TVxAId,'movies') # POST request to our URL [returns JSON string] #userdata = {"firstname": "John", "lastname": "Doe", "password": "jdoe123"} #resp = requests.post('http://www.google.com/user', data=userdata) jsonString = json.dumps(jsonString) jsonObject = json.loads(jsonString) for key in jsonObject: isFolderVal = 1 url = sys.argv[0] if(menuLevel == 1): title = key createPlaylist(title, iconimage, url, isFolderVal) elif(menuLevel == 2): if(key == selectedValue): for key in jsonObject[key][0].keys(): title = key selectedValueStepBack = selectedValue createPlaylist(title, iconimage, url, isFolderVal) elif(menuLevel == 3): if(key == selectedValueStepBack): for key2 in jsonObject[key][0].keys(): if(key2 == selectedValue): for key3 in jsonObject[key][0][key2]: title = key3["name"] isFolderVal = 0 url = key3["link"] createPlaylist(title, iconimage, url, isFolderVal) menuLevel+=1 #xbmcplugin.endOfDirectory(TVxAId) def createPlaylist(title, iconimage, url, isFolder): # Build URL and KODI data print("Title="+str(title)+" iconImage="+iconimage+" URL="+str(url)+" isFolder="+str(isFolder)) #listItem = xbmcgui.ListItem(title,iconImage=iconimage,thumbnailImage=iconimage) #xbmcplugin.addDirectoryItem(TVxAId,url,listItem, isFolder=isFolderVal) def playLivestream(url): # Create the Livestreamer session livestreamer = Livestreamer() #url = "https://livestream.com/canal-teleantioquia/events/3496592" #url = "https://livestream.com/teleformula/live" #url = "http://www.dailymotion.com/cdn/live/video/x4soz0v.m3u8?scheme=https&dvr=false&auth=1480646877-2562-ve8uf368-c89f84874f36d1c225d37259903a9592" #http://original.livestream.com/znsbahamas # Enable logging livestreamer.set_loglevel("debug") livestreamer.set_logoutput(sys.stdout) # Attempt to fetch streams try: streams = livestreamer.streams(url) print("DEFAULT RARC STREAM #############################################################") print(streams) print("STREAMS #############################################################") except NoPluginError: return("Livestreamer is unable to handle the URL '{0}'".format(url)) except PluginError as err: return("Plugin error: {0}".format(err)) if not streams: return("No streams found on URL '{0}'".format(url)) print("STREAM KEYS #############################################################") keys = streams.keys() keys.sort() for each in keys: print("%s: %s" % (each, streams.get(each))) m = re.search("hls", each) if m: stream2 = str(streams.get(each)) stream2 = stream2.replace("<HLSStream('", "") stream2 = stream2.replace("')>", "") else: m = re.search("best", each) stream2 = streams.get(each) stream2 = stream2.replace("<HLSStream('", "") stream2 = stream2.replace("')>", "") print("STREAM KEYS #############################################################") print(stream2) print("STREAM RARC DEFAULT#############################################################") #stream = streams["stream2"] try: fd = stream2.open() except Exception as e: print("FD ERROR #############################################################") print(str(e)) print("FD ERROR #############################################################") try: data = fd.read(1024) except Exception as e: print("DATA ERROR #############################################################") print(str(e)) print("DATA ERROR #############################################################") print("DATA STREAM #############################################################") print(data) print("DATA STREAM #############################################################") #fd.close() #item = xbmcgui.ListItem("test") #xbmc.Player().play(stream2, item) #RARC change if __name__ == '__main__': if __name__ == 'builtins': # Initialize vars menuLevel = 1 selectedValueStepBack = '' # Call first menu x = createMenu('') #print(x) #elif(menuLevel == 2): x = createMenu('South America') #print(x) #elif(menuLevel == 3): x = createMenu('Venezuela') #print(x) #print(menuLevel) #pprint.pprint(globals()) #pprint.pprint(locals())
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question