Solved Python update for Addon
#1
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)
Reply
#2
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)
Reply
#3
Thread moved to Python3 migration section.
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply
#4
(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
Reply
#5
Thread marked solved.
Reply
#6
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
Reply



Logout Mark Read Team Forum Stats Members Help
Python update for Addon0
This forum uses Lukasz Tkacz MyBB addons.