--- misc/xbmc/plugin.video.todic/default.py 2016/05/30 20:26:56 3037 +++ misc/xbmc/plugin.video.todic/default.py 2016/11/25 16:17:45 3152 @@ -3,7 +3,7 @@ ''' Todic plugin for XBMC - Version 0.0.15 + Version 0.1.0 ''' import sys @@ -20,6 +20,7 @@ # import pprint from xml.dom.minidom import parseString +from time import time __addon__ = xbmcaddon.Addon(id='plugin.video.todic') __key__ = __addon__.getSetting('xbmckey').lower() @@ -41,49 +42,52 @@ def __init__(self): super(TodicMovieDialog, self).__init__() + self.position = 0 def onClick(self, controlId): - print "OnClick: " + str(controlId) + print "[Todic] MovieDialog OnClick: " + str(controlId) if (controlId == 50): self.close() - play_real_video(self.url, self.name) + 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 "ONINIT" + 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) - 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")) + 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) + + #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 @@ -99,28 +103,43 @@ 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" + 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 callbackLoop(self): - print "[Todic] startLoop" - while (self.stopped == False): - if (self.started == True): - print "[todic] " + str(self.getTime()) - xbmc.sleep(5000) + def getText2(nodelist): @@ -143,12 +162,14 @@ 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) @@ -157,6 +178,16 @@ 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 "[Todic ]Some error during open_url call to ", url + + + def rootMenu(): msg = open_url(__backend__ + "&action=messages") @@ -214,6 +245,7 @@ description = getText(entry.getElementsByTagName("description")) playcount = getText(entry.getElementsByTagName("playcount")) + if playcount == '': playcount = '0' playcount = int(playcount) @@ -245,21 +277,43 @@ def play_video(url, name, description): + param1 = parse_parameter_string(url) + clipkey = param1["clipkey"] + + print "[Todic] ClipKey:" + clipkey + detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey + print "[Todic] detailURL = " + detailurl + + xml = open_url(detailurl) + + clipDetailsDoc = parseString(xml) + savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) ) + playPosition = 0 + if (description == None or description == ""): - play_real_video(url, name) + if (savedPosition > 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.setUrl(url) + d.setDetailsDoc(clipDetailsDoc) d.setName(name) d.setDescription(description) d.doModal() -def play_real_video(url, name): +def play_real_video(url, name, position): xml = open_url(url) - print 'TODIC url: ' + str(url) - print 'TODIC xml: ' + xml + print '[Todic] url: ' + str(url) + print '[Todic] xml: ' + xml + print '[Todic] pos: ' + str(position) doc = parseString(xml) url = getText(doc.getElementsByTagName("url")) @@ -281,6 +335,8 @@ 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) @@ -288,11 +344,13 @@ # kan ikke loade subtitles hvis foerend playeren koerer count = 0 while not xbmc.Player().isPlaying(): - xbmc.sleep(500) + xbmc.sleep(250) count += 1 if count > 10: break + + if xbmc.Player().isPlaying(): if os.path.isfile(subtitlesfile): player.setSubtitles(subtitlesfile) @@ -300,7 +358,20 @@ else: player.disableSubtitles() -# player.callbackLoop() + + if (position > 0): + while (player.getTotalTime() == 0.0): #Vent indtil vi har beregnet hvor langt klippet er + xbmc.sleep(250) + + print "[Todic] totalTime " + str( player.getTotalTime() ) + player.seekTime(position) + + + #Holder python kørernde indtil at det bliver bedt om at stoppe + while (not xbmc.abortRequested): + player.tick() + xbmc.sleep(500) + def search(): @@ -382,6 +453,9 @@ mode = None description = None + +#print params + try: url = urllib.unquote_plus(params["url"]) except: @@ -399,6 +473,9 @@ except: pass + + + try: open_url("http://todic.dk") except: