--- misc/xbmc/plugin.video.todic/default.py 2011/12/04 15:06:39 1649 +++ misc/xbmc/plugin.video.todic/default.py 2015/06/30 13:03:55 2595 @@ -1,6 +1,9 @@ + +# This Python file uses the following encoding: utf-8 + ''' Todic plugin for XBMC - Version 0.0.2 + Version 0.0.14 ''' import sys @@ -13,12 +16,134 @@ import xbmcgui import xbmcplugin import urllib -import urllib2, re +import urllib2 + +#import pprint + +from xml.dom.minidom import parseString __addon__ = xbmcaddon.Addon(id='plugin.video.todic') __key__ = __addon__.getSetting('xbmckey').lower() __backend__ = "http://todic.dk/xbmc.php?xbmckey=" + __key__ -fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') +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 ); + + 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 + print "[TodicPlayer] init" + +# @catchall + def onPlayBackStarted(self): + self.started = True + print "[TodicPlayer] : started" +# super.onPlayBackStarted() + + def onPlayBackStopped(self): + self.stopped = True + print "[TodicPlayer] : stopped" + + def onPlayBackEnded(self): + self.stopped = True + print "[TodicPlayer] : ended" + + def callbackLoop(self): + print "[Todic] startLoop" + while (self.stopped == False): + if (self.started == True ): + print "[todic] " + str(self.getTime()) + xbmc.sleep(5000) + + +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) @@ -29,7 +154,14 @@ def rootMenu(): - buildList(__backend__, "") # call default list + msg = open_url(__backend__ + "&action=messages") + msg = msg.strip() + + if msg != "": + dialog = xbmcgui.Dialog() + dialog.ok('XBMC Todic', msg) + + buildList(__backend__, "", False) # call default list # Adde xtra items to root menu listitem = xbmcgui.ListItem(label = "Søg film ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') @@ -38,51 +170,136 @@ u = sys.argv[0] + "?mode=10&name=" ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) + #add search series + listitem = xbmcgui.ListItem(label = "Søg Serier ...", iconImage = 'DefaultFolder.png', thumbnailImage = 'DefaultFolder.png') + listitem.setProperty('Fanart_Image', fanartImage) + + u = sys.argv[0] + "?mode=11&name=" + ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) + xbmcplugin.endOfDirectory(int(sys.argv[1])) -def buildList(url,title): - print '[TODIC]:'+str(url) +def buildList(url,title, endlist=True): + print '[TODIC]:'+str(url) + link = open_url(url) - ty=re.compile('(.+?)(.+?)(.+?)(.*)').findall(link) - l=len(m) - for name,url,thumb,description in m: - infoLabels = {} - infoLabels['title'] = name - infoLabels['plot'] = description + + entries = doc.getElementsByTagName("entry") + l=len(entries) + description = '' + for entry in entries: + name = getText( entry.getElementsByTagName("title") ) + url = getText( entry.getElementsByTagName("url") ) + thumb = getText( entry.getElementsByTagName("cover") ) + description = getText( entry.getElementsByTagName("description") ) + playcount = getText( entry.getElementsByTagName("playcount") ) + + if playcount == '': + playcount = '0' + playcount = int(playcount) + + +## print "name:" + name +# print "url:" + url +# print "thumb:" + thumb +# print "description:" + description + listitem = xbmcgui.ListItem(label = name, label2='test', iconImage = 'DefaultFolder.png', thumbnailImage = thumb) - listitem.setInfo('video', infoLabels) listitem.setProperty('Fanart_Image', fanartImage) + if mode == '50': + infoLabels = {} + infoLabels['title'] = name + infoLabels['plot'] = description + infoLabels['playcount'] = playcount + listitem.setInfo('video', infoLabels) + + name = name.encode('UTF-8') + description = description.encode('UTF-8') - u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) + + u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(name) + "&url=" + urllib.quote(url) + "&description=" + urllib.quote(description) ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = folder, totalItems = l) - xbmcplugin.endOfDirectory(int(sys.argv[1])) + if (endlist == True): + xbmcplugin.endOfDirectory(int(sys.argv[1])) + + + + +def play_video(url, name,description): + if (description == None or description == ""): + play_real_video(url,name) + else: + d = TodicMovieDialog() + d.setUrl( url) + d.setName( name ) + d.setDescription( description ) + + d.doModal() + + +def play_real_video(url, name): + xml = open_url(url) + print 'TODIC url: ' + str(url) + print 'TODIC xml: '+ xml + + doc = parseString(xml) + url = getText( doc.getElementsByTagName("url") ) + + subtitleurl = getText( doc.getElementsByTagName("subtitles") ) + subtitlesfile = os.path.join(datapath,'temp.srt') + + #if old srt file exists delete it first + if os.path.isfile(subtitlesfile): + os.unlink(subtitlesfile) + + print '[TODIC] subs: '+str(subtitleurl) + if len(subtitleurl) > 0: + subtitles = open_url(subtitleurl) + SaveFile(subtitlesfile, subtitles) + print 'TODIC downloaded subtitles' -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) + + 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: + player.disableSubtitles() + +# player.callbackLoop() + + def search(): search = getUserInput("Todic Søgning") @@ -95,6 +312,17 @@ buildList(url, "søgning") +def searchSeries(): + search = getUserInput("Todic Serie Søgning") + + 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") + @@ -125,10 +353,12 @@ def get_params(): + return parse_parameter_string( sys.argv[2] ) + +def parse_parameter_string( paramstring ): param=[] - paramstring=sys.argv[2] if len(paramstring)>=2: - params=sys.argv[2] + params = paramstring cleanedparams=params.replace('?','') if (params[len(params)-1]=='/'): params=params[0:len(params)-2] @@ -141,15 +371,12 @@ 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"]) @@ -163,9 +390,24 @@ mode = int(params["mode"]) except: 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 url == 'refresh': + #xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 + xbmc.executebuiltin("Container.Refresh") + -if mode == None: +elif mode == None: #build main menu rootMenu() @@ -175,12 +417,14 @@ elif mode == 10: search() + +elif mode == 11: + searchSeries() elif mode == 50: - play_video(url, name) + play_video(url, name, description) -# xbmcplugin.endOfDirectory(int(sys.argv[1]))