/[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 3251 by torben, Thu Feb 28 11:10:40 2019 UTC revision 3263 by torben, Tue Feb 23 19:19:52 2021 UTC
# Line 3  Line 3 
3    
4  '''  '''
5      Todic plugin for XBMC      Todic plugin for XBMC
6      Version 1.7.3      Version 1.9.2
7  '''  '''
8    
9  import sys  import sys
# Line 13  import os Line 13  import os
13  import xbmc  import xbmc
14  import xbmcaddon  import xbmcaddon
15  import xbmcgui  import xbmcgui
16    import xbmcvfs
17  import xbmcplugin  import xbmcplugin
18  import urllib  import urllib
19  import urllib2  import urllib.request
20    
21  # import pprint  # import pprint
22    
# Line 27  __key__ = __addon__.getSetting('xbmckey' Line 28  __key__ = __addon__.getSetting('xbmckey'
28  __entrypoint__ = __addon__.getSetting('entrypoint').lower()  __entrypoint__ = __addon__.getSetting('entrypoint').lower()
29  __backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__  __backend__ = "https://todic.dk/xbmc.php?xbmckey=" + __key__
30    
31    
32  if __entrypoint__ == "alternative":  if __entrypoint__ == "alternative":
33      __backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__      __backend__ = "https://alt.todic.dk/xbmc.php?xbmckey=" + __key__
34    
# Line 35  if __entrypoint__ == "testing": Line 37  if __entrypoint__ == "testing":
37    
38  print( "[Todic] entrypoint: " + __entrypoint__ )  print( "[Todic] entrypoint: " + __entrypoint__ )
39  print( "[Todic] backend: " + __backend__ )  print( "[Todic] backend: " + __backend__ )
40    print( "[Todic] version: " + __addon__.getAddonInfo('version') )
41    
42  fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg')  fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg')
43  datapath = xbmc.translatePath(  datapath = xbmcvfs.translatePath(
44      'special://profile/addon_data/plugin.video.todic/')      'special://profile/addon_data/plugin.video.todic/')
45    
46  ADDON_PATH = __addon__.getAddonInfo('path')  ADDON_PATH = __addon__.getAddonInfo('path')
# Line 146  class TodicPlayer(xbmc.Player): Line 148  class TodicPlayer(xbmc.Player):
148          self.reportPlaytime("ended")          self.reportPlaytime("ended")
149    
150      def tick(self):      def tick(self):
151          #print "[Todic] Tick: " + str( self.isPlaying() )          #print( "[Todic] Tick: " + str( self.isPlaying() ) )
152          if ( self.isPlaying() ):          if ( self.isPlaying() ):
153              tmpTime = self.getTime()              tmpTime = self.getTime()
154    
# Line 154  class TodicPlayer(xbmc.Player): Line 156  class TodicPlayer(xbmc.Player):
156              if tmpTime != self.playingPosition:              if tmpTime != self.playingPosition:
157                  self.playingPosition = tmpTime                  self.playingPosition = tmpTime
158                  now = time()                  now = time()
159                  #print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport)                  #print( "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) )
160                  if ( (now - self.lastReport) > 60.0):                  if ( (now - self.lastReport) > 60.0):
161                      self.lastReport = now                      self.lastReport = now
162                      self.reportPlaytime("playing")                      self.reportPlaytime("playing")
# Line 196  def SaveFile(path, data): Line 198  def SaveFile(path, data):
198    
199    
200  def open_url(url):  def open_url(url):
201      req = urllib2.Request(url)      with urllib.request.urlopen(url) as req:
202      content = urllib2.urlopen(req)          #data = response.read()
203      data = content.read()          #return data
204      content.close()          charset=req.info().get_content_charset()
205      return data          content=req.read().decode(charset)
206            return content
207    
208    
209  # wraps open url in a catch-all exception handler  # wraps open url in a catch-all exception handler
# Line 214  def open_url_safe(url): Line 217  def open_url_safe(url):
217    
218    
219  def rootMenu():  def rootMenu():
220        kodi_ver = xbmc.getInfoLabel('System.BuildVersion')
221        plugin_ver = __addon__.getAddonInfo('version')
222        msgurl = __backend__ + "&action=messages&kodi=" + urllib.parse.quote(kodi_ver) + "&todicplugin=" + urllib.parse.quote(plugin_ver)
223    
224      msg = open_url(__backend__ + "&action=messages")      msg = open_url(msgurl)
225      msg = msg.strip()      msg = msg.strip()
226    
227      if msg != "":      if msg != "":
228            print("[Todic] rootMenu Dialog =" + str(msg))
229          dialog = xbmcgui.Dialog()          dialog = xbmcgui.Dialog()
230          dialog.ok('XBMC Todic', msg)          dialog.ok('XBMC Todic', msg)
231    
232      buildList(__backend__, "", False)  # call default list      buildList(__backend__, "", False)  # call default list
233    
234      # Adde xtra items to root menu      # Adde xtra items to root menu
235      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(label="Søg Film ...")
236          label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')      listitem.setArt( { 'icon':'DefaultFolder.png', 'thumb':'DefaultFolder.png'} )
237      listitem.setProperty('Fanart_Image', fanartImage)      listitem.setProperty('Fanart_Image', fanartImage)
238    
239      u = sys.argv[0] + "?mode=10&name="      u = sys.argv[0] + "?mode=10&name="
# Line 234  def rootMenu(): Line 241  def rootMenu():
241          handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True)          handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True)
242    
243      # add search series      # add search series
244      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(label="Søg Serier ...")
245          label="Søg Serier ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')      listitem.setArt( { 'icon':'DefaultFolder.png', 'thumb':'DefaultFolder.png'} )
246      listitem.setProperty('Fanart_Image', fanartImage)      listitem.setProperty('Fanart_Image', fanartImage)
247    
248      u = sys.argv[0] + "?mode=11&name="      u = sys.argv[0] + "?mode=11&name="
# Line 246  def rootMenu(): Line 253  def rootMenu():
253    
254    
255  def buildList(url, title, endlist=True):  def buildList(url, title, endlist=True):
256      print( '[Todic]:' + str(url) )      print( '[Todic::buildList]:' + str(url) )
257    
258      link = open_url(url)      link = open_url(url)
259      doc = parseString(link)      doc = parseString(link)
# Line 276  def buildList(url, title, endlist=True): Line 283  def buildList(url, title, endlist=True):
283    
284  # print "name:" + name  # print "name:" + name
285  #               print "url:" + url  #               print "url:" + url
286  #               print "thumb:" + thumb  #               print "thumb:" + thumbi
287          listitem = xbmcgui.ListItem(          listitem = xbmcgui.ListItem(label=name, label2='test')
288              label=name, label2='test', iconImage='DefaultFolder.png', thumbnailImage=thumb)          listitem.setArt( {'icon': 'DefaultFolder.png'} )
289          listitem.setProperty('Fanart_Image', fanartImage)          listitem.setProperty('Fanart_Image', fanartImage)
290          listitem.addContextMenuItems([('Refresh', 'Container.Refresh')])          listitem.addContextMenuItems([('Refresh', 'Container.Refresh')])
291            listitem.setArt( {'thumb': thumb} )
292    
293          if mode == '50':          if mode == '50':
294              infoLabels = {}              infoLabels = {}
295              infoLabels['title'] = name              infoLabels['title'] = name
296              infoLabels['playcount'] = playcount              infoLabels['playcount'] = playcount
297    #            if playcount > 0:
298    #                listitem.setArt( {'thumb': thumb} ) #not pretty - but at least we can show a different icon for unwatched/watched in kodi18  
299              listitem.setInfo('video', infoLabels)              listitem.setInfo('video', infoLabels)
300    
301          name = name.encode('UTF-8')          name = name.encode('UTF-8')
302    
303          u = sys.argv[0] + "?mode=" + urllib.quote(mode) + "&name=" + urllib.quote(          u = sys.argv[0] + "?mode=" + urllib.parse.quote(mode) + "&name=" + urllib.parse.quote(name) + "&url=" + urllib.parse.quote(url)
             name) + "&url=" + urllib.quote(url)  
304          xbmcplugin.addDirectoryItem(          xbmcplugin.addDirectoryItem(
305              handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l)              handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=folder, totalItems=l)
306    
# Line 342  def play_video(url, name): Line 351  def play_video(url, name):
351  def play_real_video(url, name, position):  def play_real_video(url, name, position):
352      xml = open_url(url)      xml = open_url(url)
353      print( '[Todic] url: ' + str(url) )      print( '[Todic] url: ' + str(url) )
354      print( '[Todic] xml: ' + xml )      print( '[Todic] xml: ' + str(xml) )
355      print( '[Todic] pos: ' + str(position) )      print( '[Todic] pos: ' + str(position) )
356    
357      doc = parseString(xml)      doc = parseString(xml)
# Line 354  def play_real_video(url, name, position) Line 363  def play_real_video(url, name, position)
363      print( '[Todic] subs: ' + str(subtitleurl) )      print( '[Todic] subs: ' + str(subtitleurl) )
364    
365      image = xbmc.getInfoImage('ListItem.Thumb')      image = xbmc.getInfoImage('ListItem.Thumb')
366      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(label=name)
367          label=name, iconImage='DefaultVideo.png', thumbnailImage=image)      listitem.setArt( {'icon': 'DefaultVideo.png', 'thumb':image} )
368      listitem.setInfo(type="Video", infoLabels={"Title": name})      listitem.setInfo(type="Video", infoLabels={"Title": name})
369    
370      listitem.setProperty('StartOffset', str(position) )      listitem.setProperty('StartOffset', str(position) )
# Line 366  def play_real_video(url, name, position) Line 375  def play_real_video(url, name, position)
375      player = TodicPlayer()      player = TodicPlayer()
376      player.play(str(url), listitem)      player.play(str(url), listitem)
377    
     # kan ikke loade subtitles hvis foerend playeren koerer  
     count = 0  
     while not xbmc.Player().isPlaying():  
         xbmc.sleep(250)  
         count += 1  
         if count > 10:  
             break  
   
   
378    
379      #Holder python kørernde indtil at det bliver bedt om at stoppe      #Holder python kørernde indtil at det bliver bedt om at stoppe
380      while (not xbmc.abortRequested):      kodiMonitor = xbmc.Monitor()
381        
382        
383        while (not kodiMonitor.abortRequested()):
384          player.tick()          player.tick()
385          xbmc.sleep(500)          kodiMonitor.waitForAbort( 1 )
386    
387    
388    
# Line 388  def search(): Line 391  def search():
391    
392      if (search != None and search != ""):      if (search != None and search != ""):
393          url = __backend__ + "&action=search&search=" + \          url = __backend__ + "&action=search&search=" + \
394              urllib.quote_plus(search)              urllib.parse.quote(search)
395    
396          # print "[Todic] Search start: " + search          # print "[Todic] Search start: " + search
397          # print "[Todic] Search url: " + url          # print "[Todic] Search url: " + url
# Line 401  def searchSeries(): Line 404  def searchSeries():
404    
405      if (search != None and search != ""):      if (search != None and search != ""):
406          url = __backend__ + "&action=searchseries&search=" + \          url = __backend__ + "&action=searchseries&search=" + \
407              urllib.quote_plus(search)              urllib.parse.quote(search)
408    
409          # print "[Todic] Search start: " + search          # print "[Todic] Search start: " + search
410          # print "[Todic] Search url: " + url          # print "[Todic] Search url: " + url
# Line 412  def searchSeries(): Line 415  def searchSeries():
415  #=================================== Tool Box =======================================  #=================================== Tool Box =======================================
416  # shows a more userfriendly notification  # shows a more userfriendly notification
417  def showMessage(heading, message):  def showMessage(heading, message):
418        print( "[Todic::showMessage] " + str(message) )
419        print( message )
420      duration = 15 * 1000      duration = 15 * 1000
421      xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' %      xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' %
422                          (heading, message, duration))                          (heading, message, duration))
# Line 465  mode = None Line 470  mode = None
470  #print params  #print params
471    
472  try:  try:
473      url = urllib.unquote_plus(params["url"])      url = urllib.parse.unquote(params["url"])
474  except:  except:
475      pass      pass
476  try:  try:
477      name = urllib.unquote_plus(params["name"])      name = urllib.parse.unquote(params["name"])
478  except:  except:
479      pass      pass
480  try:  try:
# Line 477  try: Line 482  try:
482  except:  except:
483      pass      pass
484    
485    print( "[Todic] url=" + str(url))
486    print( "[Todic] name=" + str(name))
487    print( "[Todic] mode=" + str(mode))
488    
489    
490  try:  try:
491      open_url("http://todic.dk")      open_url("https://todic.dk")
492  except:  except:
493      showMessage("Fejl", "Kunne ikke forbinde til todic.dk")      showMessage("Fejl", "Kunne ikke forbinde til todic.dk")
494      exit()      exit()

Legend:
Removed from v.3251  
changed lines
  Added in v.3263

  ViewVC Help
Powered by ViewVC 1.1.20