Kodi Community Forum
Solved Python update for Addon - Printable Version

Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+---- Forum: Python 3 migration (https://forum.kodi.tv/forumdisplay.php?fid=281)
---- Thread: Solved Python update for Addon (/showthread.php?tid=362688)



Python update for Addon - Drtatom - 2021-05-19

Hi

Can anyone help me updating this small addon made in python 2.1 to 3.0 to use it in Kodi 19?.
The addon is not mine. It was developed by Amet in Github https://github.com/amet/script.stop
I tried to contact the developer with no success.

The purpose of this addon is to stop paused video after set amount of time. 

Thank you!!

This is the code of default.py

# -*- coding: utf-8 -*- 

import os
import sys
import xbmc
import xbmcaddon,xbmcvfs
import urllib,xbmcplugin

__addon__      = xbmcaddon.Addon()
__author__     = __addon__.getAddonInfo('author')
__scriptid__   = __addon__.getAddonInfo('id')
__scriptname__ = __addon__.getAddonInfo('name')
__cwd__        = __addon__.getAddonInfo('path')
__version__    = __addon__.getAddonInfo('version')
__language__   = __addon__.getLocalizedString

__cwd__        = xbmc.translatePath( __addon__.getAddonInfo('path') ).decode("utf-8")
__profile__    = xbmc.translatePath( __addon__.getAddonInfo('profile') ).decode("utf-8")
__resource__   = os.path.join( __cwd__, u'resources', u'lib' )


class MyPlayer( xbmc.Player ):
  def __init__( self, *args, **kwargs ):
    xbmc.Player.__init__( self )
    xbmc.log('MyPlayer - init')
    self.paused = False
        
  def onPlayBackStopped( self ):
    self.paused = False
  
  def onPlayBackEnded( self ):
    self.paused = False    
  
  def onPlayBackStarted( self ):
    self.paused = False

  def onPlayBackPaused( self ):
    self.paused = True

  def onPlayBackResumed( self ):
    self.paused = False    

player_monitor = MyPlayer()

counter = 0
delay = int(__addon__.getSetting("delay"))
while not xbmc.abortRequested:
  if player_monitor.paused == True:
    counter += 1
    if counter > delay*300:
      xbmc.Player().stop()
      counter = 0
  else:
    counter = 0   
  xbmc.sleep(200)



RE: Python update for Addon - matthuisman - 2021-05-19

Remember to change addon.xml to depend on python3

import os
import xbmc
import xbmcaddon
import xbmcvfs

__addon__      = xbmcaddon.Addon()
__author__     = __addon__.getAddonInfo('author')
__scriptid__   = __addon__.getAddonInfo('id')
__scriptname__ = __addon__.getAddonInfo('name')
__cwd__        = __addon__.getAddonInfo('path')
__version__    = __addon__.getAddonInfo('version')
__language__   = __addon__.getLocalizedString

__cwd__        = xbmcvfs.translatePath( __addon__.getAddonInfo('path') )
__profile__    = xbmcvfs.translatePath( __addon__.getAddonInfo('profile') )
__resource__   = os.path.join( __cwd__, 'resources', 'lib' )


class MyPlayer( xbmc.Player ):
  def __init__( self, *args, **kwargs ):
    xbmc.Player.__init__( self )
    xbmc.log('MyPlayer - init')
    self.paused = False

  def onPlayBackStopped( self ):
    self.paused = False

  def onPlayBackEnded( self ):
    self.paused = False

  def onPlayBackStarted( self ):
    self.paused = False

  def onPlayBackPaused( self ):
    self.paused = True

  def onPlayBackResumed( self ):
    self.paused = False

player_monitor = MyPlayer()

counter = 0
delay = int(__addon__.getSetting("delay") or 60)

monitor = xbmc.Monitor()
while not monitor.abortRequested():
  if player_monitor.paused == True:
    counter += 1
    if counter > delay*300:
      player_monitor.stop()
      counter = 0
  else:
    counter = 0
  xbmc.sleep(200)



RE: Python update for Addon - DarrenHill - 2021-05-19

Thread moved to Python3 migration section.


RE: Python update for Addon - Drtatom - 2021-05-19

(2021-05-19, 08:29)matthuisman Wrote: Remember to change addon.xml to depend on python3

import os
import xbmc
import xbmcaddon
import xbmcvfs

__addon__      = xbmcaddon.Addon()
__author__     = __addon__.getAddonInfo('author')
__scriptid__   = __addon__.getAddonInfo('id')
__scriptname__ = __addon__.getAddonInfo('name')
__cwd__        = __addon__.getAddonInfo('path')
__version__    = __addon__.getAddonInfo('version')
__language__   = __addon__.getLocalizedString

__cwd__        = xbmcvfs.translatePath( __addon__.getAddonInfo('path') )
__profile__    = xbmcvfs.translatePath( __addon__.getAddonInfo('profile') )
__resource__   = os.path.join( __cwd__, 'resources', 'lib' )


class MyPlayer( xbmc.Player ):
  def __init__( self, *args, **kwargs ):
    xbmc.Player.__init__( self )
    xbmc.log('MyPlayer - init')
    self.paused = False

  def onPlayBackStopped( self ):
    self.paused = False

  def onPlayBackEnded( self ):
    self.paused = False

  def onPlayBackStarted( self ):
    self.paused = False

  def onPlayBackPaused( self ):
    self.paused = True

  def onPlayBackResumed( self ):
    self.paused = False

player_monitor = MyPlayer()

counter = 0
delay = int(__addon__.getSetting("delay") or 60)

monitor = xbmc.Monitor()
while not monitor.abortRequested():
  if player_monitor.paused == True:
    counter += 1
    if counter > delay*300:
      player_monitor.stop()
      counter = 0
  else:
    counter = 0
  xbmc.sleep(200)
Thank you matthuisman!!!
The addon worked like a charm


Python update for Addon - PatK - 2021-05-24

Thread marked solved.


RE: Python update for Addon - jbinkley60 - 2021-05-28

Thanks for posting this thread.  The stopping of a paused playback, after a specific amount of time,  function is something I had never thought of.  I've now added this functionality to my uPNP server addon.  It's a great feature.  


Jeff


This forum uses Lukasz Tkacz MyBB addons.