v20 Help for RunScript addon function from settings.xml
#1
Hi,

I have an addon, named: service.subtitles.subs (example name)

with the following module:
service.subtitles.subs/resources/modules/clean_cache_functions.py

Python:
# Imports
import xbmcgui,xbmcvfs,xbmcaddon
import os,shutil,sys

# Addon parameters
MyAddonName = xbmcaddon.Addon().getAddonInfo('name')
iconx=xbmcaddon.Addon().getAddonInfo('icon')

# Cache Directories
xbmc_tranlate_path = xbmcvfs.translatePath
user_dataDir = xbmc_tranlate_path(xbmcaddon.Addon().getAddonInfo("profile"))
CachedSubFolder = xbmc_tranlate_path(os.path.join(user_dataDir, 'cache'))
TransFolder = xbmc_tranlate_path(os.path.join(user_dataDir, 'trans'))

# Notify function
def notify(msg_id, times=500, icon=iconx,sound=False):
        xbmcgui.Dialog().notification(MyAddonName, msg_id, icon, int(times), sound)

# Get command line arguments
args = sys.argv
action = None

# Check if the script is called with arguments
if len(args) > 1:
    action = args[1]
    
    
if action == "clean_folders":
    # some code
    

I'm trying to call this module with action = "clean_folders" parameter, from addon's setting. Using RunScript().
settings.xml:

XML:
<setting label="Clean Folders" type="action" action="RunScript(special://home/addons/service.subtitles.subs/resources/modules/clean_cache_functions.py, clean_folders)" />


I'm stuck on this error:
Log:
error <general>: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
                        - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
                       Error Type: <class 'RuntimeError'>
                       Error Contents: No valid addon id could be obtained. None was passed and the script wasn't executed in a normal Kodi manner.
                       Traceback (most recent call last):
                         File "C:\Users\my_user\AppData\Roaming\Kodi\addons\service.subtitles.All_Subs\resources\modules\clean_cache_functions.py", line 6, in <module>
                           MyAddonName = xbmcaddon.Addon().getAddonInfo('name')
                       RuntimeError: No valid addon id could be obtained. None was passed and the script wasn't executed in a normal Kodi manner.
                       -->End of Python script error report<--

The code can't identify addon ID, for addon information (name, icon, etc..)

Thanks for help
Reply
#2
disregard
Reply
#3
(2023-08-14, 02:34)barronen1 Wrote: I'm trying to call this module with action = "clean_folders" parameter, from addon's setting. Using RunScript().

Without seeing all of your code, I am not sure of the exact issue but I would guess this is an extension point issue.  Take a look at this addon specifically the utilites.py file and line 9 in the addon.xml file.   I think you need to add a similar line in your addon.xml file for your /resources/modules/clean_cache_functions.py file.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#4
(2023-08-14, 03:35)jbinkley60 Wrote:
(2023-08-14, 02:34)barronen1 Wrote: I'm trying to call this module with action = "clean_folders" parameter, from addon's setting. Using RunScript().

Without seeing all of your code, I am not sure of the exact issue but I would guess this is an extension point issue.  Take a look at this addon specifically the utilites.py file and line 9 in the addon.xml file.   I think you need to add a similar line in your addon.xml file for your /resources/modules/clean_cache_functions.py file.


Thanks,

Jeff

Thanks for the reply!

So it will be in addon.xml in this syntax?

XML:
<extension point="xbmc.python.library" library="resources/modules/clean_cache_functions.py"/>
Reply
#5
(2023-08-14, 03:48)barronen1 Wrote:
(2023-08-14, 03:35)jbinkley60 Wrote:
(2023-08-14, 02:34)barronen1 Wrote: I'm trying to call this module with action = "clean_folders" parameter, from addon's setting. Using RunScript().

Without seeing all of your code, I am not sure of the exact issue but I would guess this is an extension point issue.  Take a look at this addon specifically the utilites.py file and line 9 in the addon.xml file.   I think you need to add a similar line in your addon.xml file for your /resources/modules/clean_cache_functions.py file.


Thanks,

Jeff

Thanks for the reply!

So it will be in addon.xml in this syntax?

XML:
<extension point="xbmc.python.library" library="resources/modules/clean_cache_functions.py"/>

Yes, I believe that will eliminate the error you are seeing.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#6
(2023-08-14, 10:16)jbinkley60 Wrote: Yes, I believe that will eliminate the error you are seeing.


Jeff

Unfortunately, I get the same error in kodi.log

addon.xml:

XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="service.subtitles.subs" name="Subs" version="1.0.0" provider-name="Subs">
  <requires>
    
    <import addon="script.module.requests" version="2.9.1" />
    <import addon="script.module.chardet" />
    
  </requires>
  <extension point="xbmc.subtitle.module" library="start.py"  start="startup"></extension>
  <extension point="xbmc.service" library="autosub.py"/>
  <extension point="xbmc.python.library" library="resources/modules/clean_cache_functions.py"/>
  <extension point="xbmc.addon.metadata">
    <reuselanguageinvoker>true</reuselanguageinvoker>
    <summary lang="en">addon summary</summary>
    <description lang="en">addon description</description>
    <assets>
            <icon>icon.png</icon>
            <fanart>fanart.png</fanart>
    </assets>
    <language>en</language>
  </extension>
    
</addon>
Reply
#7
(2023-08-15, 10:09)TwilightMercy Wrote: Unfortunately, I get the same error in kodi.log

addon.xml:

I believe the problem is related to how you are calling the script in your settings.xml file.  See this example I use.  You call your addon, pass any extra data as a variable.  The addon.xml entry you added tells Kodi what file to run.  In your settings.xml file above you are attempting to call the script directly.  Let Kodi do that via the addon.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#8
(2023-08-15, 11:57)jbinkley60 Wrote: I believe the problem is related to how you are calling the script in your settings.xml file.  See this example I use.  You call your addon, pass any extra data as a variable.  The addon.xml entry you added tells Kodi what file to run.  In your settings.xml file above you are attempting to call the script directly.  Let Kodi do that via the addon.


Thanks,

Jeff
I see, I haven't tried yet. but what you suggest is changing:

XML:
<setting label="Clean Folders" type="action" action="RunScript(special://home/addons/service.subtitles.subs/resources/modules/clean_cache_functions.py, clean_folders)" />

To:

XML:
<setting label="Clean Folders" type="action" action="RunScript(service.subtitles.subs, clean_folders)" />

It will know to send "clean_folders" to clean_cache_functions.py file?
Reply
#9
(2023-08-15, 16:32)TwilightMercy Wrote: XML:<setting label="Clean Folders" type="action" action="RunScript(service.subtitles.subs, clean_folders)" />

Yes, that should work.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#10
Thank you it works!
Reply
#11
(2023-08-15, 18:09)TwilightMercy Wrote: Thank you it works!

Great to hear.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#12
(2023-08-15, 20:51)jbinkley60 Wrote:
(2023-08-15, 18:09)TwilightMercy Wrote: Thank you it works!

Great to hear.


Jeff

I have another question,
Now that the function works from settings, can it automatically run every settings change / save in Kodi?
Reply
#13
(2023-08-16, 08:41)TwilightMercy Wrote: I have another question,
Now that the function works from settings, can it automatically run every settings change / save in Kodi?

I believe there is a way to detect when an addon setting has been changed and then take an action.  I've seen it but can't recall it right now.  Maybe someone else here can assist.  For my addon, I check the setting value of interest when the GUI runs.


Thanks,

Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply
#14
(2023-08-16, 11:24)jbinkley60 Wrote:
(2023-08-16, 08:41)TwilightMercy Wrote: I have another question,
Now that the function works from settings, can it automatically run every settings change / save in Kodi?

I believe there is a way to detect when an addon setting has been changed and then take an action.  I've seen it but can't recall it right now.  Maybe someone else here can assist.  For my addon, I check the setting value of interest when the GUI runs.


Thanks,

Jeff

Instead I want to run: xbmc.executebuiltin("RunScript(service.subtitles.subs, clean_folders)") at Kodi startup.

I added this line to addon.xml:
XML:
<extension point="xbmc.service" library="kodi_startup.py" start="startup" />

kodi_startup.py code:
Python:
import xbmc

xbmc.executebuiltin("RunScript(service.subtitles.subs, clean_folders)")

The code indeed works and runs at Kodi launch. but then the code runs again when I launch the addon inside Kodi.
I want to run the code only once for Kodi startup only.

Is it possible?
Reply
#15
(2023-08-18, 13:20)TwilightMercy Wrote: The code indeed works and runs at Kodi launch. but then the code runs again when I launch the addon inside Kodi.
I want to run the code only once for Kodi startup only.

Is it possible?

Yes, you'll need to catch sys.argv[2]  in your kodi_startup.py file and if it is "clean_folders" then don't execute.  Another way to do it is in your service since it only runs once.  I do this here in my sevice.py file.  These three functions only get called once when the service starts.


Jeff
Running with the Mezzmo Kodi addon.  The easier way to share your media with multiple Kodi clients.
Service.autostop , CBC Sports, Kodi Selective Cleaner and Mezzmo Kodi addon author.
Reply

Logout Mark Read Team Forum Stats Members Help
Help for RunScript addon function from settings.xml0