--- misc/xbmc/plugin.video.todic/default.py 2011/12/12 17:50:21 1659 +++ misc/xbmc/plugin.video.todic/default.py 2016/11/25 16:17:45 3152 @@ -1,10 +1,12 @@ + +# This Python file uses the following encoding: utf-8 + ''' Todic plugin for XBMC - Version 0.0.2 + Version 0.1.0 ''' import sys -import cgi as urlparse import os @@ -13,177 +15,494 @@ 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__ -fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'fanart.jpg') +__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__() + self.position = 0 + + def onClick(self, controlId): + print "[Todic] MovieDialog OnClick: " + str(controlId) + + if (controlId == 50): + self.close() + play_real_video(self.url, self.name, 0) + + if (controlId == 51): + self.close() + play_real_video(self.url, self.name, self.position) + + if (controlId == 98): + self.close() + + def onInit(self): + + print "[Todic] MovieDialog 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) + + if (self.position > 0): + self.getControl(51).setVisible(True) + self.getControl(50).setPosition(100, 570) + self.getControl(51).setPosition(450, 570) + self.getControl(50).controlLeft( self.getControl(51) ) + self.getControl(50).controlRight( self.getControl(51) ) + else: + self.getControl(51).setVisible(False) -def open_url(url): - req = urllib2.Request(url) - content = urllib2.urlopen(req) - data = content.read() - content.close() - return data + #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 setDetailsDoc(self, detailsDoc): + print "[Todic] MovieDialog setDetailsDoc:" + self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating")) + self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups")) + self.playlength = getText(detailsDoc.getElementsByTagName("playlength")) + self.codecdetails = getText(detailsDoc.getElementsByTagName("codecdetails")) + self.position = int( getText(detailsDoc.getElementsByTagName("position")) ) + + + 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" + + def onPlayBackStarted(self): + self.started = True + print "[TodicPlayer] : started" + + #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" + self.reportPlaytime("stopped") + + + + def onPlayBackEnded(self): + self.stopped = True + print "[TodicPlayer] : ended" + self.reportPlaytime("ended") + + 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.lastReport = now + self.reportPlaytime("playing") + + def reportPlaytime(self, subaction): + if (self.playingPosition > 60): + url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition ) + print "[Todic] reportPlaytime:" + url + open_url_safe(url) -def rootMenu(): + - 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') - listitem.setProperty('Fanart_Image', fanartImage) +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 - u = sys.argv[0] + "?mode=10&name=" - ok = xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = listitem, isFolder = True) - xbmcplugin.endOfDirectory(int(sys.argv[1])) +def SaveFile(path, data): + file = open(path, 'w') + file.write(data) + file.close() -def buildList(url,title, endlist=True): - print '[TODIC]:'+str(url) - link = open_url(url) - ty=re.compile(' 0): + dialog = xbmcgui.Dialog() + #yes / true -afspil fra position + answer = dialog.yesno(heading='Todic', line1='Afspil fra gemt', nolabel='Fra start', yeslabel='Fortsæt') + if (answer == True): + playPosition = savedPosition + + play_real_video(url, name, playPosition) + + else: + d = TodicMovieDialog() + d.setDetailsDoc(clipDetailsDoc) + d.setName(name) + d.setDescription(description) + + d.doModal() + + +def play_real_video(url, name, position): + xml = open_url(url) + print '[Todic] url: ' + str(url) + print '[Todic] xml: ' + xml + print '[Todic] pos: ' + str(position) + + 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.setInfo(type="Video", infoLabels={"Title": name}) + listitem.setProperty('ResumeTime', '300') + listitem.setProperty('TotalTime', '3000') + + 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(250) + 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('