/[projects]/misc/xbmc/plugin.video.todic/default.py
ViewVC logotype

Diff of /misc/xbmc/plugin.video.todic/default.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3147 by torben, Wed Nov 23 20:10:15 2016 UTC revision 3158 by torben, Thu Dec 1 13:43:40 2016 UTC
# Line 3  Line 3 
3    
4  '''  '''
5      Todic plugin for XBMC      Todic plugin for XBMC
6      Version 0.0.19      Version 0.1.3
7  '''  '''
8    
9  import sys  import sys
# Line 60  class TodicMovieDialog(xbmcgui.WindowXML Line 60  class TodicMovieDialog(xbmcgui.WindowXML
60    
61      def onInit(self):      def onInit(self):
62    
63          print "[Todic] MovieDialog ONINIT"          print "[Todic] MovieDialog onInit"
64          self.getControl(1).setLabel(self.name)          self.getControl(1).setLabel(self.name)
65          self.getControl(2).setLabel(self.moviegroups)          self.getControl(2).setLabel(self.moviegroups)
66          self.getControl(3).setLabel(self.description)          self.getControl(3).setLabel(self.description)
# Line 80  class TodicMovieDialog(xbmcgui.WindowXML Line 80  class TodicMovieDialog(xbmcgui.WindowXML
80          #self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width          #self.starwidth = (float(self.imdbrating) / 10.0) * orig_img_width
81          #self.getControl(40).setWidth(int(self.starwidth))          #self.getControl(40).setWidth(int(self.starwidth))
82    
83        def setDetailsDoc(self, detailsDoc):
84            print "[Todic] MovieDialog setDetailsDoc:"
85            self.imdbrating = getText(detailsDoc.getElementsByTagName("imdbrating"))
86            self.moviegroups = getText(detailsDoc.getElementsByTagName("moviegroups"))
87            self.playlength = getText(detailsDoc.getElementsByTagName("playlength"))
88            self.codecdetails = getText(detailsDoc.getElementsByTagName("codecdetails"))
89            self.position = int( getText(detailsDoc.getElementsByTagName("position")) )
90    
91      def setUrl(self, url):      def setUrl(self, url):
         print "[Todic] MovieDialog SETURL:" + url  
92          self.url = url          self.url = url
         self.fetchClipDetails()  
   
     def setPosition(self, pos):  
         print "[Todic] MovieDialog setPosition:" + str(pos)  
         self.position = pos  
   
   
   
     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"))  
93    
94      def setName(self, name):      def setName(self, name):
95          self.name = name          self.name = name
# Line 124  class TodicPlayer(xbmc.Player): Line 109  class TodicPlayer(xbmc.Player):
109          self.lastReport = 0          self.lastReport = 0
110          print "[TodicPlayer] init"          print "[TodicPlayer] init"
111    
 #       @catchall  
112      def onPlayBackStarted(self):      def onPlayBackStarted(self):
113          self.started = True          self.started = True
114          print "[TodicPlayer] : started"          print "[TodicPlayer] : started"
 #               super.onPlayBackStarted()  
115    
116      #When user presses stop, we report back the the position registered in the last call to self.tick()      #When user presses stop, we report back the the position registered in the last call to self.tick()
117      def onPlayBackStopped(self):      def onPlayBackStopped(self):
118          self.stopped = True          self.stopped = True
119          print "[TodicPlayer] : stopped"          print "[TodicPlayer] : stopped"
120          url = __backend__ + "&action=playbacktime&subaction=stopped&time=" + str( self.playingPosition )          self.reportPlaytime("stopped")
121          open_url_safe(url)  
122        def onPlayBackPaused(self):
123            print "[TodicPlayer] : paused"
124            self.reportPlaytime("paused")
125    
126        def onPlayBackResumed(self):
127            print "[TodicPlayer] : resumed"
128            self.reportPlaytime("resumed")
129    
130    
131      def onPlayBackEnded(self):      def onPlayBackEnded(self):
132          self.stopped = True          self.stopped = True
133          print "[TodicPlayer] : ended"          print "[TodicPlayer] : ended"
134          url = __backend__ + "&action=playbacktime&subaction=ended&time="          self.reportPlaytime("ended")
         open_url_safe(url)  
135    
136      def tick(self):      def tick(self):
137            #print "[Todic] Tick: " + str( self.isPlaying() )
138          if ( self.isPlaying() ):          if ( self.isPlaying() ):
139              self.playingPosition = self.getTime()              self.playingPosition = self.getTime()
140              now = time()              now = time()
141              #print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport)              #print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport)
142              if ( (now - self.lastReport) > 60.0):              if ( (now - self.lastReport) > 60.0):
143                  self.lastReport = now                  self.lastReport = now
144                  self.reportPlaytime()                  self.reportPlaytime("playing")
   
               
145    
146        def reportPlaytime(self, subaction):
147            if (self.playingPosition > 60):
148                url = __backend__ + "&action=playbacktime&subaction=" + subaction + "&time=" + str( self.playingPosition )
149                print "[Todic] reportPlaytime:" + url
150                open_url_safe(url)
151    
     def reportPlaytime(self):  
         url = __backend__ + "&action=playbacktime&subaction=playing&time=" + str( self.playingPosition )  
         open_url_safe(url)  
         print "[Todic] reportPlaytime:" + url  
                   
152    
153    
154  def getText2(nodelist):  def getText2(nodelist):
# Line 205  def open_url_safe(url): Line 193  def open_url_safe(url):
193      try:      try:
194          return open_url(url)          return open_url(url)
195      except:      except:
196          print "[Todic ]Some error during open_url call to ", url          print "[Todic] Some error during open_url call to ", url
197    
198    
199    
# Line 222  def rootMenu(): Line 210  def rootMenu():
210    
211      # Adde xtra items to root menu      # Adde xtra items to root menu
212      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(
213          label="Søg film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')          label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')
214      listitem.setProperty('Fanart_Image', fanartImage)      listitem.setProperty('Fanart_Image', fanartImage)
215    
216      u = sys.argv[0] + "?mode=10&name="      u = sys.argv[0] + "?mode=10&name="
# Line 242  def rootMenu(): Line 230  def rootMenu():
230    
231    
232  def buildList(url, title, endlist=True):  def buildList(url, title, endlist=True):
233      print '[TODIC]:' + str(url)      print '[Todic]:' + str(url)
234    
235      link = open_url(url)      link = open_url(url)
236      doc = parseString(link)      doc = parseString(link)
237      ty = doc.getElementsByTagName("meta")[0].getAttribute("type")      ty = doc.getElementsByTagName("meta")[0].getAttribute("type")
238      print '[TODIC]' + str(ty)      print '[Todic]' + str(ty)
239    
240      if ty == 'clipList':      if ty == 'clipList':
241          mode = '50'          mode = '50'
# Line 266  def buildList(url, title, endlist=True): Line 254  def buildList(url, title, endlist=True):
254          description = getText(entry.getElementsByTagName("description"))          description = getText(entry.getElementsByTagName("description"))
255          playcount = getText(entry.getElementsByTagName("playcount"))          playcount = getText(entry.getElementsByTagName("playcount"))
256    
257    
258          if playcount == '':          if playcount == '':
259              playcount = '0'              playcount = '0'
260          playcount = int(playcount)          playcount = int(playcount)
# Line 297  def buildList(url, title, endlist=True): Line 286  def buildList(url, title, endlist=True):
286    
287    
288  def play_video(url, name, description):  def play_video(url, name, description):
289        playPosition = 0
290        savedPosition = 0
291        try:
292            param1 = parse_parameter_string(url)
293            clipkey = param1["clipkey"]
294    
295            print "[Todic] ClipKey:" + clipkey
296            detailurl = __backend__ + "&action=clipdetails&clipkey=" + clipkey
297            print "[Todic] detailURL = " + detailurl
298    
299            xml = open_url(detailurl)
300    
301            clipDetailsDoc = parseString(xml)
302            savedPosition = int( getText(clipDetailsDoc.getElementsByTagName("position")) )
303        except:
304            print "[Todic] Unexpected error:", sys.exc_info()[0]
305    
306      if (description == None or description == ""):      if (description == None or description == ""):
307          play_real_video(url, name, 0)          if (savedPosition > 0):
308                dialog = xbmcgui.Dialog()
309                #yes / true -afspil fra position
310                answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt')
311                if (answer == True):
312                    playPosition = savedPosition
313            
314            play_real_video(url, name, playPosition)
315    
316      else:      else:
317          d = TodicMovieDialog()          d = TodicMovieDialog()
318          d.setUrl(url)          d.setDetailsDoc(clipDetailsDoc)
319          d.setName(name)          d.setName(name)
320            d.setUrl(url)
321          d.setDescription(description)          d.setDescription(description)
         d.setPosition(pos) #tager pos fra global scope  
322    
323          d.doModal()          d.doModal()
324    
# Line 325  def play_real_video(url, name, position) Line 339  def play_real_video(url, name, position)
339      if os.path.isfile(subtitlesfile):      if os.path.isfile(subtitlesfile):
340          os.unlink(subtitlesfile)          os.unlink(subtitlesfile)
341    
342      print '[TODIC] subs: ' + str(subtitleurl)      print '[Todic] subs: ' + str(subtitleurl)
343      if len(subtitleurl) > 0:      if len(subtitleurl) > 0:
344          subtitles = open_url(subtitleurl)          subtitles = open_url(subtitleurl)
345          SaveFile(subtitlesfile, subtitles)          SaveFile(subtitlesfile, subtitles)
346          print 'TODIC downloaded subtitles'          print '[Todic] downloaded subtitles'
347    
348      image = xbmc.getInfoImage('ListItem.Thumb')      image = xbmc.getInfoImage('ListItem.Thumb')
349      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(
# Line 354  def play_real_video(url, name, position) Line 368  def play_real_video(url, name, position)
368      if xbmc.Player().isPlaying():      if xbmc.Player().isPlaying():
369          if os.path.isfile(subtitlesfile):          if os.path.isfile(subtitlesfile):
370              player.setSubtitles(subtitlesfile)              player.setSubtitles(subtitlesfile)
371              print 'TODIC started subtitles'              print '[Todic] started subtitles'
372          else:          else:
373              player.disableSubtitles()              player.disableSubtitles()
374    
# Line 381  def search(): Line 395  def search():
395          url = __backend__ + "&action=search&search=" + \          url = __backend__ + "&action=search&search=" + \
396              urllib.quote_plus(search)              urllib.quote_plus(search)
397    
398          # print "[TODIC] Search start: " + search          # print "[Todic] Search start: " + search
399          # print "[TODIC] Search url: " + url          # print "[Todic] Search url: " + url
400    
401          buildList(url, "søgning")          buildList(url, "søgning")
402    
# Line 394  def searchSeries(): Line 408  def searchSeries():
408          url = __backend__ + "&action=searchseries&search=" + \          url = __backend__ + "&action=searchseries&search=" + \
409              urllib.quote_plus(search)              urllib.quote_plus(search)
410    
411          # print "[TODIC] Search start: " + search          # print "[Todic] Search start: " + search
412          # print "[TODIC] Search url: " + url          # print "[Todic] Search url: " + url
413    
414          buildList(url, "serie søgning")          buildList(url, "serie søgning")
415    
# Line 452  url = None Line 466  url = None
466  name = None  name = None
467  mode = None  mode = None
468  description = None  description = None
469  pos = 0  
470    
471    #print params
472    
473  try:  try:
474      url = urllib.unquote_plus(params["url"])      url = urllib.unquote_plus(params["url"])
# Line 471  try: Line 487  try:
487  except:  except:
488      pass      pass
489    
490  try:  
     pos = int(params["pos"])  
 except:  
     pass  
491    
492    
493  try:  try:

Legend:
Removed from v.3147  
changed lines
  Added in v.3158

  ViewVC Help
Powered by ViewVC 1.1.20