Pythonで解析しようとしている大きなjson文字列があります。基本的に、この文字列には iptv ストリームが含まれています。
xmbc/kodi のアドオンを開発しようとしています。
文字列の例: http://pastebin.com/SmEGXaN9
また、ストリームを LIVE と VOD の 2 つの異なるストリームに分割する必要があります。これを正規表現で行うことはできますか?
json LIVE ストリームには "live":"1" があり、VOD には "live":0" があります
"live":"(.+?)" をキャプチャしてから if ステートメントを実行して LIVE か VOD かを確認しようとしましたが、何らかの理由で "live":"1" が返されないことがあります。
if ステートメントの代わりに正規表現でストリームを分割することは可能ですか?
LIVEグラブの機能は次のとおりです。
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("\/","/"),'')
LIVE ストリームの場合、name、stream_id、stream_icon の3 つを取得する必要があります。
VODグラブの機能は次のとおりです。
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
VOD ストリームの場合、name、stream_id、container_extension、stream_icon の4 つをキャプチャする必要があります。
誰かが私の必要に応じて正しいtregexを構築するのを手伝ってくれますか?また、それが何をどのように機能させるかを正確に説明してください. Python 正規表現のドキュメントは、私にとってかなり複雑です。