--- misc/xbmc/plugin.video.todic/default.py 2012/01/23 15:50:40 1677 +++ misc/xbmc/plugin.video.todic/default.py 2015/06/29 11:34:00 2592 @@ -1,9 +1,9 @@ -# This Python file uses the following encoding: utf-8 +# This Python file uses the following encoding: utf-8 ''' Todic plugin for XBMC - Version 0.0.2 + Version 0.0.13 ''' import sys @@ -16,12 +16,54 @@ import xbmcgui import xbmcplugin import urllib -import urllib2, re +import urllib2 + +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') +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.description ); + + def setUrl( self, url): + self.url = url + + def setName( self, name ): + self.name = name + + def setDescription( self, description ): + self.description = description class TodicPlayer(xbmc.Player): @@ -54,6 +96,28 @@ 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): @@ -65,6 +129,13 @@ def rootMenu(): + 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 @@ -74,35 +145,67 @@ 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, endlist=True): - print '[TODIC]:'+str(url) + print '[TODIC]:'+str(url) + link = open_url(url) - ty=re.compile('(.+?)(.+?)(.+?)(.*)').findall(link) - l=len(m) - for name,url,thumb,description in m: + + 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.setProperty('Fanart_Image', fanartImage) if mode == '50': infoLabels = {} infoLabels['title'] = name - infoLabels['plot'] = description + infoLabels['plot'] = description + infoLabels['playcount'] = playcount listitem.setInfo('video', infoLabels) - u = sys.argv[0] + "?mode=" + urllib.quote_plus(mode) + "&name=" + urllib.quote_plus(name) + "&url=" + urllib.quote_plus(url) + name = name.encode('UTF-8') + description = description.encode('UTF-8') + + + 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) if (endlist == True): @@ -111,20 +214,65 @@ -def play_video(url, name): - link = open_url(url) - match=re.compile('(.+?)').findall(link) - url = match[0] - print '[TODIC]:'+str(url) +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' + + + 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) player = TodicPlayer(xbmc.PLAYER_CORE_AUTO) player.play(str(url), listitem) - player.callbackLoop() + + #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() @@ -139,6 +287,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") + @@ -185,15 +344,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"]) @@ -207,9 +363,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 mode == None: +if url == 'refresh': + #xbmc.output("[tvserver] Container.Refresh") #20130418 xbmc.output virker ikke med XBMC12 + xbmc.executebuiltin("Container.Refresh") + + +elif mode == None: #build main menu rootMenu() @@ -219,12 +390,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]))