'''
Todic plugin for XBMC
Version 0.0.2
'''
import sys
import cgi as urlparse
import xbmc
import xbmcaddon
import xbmcgui
import xbmcplugin
import urllib
import urllib2, re
__addon__ = xbmcaddon.Addon(id='plugin.video.todic')
__key__ = __addon__.getSetting('xbmckey').lower()
__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__
def open_url(url):
req = urllib2.Request(url)
content = urllib2.urlopen(req)
data = content.read()
content.close()
return data
def rootMenu():
link = open_url(__backend__)
m=re.compile('
(.+?)(.+?)').findall(link)
l = len(m)
for name,url in m:
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
u = sys.argv[0] + "?mode=1&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l)
listitem = xbmcgui.ListItem(label = "Søg ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png')
u = sys.argv[0] + "?mode=10&name=" + urllib.quote_plus(name)
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True, totalItems = l)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def buildList(url,title):
print '[TODIC]:'+str(url)
link = open_url(url)
ty=re.compile('(.+?)(.+?)(.+?)').findall(link)
l=len(m)
for name,url,thumb in m:
if ty[0] == 'clipList':
mode = '50'
folder = False
else:
mode = '2'
folder = True
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def buildSubList(url,title):
print '[TODIC]:'+str(url)
link = open_url(url)
m=re.compile('(.+?)(.+?)(.+?)').findall(link)
l = len(m)
for name,url,thumb in m:
listitem = xbmcgui.ListItem(label = name, iconImage = 'DefaultFolder.png', thumbnailImage = thumb)
u = sys.argv[0] + "?mode=50&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url)
ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = False, totalItems = l)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
def play_video(url, name):
link = open_url(url)
match=re.compile('(.+?)').findall(link)
url = match[0]
print '[TODIC]:'+str(url)
image = xbmc.getInfoImage( 'ListItem.Thumb' )
listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = image)
# listitem = xbmcgui.ListItem(label = name , iconImage = 'DefaultVideo.png', thumbnailImage = 'DefaultVideo.png')
listitem.setInfo( type = "Video", infoLabels={ "Title": name } )
xbmc.Player(xbmc.PLAYER_CORE_AUTO).play(str(url), listitem)
xbmc.sleep(200)
def search():
search = getUserInput("Todic Søgning")
url = __backend__ + "&action=search&search=" + urllib.quote_plus(search)
print "[TODIC] Search start: " + search
print "[TODIC] Search url: " + url
buildSubList(url, "søgning")
#=================================== Tool Box =======================================
# shows a more userfriendly notification
def showMessage(heading, message):
duration = 15*1000
xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' % ( heading, message, duration) )
# raise a keyboard for user input
def getUserInput(title = "Input", default="", hidden=False):
result = None
# Fix for when this functions is called with default=None
if not default:
default = ""
keyboard = xbmc.Keyboard(default, title)
keyboard.setHiddenInput(hidden)
keyboard.doModal()
if keyboard.isConfirmed():
result = keyboard.getText()
return result
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
params = get_params()
url = None
name = None
mode = None
params = get_params()
url = None
name = None
mode = None
try:
url = urllib.unquote_plus(params["url"])
except:
pass
try:
name = urllib.unquote_plus(params["name"])
except:
pass
try:
mode = int(params["mode"])
except:
pass
if mode == None:
#build main menu
rootMenu()
elif mode == 1:
#build list of movie starting letters
buildList(url, name)
elif mode == 2:
#build list of series
buildSubList(url, name)
elif mode == 10:
search()
elif mode == 50:
play_video(url, name)
xbmcplugin.endOfDirectory(int(sys.argv[1]))