Created
February 25, 2012 21:30
-
-
Save anonymous/1910960 to your computer and use it in GitHub Desktop.
XBMC rtmpGUI plugin with multiple source lists, channel logos and distinction by language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import urllib, urllib2, cookielib | |
import string, os, re, time, datetime, sys | |
import xbmc, xbmcgui, xbmcplugin, xbmcaddon | |
#from xml.etree import ElementTree | |
from elementtree import ElementTree | |
BASE = [ | |
'http://apps.ohlulz.com/rtmpgui/list.xml', | |
#'http://localhost/links.xml', | |
] | |
def addFolder(source=None, lang=''): | |
if not lang: | |
title=BASE[source] | |
else: | |
title=lang | |
u=sys.argv[0]+"?src="+str(source)+"&lang="+lang | |
item=xbmcgui.ListItem(title, iconImage="DefaultFolder.png") | |
item.setInfo( type="Video", infoLabels={ "Title": title }) | |
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=item,isFolder=True) | |
def get_params(): | |
param=[] | |
paramstring=sys.argv[2] | |
if len(paramstring)>=2: | |
params=sys.argv[2] | |
cleanedparams=params.replace('?','') | |
if (params[-1]=='/'): | |
params=params[0:-2] | |
pairsofparams=cleanedparams.split('&') | |
param={} | |
for i in pairsofparams: | |
splitparams={} | |
splitparams=i.split('=') | |
if (len(splitparams))==2: | |
param[splitparams[0]]=splitparams[1] | |
return param | |
def listSources(): | |
if len(BASE) < 2: | |
listVideos() | |
return | |
for source in BASE: | |
addFolder(BASE.index(source)) | |
xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ) ) | |
def listLanguages(src=0): | |
xml=getURL(BASE[int(src)]) | |
tree = ElementTree.XML(xml) | |
streams = tree.findall('stream') | |
languages = [] | |
for stream in streams: | |
language = stream.findtext('language').strip() | |
if not language in languages: | |
languages.append(language) | |
languages = list(set(languages)) | |
languages.sort() | |
if len(languages) < 2: | |
listVideos(src, languages[0]) | |
return | |
for lang in languages: | |
addFolder(src, lang) | |
xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ) ) | |
def listVideos(src=0,lang=''): | |
xml=getURL(BASE[int(src)]) | |
tree = ElementTree.XML(xml) | |
streams = tree.findall('stream') | |
for stream in streams: | |
language = stream.findtext('language').strip() | |
if language == lang and language.find('Link Down') == -1 : | |
title = stream.findtext('title') | |
rtmplink = stream.findtext('link')+' playpath='+stream.findtext('playpath')+' swfurl='+stream.findtext('swfUrl')+' pageurl='+stream.findtext('pageUrl') | |
logo=stream.findtext('logourl', default="DefaultTVShows.png") | |
item=xbmcgui.ListItem(title, iconImage=logo) | |
item.setInfo( type="Video", infoLabels={'title':title}) | |
item.setProperty('IsPlayable', 'true') | |
xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=rtmplink,listitem=item,isFolder=False) | |
xbmcplugin.endOfDirectory( handle=int( sys.argv[ 1 ] ) ) | |
def getURL( url ): | |
print 'RTMPGUI --> common :: getURL :: url = '+url | |
cj = cookielib.LWPCookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
opener.addheaders = [('User-Agent', 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2;)')] | |
usock=opener.open(url) | |
response=usock.read() | |
usock.close() | |
return response | |
#listVideos() | |
parms=get_params() | |
if "src" in parms and 'lang' in parms and parms['lang']: | |
listVideos(parms['src'], parms['lang']) | |
elif 'src' in parms: | |
listLanguages(parms['src']) | |
else: | |
listSources() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment