PYTHON   1

tvskipintro - service.py

Guest
le 13 January 2025

  1. # -*- coding: utf-8 -*-
  2.  
  3. '''
  4.    TvSkipIntro Add-on
  5.    Copyright (C) 2018 aenema
  6.  
  7.    This program is free software: you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation, either version 3 of the License, or
  10.    (at your option) any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program.  If not, see .
  19. '''
  20.  
  21. import xbmcvfs,xbmc,xbmcaddon,json,os,xbmcgui, time, re
  22.  
  23. KODI_VERSION = int(xbmc.getInfoLabel("System.BuildVersion").split(".")[0])
  24. addonInfo = xbmcaddon.Addon().getAddonInfo
  25. settings = xbmcaddon.Addon().getSetting
  26. profilePath = xbmcvfs.translatePath(addonInfo('profile'))
  27. addonPath = xbmcvfs.translatePath(addonInfo('path'))
  28. skipFile = os.path.join(profilePath, 'skipintro.json')
  29. defaultSkip = settings('default.skip')
  30. if not os.path.exists(profilePath): xbmcvfs.mkdir(profilePath)
  31.  
  32. def cleantitle(title):
  33.     if title == None: return
  34.     title = title.lower()
  35.     title = re.sub('&#(\d+);', '', title)
  36.     title = re.sub('(&#[0-9]+)([^;^0-9]+)', '\\1;\\2', title)
  37.     title = title.replace('"', '\"').replace('&', '&')
  38.     title = re.sub(r'\]*\>','', title)
  39.     title = re.sub('\n|([[].+?[]])|([(].+?[)])|\s(vs|v[.])\s|(:|;|-|"|,|\'|\_|\.|\?)|\(|\)|\[|\]|\{|\}|\s', '', title).lower()
  40.     return title.lower()
  41.    
  42. def updateSkip(title, seconds=defaultSkip, start=0, service=True):
  43.     with open(skipFile, 'r') as file:
  44.          json_data = json.load(file)
  45.          for item in json_data:
  46.                if cleantitle(item['title']) == cleantitle(title):
  47.                   item['service'] = service
  48.                   item['skip'] = seconds
  49.                   item['start'] = start
  50.     with open(skipFile, 'w') as file:
  51.         json.dump(json_data, file, indent=2)
  52.        
  53. def newskip(title, seconds, start=0):
  54.     if seconds == '' or seconds == None: seconds = defaultSkip
  55.     newIntro = {'title': title, 'service': True, 'skip': seconds, 'start': start}
  56.     try:
  57.         with open(skipFile) as f:
  58.             data = json.load(f)
  59.     except:
  60.         data = []
  61.     for item in data:
  62.         if cleantitle(title) in cleantitle(item['title']):
  63.             updateSkip(title, seconds=seconds, start=start, service=True)
  64.             return
  65.     data.append(newIntro)
  66.     with open(skipFile, 'w') as f:
  67.         json.dump(data, f, indent=2)
  68.  
  69. def getSkip(title):
  70.     try:
  71.         with open(skipFile) as f:
  72.             data = json.load(f)
  73.         skip = [i for i in data if i['service'] != False]
  74.         skip = [i['skip'] for i in skip if cleantitle(i['title']) == cleantitle(title)][0]
  75.     except:
  76.         skip = defaultSkip
  77.         newskip(title, skip)
  78.     return  skip
  79.    
  80. def checkService(title):
  81.     try:
  82.         with open(skipFile) as f: data = json.load(f)
  83.         skip = [i['service'] for i in data if cleantitle(i['title']) == cleantitle(title)][0]
  84.     except: skip = True
  85.     return  skip
  86.  
  87. def checkStartTime(title):
  88.     try:
  89.         with open(skipFile) as f: data = json.load(f)
  90.         start = [i['start'] for i in data if cleantitle(i['title']) == cleantitle(title)][0]
  91.     except: start = 0
  92.     return  start
  93.    
  94. if not os.path.exists(skipFile): newskip('default', defaultSkip)
  95.  
  96.  
  97. class Service():
  98.  
  99.     WINDOW = xbmcgui.Window(10000)
  100.  
  101.     def __init__(self, *args):
  102.         addonName = 'Skip Player'
  103.         self.skipped = False
  104.  
  105.  
  106.  
  107.     def ServiceEntryPoint(self):
  108.         monitor = xbmc.Monitor()
  109.  
  110.  
  111.         while not monitor.abortRequested():
  112.             # check every 5 sec
  113.             if monitor.waitForAbort(5):
  114.                 # Abort was requested while waiting. We should exit
  115.                 break
  116.             if xbmc.Player().isPlaying():
  117.                 try:
  118.                     playTime = xbmc.Player().getTime()
  119.  
  120.                     totalTime = xbmc.Player().getTotalTime()
  121.  
  122.                     self.currentShow = xbmc.getInfoLabel("VideoPlayer.TVShowTitle")
  123.                     if self.currentShow:
  124.                        
  125.                         if playTime > 250: self.skipped = True
  126.                         if self.skipped == False: self.SkipIntro(self.currentShow)
  127.                     print(("CURRENT SHOW PLAYER", currentShow, playTime))
  128.                 except:pass
  129.             else: self.skipped = False
  130.                
  131.     def SkipIntro(self, tvshow):
  132.         try:
  133.             if not xbmc.Player().isPlayingVideo(): raise Exception()
  134.            
  135.             time.sleep(2)
  136.             timeNow = xbmc.Player().getTime()
  137.             status = checkService(tvshow)
  138.            
  139.             if status == False:
  140.                 self.skipped = True
  141.                 raise Exception()
  142.             startTime = checkStartTime(tvshow)
  143.            
  144.             if int(startTime) >= int(timeNow): raise Exception()
  145.            
  146.             Dialog = CustomDialog('script-dialog.xml', addonPath, show=tvshow)
  147.             Dialog.doModal()
  148.             self.skipped = True
  149.             del Dialog  
  150.            
  151.         except:pass
  152.  
  153. OK_BUTTON = 201
  154. NEW_BUTTON = 202
  155. DISABLE_BUTTON = 210
  156. ACTION_PREVIOUS_MENU = 10
  157. ACTION_BACK = 92
  158. INSTRUCTION_LABEL = 203
  159. AUTHCODE_LABEL = 204
  160. WARNING_LABEL = 205
  161. CENTER_Y = 6
  162. CENTER_X = 2
  163.  
  164. class CustomDialog(xbmcgui.WindowXMLDialog):
  165.  
  166.     def __init__(self, xmlFile, resourcePath, show):
  167.         self.tvshow = show
  168.  
  169.     def onInit(self):
  170.         instuction = ''
  171.         self.skipValue = int(getSkip(self.tvshow))
  172.         skipLabel = 'SKIP INTRO: %s' % self.skipValue
  173.         skipButton = self.getControl(OK_BUTTON)
  174.         skipButton.setLabel(skipLabel)
  175.        
  176.     def onAction(self, action):
  177.         if action == ACTION_PREVIOUS_MENU or action == ACTION_BACK:
  178.             self.close()
  179.  
  180.     def onControl(self, control):
  181.         pass
  182.  
  183.     def onFocus(self, control):
  184.         pass
  185.  
  186.     def onClick(self, control):
  187.         print(('onClick: %s' % (control)))
  188.  
  189.         if control == OK_BUTTON:
  190.             timeNow = xbmc.Player().getTime()
  191.             skipTotal = int(timeNow) + int(self.skipValue)
  192.             xbmc.Player().seekTime(int(skipTotal))          
  193.  
  194.         if control == NEW_BUTTON:
  195.             dialog = xbmcgui.Dialog()
  196.             d = dialog.input('Skip Value (seconds)', type=xbmcgui.INPUT_NUMERIC)
  197.             d2 = 0
  198.             d2 = dialog.input('Prompt At (seconds)', type=xbmcgui.INPUT_NUMERIC)
  199.             if d2 == '' or d2 == None: d2 = 0
  200.             if str(d) != '' and str(d) != '0': newskip(self.tvshow , d , start=d2)
  201.  
  202.                    
  203.            
  204.         if control == DISABLE_BUTTON:
  205.             updateSkip(self.tvshow, seconds=self.skipValue, service=False)
  206.            
  207.  
  208.         if control in [OK_BUTTON, NEW_BUTTON, DISABLE_BUTTON]:
  209.             self.close()
  210.            
  211. Service().ServiceEntryPoint()

Modifier ce paste:


<b><a class="btn btn-default" data-target="#signin" data-toggle="modal" href="#">CONNEXION</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-default" data-target="#signup" data-toggle="modal" href="#">INSCRIPTION</a></b>