--- misc/xbmc/plugin.video.todic/default.py 2011/12/03 13:53:47 1647 +++ misc/xbmc/plugin.video.todic/default.py 2016/11/23 08:09:53 3144 @@ -1,183 +1,469 @@ + +# This Python file uses the following encoding: utf-8 + ''' Todic plugin for XBMC - Version 0.0.2 + Version 0.0.17 ''' import sys -import cgi as urlparse +import os + import xbmc import xbmcaddon import xbmcgui import xbmcplugin import urllib -import urllib2, re +import urllib2 + +# import pprint + +from xml.dom.minidom import parseString +from time import time __addon__ = xbmcaddon.Addon(id='plugin.video.todic') __key__ = __addon__.getSetting('xbmckey').lower() -__backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ +__backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__ +fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg') +datapath = xbmc.translatePath( + 'special://profile/addon_data/plugin.video.todic/') + +ADDON_PATH = __addon__.getAddonInfo('path') +SkinMasterPath = os.path.join(ADDON_PATH, 'skins') + '/' +MySkinPath = (os.path.join(SkinMasterPath, '720p')) + '/' +MySkin = 'main.xml' + + +class TodicMovieDialog(xbmcgui.WindowXMLDialog): + + def __new__(cls): + return super(TodicMovieDialog, cls).__new__(cls, "main.xml", ADDON_PATH) + + def __init__(self): + super(TodicMovieDialog, self).__init__() + + def onClick(self, controlId): + print "OnClick: " + str(controlId) + + if (controlId == 50): + self.close() + play_real_video(self.url, self.name) + + if (controlId == 98): + self.close() + + def onInit(self): + + print "ONINIT" + self.getControl(1).setLabel(self.name) + self.getControl(2).setLabel(self.moviegroups) + self.getControl(3).setLabel(self.description) + self.getControl(10).setLabel(self.playlength) + self.getControl(11).setLabel(self.codecdetails) + + orig_img_width = self.getControl(40).getWidth() + self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width + self.getControl(40).setWidth(int(self.starwidth)) + + def setUrl(self, url): + print "SETURL:" + url + self.url = url + self.fetchClipDetails() + + def fetchClipDetails(self): + param1 = parse_parameter_string(self.url) + + self.clipkey = param1["clipkey"] + print "CLIPKEY:" + self.clipkey + detailurl = __backend__ + "&action=clipdetails&clipkey=" + self.clipkey + + xml = open_url(detailurl) + + doc = parseString(xml) + self.imdbrating = getText(doc.getElementsByTagName("imdbrating")) + self.moviegroups = getText(doc.getElementsByTagName("moviegroups")) + self.playlength = getText(doc.getElementsByTagName("playlength")) + self.codecdetails = getText(doc.getElementsByTagName("codecdetails")) + + def setName(self, name): + self.name = name + + def setDescription(self, description): + self.description = description + + +class TodicPlayer(xbmc.Player): + + def __init__(self, *args, **kwargs): + # xbmc.Player.__init__(selv,*args,**kwargs) + xbmc.Player.__init__(self, xbmc.PLAYER_CORE_MPLAYER) + self.stopped = False + self.started = False + self.playingPosition = 0.0 + self.lastReport = 0 + print "[TodicPlayer] init" + +# @catchall + def onPlayBackStarted(self): + self.started = True + print "[TodicPlayer] : started" +# super.onPlayBackStarted() + + #When user presses stop, we report back the the position registered in the last call to self.tick() + def onPlayBackStopped(self): + self.stopped = True + print "[TodicPlayer] : stopped" + url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition ) + open_url_safe(url) + + + def onPlayBackEnded(self): + self.stopped = True + print "[TodicPlayer] : ended" + url = __backend__ + "&action=playbacktime&subaction=ended&time=" + open_url_safe(url) + + def tick(self): + if ( self.isPlaying() ): + self.playingPosition = self.getTime() + now = time() + #print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) + if ( (now - self.lastReport) > 60.0): + self.reportPlaytime() + self.lastReport = now + + + + def reportPlaytime(self): + url = __backend__ + "&action=playbacktime&subaction=playing&time=" + str( self.playingPosition ) + open_url_safe(url) + print "[Todic] reportPlaytime:" + url + + + +def getText2(nodelist): + rc = [] + for node in nodelist: + if node.nodeType == node.TEXT_NODE: + rc.append(node.data) + else: + rc.append(getText(node.childNodes)) + return ''.join(rc) + + +def getText(nodelist): + if nodelist.length == 0: + return '' + else: + if nodelist[0].childNodes.length == 0: + return '' + else: + return nodelist[0].childNodes[0].nodeValue + + + +def SaveFile(path, data): + file = open(path, 'w') + file.write(data) + file.close() + + def open_url(url): - req = urllib2.Request(url) - content = urllib2.urlopen(req) - data = content.read() - content.close() - return data + req = urllib2.Request(url) + content = urllib2.urlopen(req) + data = content.read() + content.close() + return data + + +# wraps open url in a catch-all exception handler +# usefull for periodic back-reporting that should not interrupt the program flow +def open_url_safe(url): + try: + return open_url(url) + except: + print "Some error during open_url call to ", url + + 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 film ...", 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(' 0: + subtitles = open_url(subtitleurl) + SaveFile(subtitlesfile, subtitles) + print 'TODIC downloaded subtitles' + + image = xbmc.getInfoImage('ListItem.Thumb') + listitem = xbmcgui.ListItem( + label=name, iconImage='DefaultVideo.png', thumbnailImage=image) + listitem.setInfo(type="Video", infoLabels={"Title": name}) + + player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) + player.play(str(url), listitem) + + # kan ikke loade subtitles hvis foerend playeren koerer + count = 0 + while not xbmc.Player().isPlaying(): + xbmc.sleep(500) + count += 1 + if count > 10: + break + + if xbmc.Player().isPlaying(): + if os.path.isfile(subtitlesfile): + player.setSubtitles(subtitlesfile) + print 'TODIC started subtitles' else: - mode = '1' - folder = True + player.disableSubtitles() - m=re.compile('(.+?)(.+?)(.+?)(.*)').findall(link) - l=len(m) - for name,url,thumb,description in m: - infoLabels = {} - infoLabels['title'] = name - infoLabels['plot'] = description - - listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) - listitem.setInfo('video', infoLabels) - 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])) + #Holder python kørernde indtil at det bliver bedt om at stoppe + while (not xbmc.abortRequested): + player.tick() + xbmc.sleep(100) +# player.callbackLoop() -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") + search = getUserInput("Todic Søgning") - if (search != None and search != ""): - url = __backend__ + "&action=search&search=" + urllib.quote_plus(search) + if (search != None and search != ""): + url = __backend__ + "&action=search&search=" + \ + urllib.quote_plus(search) - #print "[TODIC] Search start: " + search - #print "[TODIC] Search url: " + url + # print "[TODIC] Search start: " + search + # print "[TODIC] Search url: " + url - buildList(url, "søgning") + buildList(url, "søgning") - +def searchSeries(): + search = getUserInput("Todic Serie Søgning") - -#=================================== Tool Box ======================================= + if (search != None and search != ""): + url = __backend__ + "&action=searchseries&search=" + \ + urllib.quote_plus(search) + + # print "[TODIC] Search start: " + search + # print "[TODIC] Search url: " + url + + buildList(url, "serie 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) ) + 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 +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 + # 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 + return parse_parameter_string(sys.argv[2]) + + +def parse_parameter_string(paramstring): + param = [] + if len(paramstring) >= 2: + params = paramstring + 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 +description = None try: - url = urllib.unquote_plus(params["url"]) + url = urllib.unquote_plus(params["url"]) except: - pass + pass try: - name = urllib.unquote_plus(params["name"]) + name = urllib.unquote_plus(params["name"]) except: - pass + pass try: - mode = int(params["mode"]) + mode = int(params["mode"]) except: - pass + pass +try: + description = urllib.unquote_plus(params["description"]) +except: + pass +try: + open_url("http://todic.dk") +except: + showMessage("Fejl", "Kunne ikke forbinde til todic.dk") + exit() -if mode == None: - #build main menu - rootMenu() - -elif mode == 1: - #build list of movie starting letters - buildList(url, name) -elif mode == 10: - search() - +if url == 'refresh': + # xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker + # ikke med XBMC12 + xbmc.executebuiltin("Container.Refresh") -elif mode == 50: - play_video(url, name) +elif mode == None: + # build main menu + rootMenu() + +elif mode == 1: + # build list of movie starting letters + buildList(url, name) + +elif mode == 10: + search() +elif mode == 11: + searchSeries() -# xbmcplugin.endOfDirectory(int(sys.argv[1])) +elif mode == 50: + play_video(url, name, description)