/[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 3256 by torben, Tue Mar 5 10:58:04 2019 UTC revision 3265 by torben, Sat Mar 20 18:35: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.4
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 platform
22    
23  # import pprint  # import pprint
24    
# Line 36  if __entrypoint__ == "testing": Line 39  if __entrypoint__ == "testing":
39    
40  print( "[Todic] entrypoint: " + __entrypoint__ )  print( "[Todic] entrypoint: " + __entrypoint__ )
41  print( "[Todic] backend: " + __backend__ )  print( "[Todic] backend: " + __backend__ )
42    print( "[Todic] version: " + __addon__.getAddonInfo('version') )
43    
44  fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg')  fanartImage = os.path.join(__addon__.getAddonInfo('path'), 'movie_bg_blur.jpg')
45  datapath = xbmc.translatePath(  datapath = xbmcvfs.translatePath(
46      'special://profile/addon_data/plugin.video.todic/')      'special://profile/addon_data/plugin.video.todic/')
47    
48  ADDON_PATH = __addon__.getAddonInfo('path')  ADDON_PATH = __addon__.getAddonInfo('path')
# Line 147  class TodicPlayer(xbmc.Player): Line 150  class TodicPlayer(xbmc.Player):
150          self.reportPlaytime("ended")          self.reportPlaytime("ended")
151    
152      def tick(self):      def tick(self):
153          #print "[Todic] Tick: " + str( self.isPlaying() )          #print( "[Todic] Tick: " + str( self.isPlaying() ) )
154          if ( self.isPlaying() ):          if ( self.isPlaying() ):
155              tmpTime = self.getTime()              tmpTime = self.getTime()
156    
# Line 155  class TodicPlayer(xbmc.Player): Line 158  class TodicPlayer(xbmc.Player):
158              if tmpTime != self.playingPosition:              if tmpTime != self.playingPosition:
159                  self.playingPosition = tmpTime                  self.playingPosition = tmpTime
160                  now = time()                  now = time()
161                  #print "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport)                  #print( "[Todic] tick " + str(now) + " " + str(self.lastReport) + " : " +str(now - self.lastReport) )
162                  if ( (now - self.lastReport) > 60.0):                  if ( (now - self.lastReport) > 60.0):
163                      self.lastReport = now                      self.lastReport = now
164                      self.reportPlaytime("playing")                      self.reportPlaytime("playing")
# Line 197  def SaveFile(path, data): Line 200  def SaveFile(path, data):
200    
201    
202  def open_url(url):  def open_url(url):
203      req = urllib2.Request(url)      kodi_ver = xbmc.getInfoLabel('System.BuildVersion')
204      content = urllib2.urlopen(req)      reqobj = urllib.request.Request(
205      data = content.read()          url,
206      content.close()          data=None,
207      return data          headers={
208                'User-Agent': 'TodicKodi:' + str(__addon__.getAddonInfo('version')) + " Kodi:" + str(kodi_ver) + " Platform:" + str(platform.system()) + " " + str(platform.release())
209            }
210        )
211    
212        with urllib.request.urlopen(reqobj) as req:
213            #data = response.read()
214            #return data
215            charset=req.info().get_content_charset()
216            content=req.read().decode(charset)
217            return content
218    
219    
220  # wraps open url in a catch-all exception handler  # wraps open url in a catch-all exception handler
# Line 217  def open_url_safe(url): Line 230  def open_url_safe(url):
230  def rootMenu():  def rootMenu():
231      kodi_ver = xbmc.getInfoLabel('System.BuildVersion')      kodi_ver = xbmc.getInfoLabel('System.BuildVersion')
232      plugin_ver = __addon__.getAddonInfo('version')      plugin_ver = __addon__.getAddonInfo('version')
233      msgurl = __backend__ + "&action=messages&kodi=" + urllib.quote_plus(kodi_ver) + "&todicplugin=" + urllib.quote_plus(plugin_ver)      msgurl = __backend__ + "&action=messages&kodi=" + urllib.parse.quote(kodi_ver) + "&todicplugin=" + urllib.parse.quote(plugin_ver)
234    
235      msg = open_url(msgurl)      msg = open_url(msgurl)
236      msg = msg.strip()      msg = msg.strip()
237    
238      if msg != "":      if msg != "":
239            print("[Todic] rootMenu Dialog =" + str(msg))
240          dialog = xbmcgui.Dialog()          dialog = xbmcgui.Dialog()
241          dialog.ok('XBMC Todic', msg)          dialog.ok('XBMC Todic', msg)
242    
243      buildList(__backend__, "", False)  # call default list      buildList(__backend__, "", False)  # call default list
244    
245      # Adde xtra items to root menu      # Adde xtra items to root menu
246      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(label="Søg Film ...")
247          label="Søg Film ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')      listitem.setArt( { 'icon':'DefaultFolder.png', 'thumb':'DefaultFolder.png'} )
248      listitem.setProperty('Fanart_Image', fanartImage)      listitem.setProperty('Fanart_Image', fanartImage)
249    
250      u = sys.argv[0] + "?mode=10&name="      u = sys.argv[0] + "?mode=10&name="
# Line 238  def rootMenu(): Line 252  def rootMenu():
252          handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True)          handle=int(sys.argv[1]), url=u, listitem=listitem, isFolder=True)
253    
254      # add search series      # add search series
255      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(label="Søg Serier ...")
256          label="Søg Serier ...", iconImage='DefaultFolder.png', thumbnailImage='DefaultFolder.png')      listitem.setArt( { 'icon':'DefaultFolder.png', 'thumb':'DefaultFolder.png'} )
257      listitem.setProperty('Fanart_Image', fanartImage)      listitem.setProperty('Fanart_Image', fanartImage)
258    
259      u = sys.argv[0] + "?mode=11&name="      u = sys.argv[0] + "?mode=11&name="
# Line 250  def rootMenu(): Line 264  def rootMenu():
264    
265    
266  def buildList(url, title, endlist=True):  def buildList(url, title, endlist=True):
267      print( '[Todic]:' + str(url) )      print( '[Todic::buildList]:' + str(url) )
268    
269      link = open_url(url)      link = open_url(url)
270      doc = parseString(link)      doc = parseString(link)
# Line 280  def buildList(url, title, endlist=True): Line 294  def buildList(url, title, endlist=True):
294    
295  # print "name:" + name  # print "name:" + name
296  #               print "url:" + url  #               print "url:" + url
297  #               print "thumb:" + thumb  #               print "thumb:" + thumbi
298          listitem = xbmcgui.ListItem(          listitem = xbmcgui.ListItem(label=name, label2='test')
299              label=name, label2='test', iconImage='DefaultFolder.png')          listitem.setArt( {'icon': 'DefaultFolder.png'} )
300          listitem.setProperty('Fanart_Image', fanartImage)          listitem.setProperty('Fanart_Image', fanartImage)
301          listitem.addContextMenuItems([('Refresh', 'Container.Refresh')])          listitem.addContextMenuItems([('Refresh', 'Container.Refresh')])
302            listitem.setArt( {'thumb': thumb} )
303    
304          if mode == '50':          if mode == '50':
305              infoLabels = {}              infoLabels = {}
306              infoLabels['title'] = name              infoLabels['title'] = name
307              infoLabels['playcount'] = playcount              infoLabels['playcount'] = playcount
308              if playcount > 0:  #            if playcount > 0:
309                  listitem.setArt( {'thumb': thumb} ) #not pretty - but at least we can show a different icon for unwatched/watched in kodi18    #                listitem.setArt( {'thumb': thumb} ) #not pretty - but at least we can show a different icon for unwatched/watched in kodi18  
310              listitem.setInfo('video', infoLabels)              listitem.setInfo('video', infoLabels)
             listitem.setProperty('IsPlayable', 'true')  
311    
312          name = name.encode('UTF-8')          name = name.encode('UTF-8')
313    
314          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)  
315          xbmcplugin.addDirectoryItem(          xbmcplugin.addDirectoryItem(
316              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)
317    
# Line 330  def play_video(url, name): Line 343  def play_video(url, name):
343          if (savedPosition > 0):          if (savedPosition > 0):
344              dialog = xbmcgui.Dialog()              dialog = xbmcgui.Dialog()
345              #yes / true -afspil fra position              #yes / true -afspil fra position
346              answer = dialog.yesno(heading='Todic', line1='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt')              answer = dialog.yesno(heading='Todic', message='Afspil fra sidste position', nolabel='Fra start', yeslabel='Fortsæt')
347              if (answer == True):              if (answer == True):
348                  playPosition = savedPosition                  playPosition = savedPosition
349                    
# Line 349  def play_video(url, name): Line 362  def play_video(url, name):
362  def play_real_video(url, name, position):  def play_real_video(url, name, position):
363      xml = open_url(url)      xml = open_url(url)
364      print( '[Todic] url: ' + str(url) )      print( '[Todic] url: ' + str(url) )
365      print( '[Todic] xml: ' + xml )      print( '[Todic] xml: ' + str(xml) )
366      print( '[Todic] pos: ' + str(position) )      print( '[Todic] pos: ' + str(position) )
367    
368      doc = parseString(xml)      doc = parseString(xml)
# Line 361  def play_real_video(url, name, position) Line 374  def play_real_video(url, name, position)
374      print( '[Todic] subs: ' + str(subtitleurl) )      print( '[Todic] subs: ' + str(subtitleurl) )
375    
376      image = xbmc.getInfoImage('ListItem.Thumb')      image = xbmc.getInfoImage('ListItem.Thumb')
377      listitem = xbmcgui.ListItem(      listitem = xbmcgui.ListItem(label=name)
378          label=name, iconImage='DefaultVideo.png', thumbnailImage=image)      listitem.setArt( {'icon': 'DefaultVideo.png', 'thumb':image} )
379      listitem.setInfo(type="Video", infoLabels={"Title": name})      listitem.setInfo(type="Video", infoLabels={"Title": name})
380    
381      listitem.setProperty('StartOffset', str(position) )      listitem.setProperty('StartOffset', str(position) )
# Line 375  def play_real_video(url, name, position) Line 388  def play_real_video(url, name, position)
388    
389    
390      #Holder python kørernde indtil at det bliver bedt om at stoppe      #Holder python kørernde indtil at det bliver bedt om at stoppe
391      while (not xbmc.abortRequested):      kodiMonitor = xbmc.Monitor()
392        
393        
394        while (not kodiMonitor.abortRequested()):
395          player.tick()          player.tick()
396          xbmc.sleep(500)          kodiMonitor.waitForAbort( 1 )
397    
398    
399    
# Line 386  def search(): Line 402  def search():
402    
403      if (search != None and search != ""):      if (search != None and search != ""):
404          url = __backend__ + "&action=search&search=" + \          url = __backend__ + "&action=search&search=" + \
405              urllib.quote_plus(search)              urllib.parse.quote(search)
406    
407          # print "[Todic] Search start: " + search          # print "[Todic] Search start: " + search
408          # print "[Todic] Search url: " + url          # print "[Todic] Search url: " + url
# Line 399  def searchSeries(): Line 415  def searchSeries():
415    
416      if (search != None and search != ""):      if (search != None and search != ""):
417          url = __backend__ + "&action=searchseries&search=" + \          url = __backend__ + "&action=searchseries&search=" + \
418              urllib.quote_plus(search)              urllib.parse.quote(search)
419    
420          # print "[Todic] Search start: " + search          # print "[Todic] Search start: " + search
421          # print "[Todic] Search url: " + url          # print "[Todic] Search url: " + url
# Line 410  def searchSeries(): Line 426  def searchSeries():
426  #=================================== Tool Box =======================================  #=================================== Tool Box =======================================
427  # shows a more userfriendly notification  # shows a more userfriendly notification
428  def showMessage(heading, message):  def showMessage(heading, message):
429        print( "[Todic::showMessage] " + str(message) )
430        print( message )
431      duration = 15 * 1000      duration = 15 * 1000
432      xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' %      xbmc.executebuiltin('XBMC.Notification("%s", "%s", %s)' %
433                          (heading, message, duration))                          (heading, message, duration))
# Line 463  mode = None Line 481  mode = None
481  #print params  #print params
482    
483  try:  try:
484      url = urllib.unquote_plus(params["url"])      url = urllib.parse.unquote(params["url"])
485  except:  except:
486      pass      pass
487  try:  try:
488      name = urllib.unquote_plus(params["name"])      name = urllib.parse.unquote(params["name"])
489  except:  except:
490      pass      pass
491  try:  try:
# Line 475  try: Line 493  try:
493  except:  except:
494      pass      pass
495    
496    print( "[Todic] url=" + str(url))
497    print( "[Todic] name=" + str(name))
498    print( "[Todic] mode=" + str(mode))
499    
500    
501  try:  try:
502      open_url("http://todic.dk")      open_url("https://todic.dk")
503  except:  except:
504      showMessage("Fejl", "Kunne ikke forbinde til todic.dk")      showMessage("Fejl", "Kunne ikke forbinde til todic.dk")
505      exit()      exit()

Legend:
Removed from v.3256  
changed lines
  Added in v.3265

  ViewVC Help
Powered by ViewVC 1.1.20