Help with call script fro skin to addon.
#1
Ok, unfortunally, my knowledge do not alowed me to get this work, I need some help from experts:

I have this two buttons on a skin:

Code:
<!-- This Button Make a Issue -->
<control type="button" id="1032">
     <visible>Container.Content(images) + System.HasAddon(plugin.program.newsstand) + Container.HasFiles</visible>
     <include>DialogSettingButton</include>
     <onclick>RunScript(special://home/addons/plugin.program.newsstand/resources/make_issue.py, issue, $INFO[ListItem.Path], $INFO[ListItem.FolderName])</onclick>
     <label>Make this folder a Issue</label>
     <align>center</align>
</control>

<!-- This Button Make a Album -->
<control type="button" id="1033">
     <visible>Container.Content(images) + System.HasAddon(plugin.program.newsstand) + Container.HasFiles</visible>
     <include>DialogSettingButton</include>
     <onclick>RunScript(special://home/addons/plugin.program.newsstand/resources/make_issue.py, album, $INFO[ListItem.Path], $INFO[ListItem.FolderName])</onclick>
     <label>Add to NewsStand Albuns</label>
     <align>center</align>
</control>

This two buttons poit to this script:

Code:
import xbmc
import xbmcgui
import sys

path = sys.argv[2]
name = sys.argv[3]

def make_issue():
    if not os.path.exists(path + name + '.album'):
        with open(path + name + '.album', 'w') as f:
            f.write('this is a album file!')
            xbmcgui.Dialog().notification('NewsStand', 'Album "{}" created on "{}"'.format(name, path), xbmcgui.NOTIFICATION_INFO)
    else: 
        xbmcgui.Dialog().notification('NewsStand', 'Album "{}" already saved on "{}"'.format(name, path), xbmcgui.NOTIFICATION_WARNING) 
        
def make_album():
    xbmc.executebuiltin('RunPlugin(plugin://plugin.program.newsstand/?com=ADD_ALBUM_SKIN)')

# --- Script Entry Point ---#
if ( __name__ == "__main__" ):
    if len(sys.argv[ 1 ]) > 0:
        if sys.argv[1] == "issue":
            make_issue()
        elif sys.argv[1] == "album":
            make_album()

If the button with the argument "issue" is pressed, the "make_issue" def is executed.
If the button with the argument "album" is pressed, the "make_album" def is executed.

Until this point, this work very well.

My question is: 
When the secont button is pressed (the one with "album" argument), "make_album" def calls the "_command_add_new_album" def in main.py from de addon NewsStand (this is just a private addon that I'm "creating" to learn how to develop addon for Kodi, ignore it for now). 

the begining of this "_command_add_new_album" is this one:
Code:
def _command_add_new_album(self):
        
        LAUNCHER_FOLDER          = 2
        categoryID = 'Albuns'
        launcher_type = LAUNCHER_FOLDER
        app = MAGAZINE_FOLDER_APP_NAME 
        app_FName = FileName(app)
        ext = 'album'
        args = '$rom$'
        path = 'I Need to put the variable "path = sys.argv[2]" here'
        ....

It's possible to insert the "path" variable from the first script? 
I already tried using "from the .make_issue import *", but the variable becomes "?com=ADD_ALBUM_SKIN". And from what I've researched, the command "xbmc.executebuiltin('RunPlugin(plugin') is the one who changes the sys.argv variables, correct?

Is there a way to do this?

thanks in advance
Reply
#2
(2022-08-10, 21:57)sagrath Wrote: It's possible to insert the "path" variable from the first script? 
I already tried using "from the .make_issue import *", but the variable becomes "?com=ADD_ALBUM_SKIN". And from what I've researched, the command "xbmc.executebuiltin('RunPlugin(plugin') is the one who changes the sys.argv variables, correct?

Is there a way to do this?

thanks in advance

I am not an expert, just someone who learned this one the hard way Smile

I think you are looking for something like this:

xbmc.executebuiltin('RunScript(%s, %s)' % ("plugin.video.mezzmo", "performance"))

In this example I am passing two variables to Runscript, the first is the addon name and the second is another variable I parse to decide what to do.  It should just as easily be a path variable.  You can pass more variables than 2 by adding additional instances of %s and variables.

On the receiving side I parse the second variable like:

if sys.argv[1] == 'performance':                                # Display Performance stats
    displayMenu()

Remember sys.argv variables start with 0, which will be the addon name.  sys.argv[1] will be the first one you can parse.


The other method, if you want to pass as a URL is like so:

base_url = sys.argv[0]

def build_url(query):
    return base_url + '?' + urllib.urlencode(query)

itemurl = build_url({'mode': 'server', 'contentdirectory': contenturl})

On the receiving side you I parse for mode or contentdirectory like:

mode = args.get('mode', 'none')

if mode[0] == 'server':
    url = args.get('contentdirectory', '')
    # Do something
elif mode == 'none':
    # Do something else




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

Logout Mark Read Team Forum Stats Members Help
Help with call script fro skin to addon.0