I have big json string, that i am trying to parse with python. Basicly this string contains iptv streams.
I am trying to develope addon for xmbc/kodi.
String example: http://pastebin.com/SmEGXaN9
I also need to split streams to 2 different ones: LIVE and VOD, can i do this with regex ?
In json LIVE streams have "live":"1" and VOD has "live":0"
I try to capture "live":"(.+?)" and then do if statement to see if its LIVE or VOD, but sometimes it doesnt return any "live":"1" for some reason.
Is it possible to split streams up with regex instead of if statement?
Here is function for LIVE grabbing:
def LIVE(url):
xbmcplugin.addSortMethod( handle=int( sys.argv[ 1 ] ), sortMethod=xbmcplugin.SORT_METHOD_TITLE )
vidlocation=('%s:%s/live/%s/%s/'%(site,port,usern,passw))
link = OPEN_URL(url) #GET DATA FROM JSON API
match=re.compile('{"name":"(.+?)","stream_id":"(.+?)","stream_icon":"(.+?)","live":"(.+?)"').findall(link)
for name,streamid,iconimage,live in match:
if "1" in live:
addLink('%s'%(live),'%s%s.ts'%(vidlocation,streamid),'%s'%(iconimage).replace("\/","/"),'')
For LIVE streams i need to retrive 3 things: name,stream_id,stream_icon
Here is function for VOD grabbing:
def VOD(url):
vidlocation=('%s:%s/movie/%s/%s/'%(site,port,usern,passw))
link = OPEN_URL(url)
match=re.compile('{"name":"(.+?)","stream_id":"(.+?)","live":"(.+?)","container_extension":"(.+?)","stream_icon":"(.+?)"').findall(link)
for name,streamid,live,container,iconimage in match:
if not "1" in live:
addLink3('%s'%(name),'%s%s.%s'%(vidlocation,streamid,container),'','%s'%(iconimage).replace("\/","/"),'','PLOT')
else:
#novod
For VOD streams i need to capture 4 things: name,stream_id,container_extension;stream_icon
Can someone help me build correct tregex for my need, and also please explain exactly what and how it does work. Python regex documentation is pretty complex for me.