Kodi Community Forum

Full Version: Removing default Add favorites in context menu
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
So i have been playing around with the offical plex script and noticed when pressing c for the context menu we do not get the default annoying add to favorites option in there context menu.
Can someone explain to me how they are by passing this since from my past understand that was something that we where not supposed to be able to over ride. As i too would like to remove it from a future plugin.
if it is really a 'script' and not a 'plugin', you would need to construct the context menu yourself.
only plugins use (and can add items, but not remove) from the default context menu in kodi.

check the docs on how to create a context menu in a script addon:
https://codedocs.xyz/xbmc/xbmc/group__py...b690163bef
So I would add that to the container as I did with the plugin correct, just this time if it don't add it there will be no context menu.

Again thank you for all your help on the past year plus... I just hope what you am working on turns out to be worth time.

On a side note I am learning a lot. So that's a plus.
nope, it works differently...

your script needs to listen for input actions. whenever someone presses the context menu button on their keyboard/remote
your script should call the context dialog function.

python:
def onAction(self, action):
    if action.getId() == 117:
        selection = xbmcgui.Dialog().contextmenu(['Option #1', 'Option #2', 'Option #3'])

https://codedocs.xyz/xbmc/xbmc/group__py...ction.html
I will give it a test run later tonight when I get a little free time...

Is it sad I am getting a little excited with all this new information? 😆
(2018-05-29, 09:14)ronie Wrote: [ -> ]if it is really a 'script' and not a 'plugin', you would need to construct the context menu yourself.
only plugins use (and can add items, but not remove) from the default context menu in kodi.

check the docs on how to create a context menu in a script addon:
https://codedocs.xyz/xbmc/xbmc/group__py...b690163bef

I have a plugin where I've added some context menu items.  One thing which would be very desirable is if I could override the behavior of an existing context menu item, specifically the Mark Watched behavior.  I see from above that a deleting and replacing by adding isn't an option.  Can a plugin via the onAction capability override the behavior or is that limited to scripts ?
(2020-08-28, 11:07)jbinkley60 Wrote: [ -> ]Can a plugin via the onAction capability override the behavior or is that limited to scripts ?

that's indeed for scripts only...
(2020-08-28, 11:42)ronie Wrote: [ -> ]
(2020-08-28, 11:07)jbinkley60 Wrote: [ -> ]Can a plugin via the onAction capability override the behavior or is that limited to scripts ?

that's indeed for scripts only...
Thanks for the quick response.  Can a plugin extend the functionality of a builtin context menu item ?  I am thinking let the default behavior occur but then via onAction perform some additional actions.  Is that possible ?  I am wanting to use the Mark watched context menu item to update the play counter on my uPNP server.  Right now it updates the Kodi database.  I am trying to avoid adding another context menu item.
onAction can only be used by scripts who create their own window.
the purpose of onAction is to capture actions that are send to that window.

what i think you could do is create a service addon that uses the onNotification method of the xbmc.Monitor() class.
that way you can receive a notification whever on update to your database occurs.

python:
import xbmc

class Main():
    def __init__(self):
        self.Monitor = MyMonitor()
        while not self.Monitor.abortRequested():
            xbmc.sleep(100)

class MyMonitor(xbmc.Monitor):
    def __init__(self):
        xbmc.Monitor.__init__(self)

    def onNotification(self, sender, method, data):
        print(sender)
        print(method)
        print(data)

if __name__ == '__main__':
    Main()


an example of the sender, method and data this will capture:
Code:
xbmc
VideoLibrary.OnUpdate
{"item":{"id":40,"type":"movie"},"playcount":1}
(2020-08-29, 00:31)ronie Wrote: [ -> ]onAction can only be used by scripts who create their own window.
the purpose of onAction is to capture actions that are send to that window.

what i think you could do is create a service addon that uses the onNotification method of the xbmc.Monitor() class.
that way you can receive a notification whever on update to your database occurs.

python:
import xbmc

class Main():
    def __init__(self):
        self.Monitor = MyMonitor()
        while not self.Monitor.abortRequested():
            xbmc.sleep(100)

class MyMonitor(xbmc.Monitor):
    def __init__(self):
        xbmc.Monitor.__init__(self)

    def onNotification(self, sender, method, data):
        print(sender)
        print(method)
        print(data)

if __name__ == '__main__':
    Main()


an example of the sender, method and data this will capture:
Code:
xbmc
VideoLibrary.OnUpdate
{"item":{"id":40,"type":"movie"},"playcount":1}
Thanks so much for this but I've determined that I am going to need to use another context menu item button.   It has to do with differences in the list item objectID between when it displays in a playlist via a Kodi listitem vs. a full sync of the uPNP server with the Kodi database.  The objectIDs are different and Kodi has no way to determine that. 

I've inherited this code and realized they had created a context menu item called Details which was nothing more than the  function which already exists in the context menu as Info that calls XBMC.Action(Info).  So I am reusing / renaming it and changing the function of the menu items. 

Here's the code and it is working pretty well:

                    if playcount == 0:
                        li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'),            \
                        (addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30372),   \
                        'XBMC.RunScript(special://home/addons/plugin.video.mezzmo/resources/lib/playcount.py,       \
                        {},{}, {}, {}, {}, {}, {})'.format(mtitle, itemurl, season_text, episode_text, playcount,   \
                        album_text, pcdbfile)) ])
                    elif playcount > 0:
                        li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'),            \
                        (addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30373),   \
                        'XBMC.RunScript(special://home/addons/plugin.video.mezzmo/resources/lib/playcount.py,       \
                        {},{}, {}, {}, {}, {}, {})'.format(mtitle, itemurl, season_text, episode_text, playcount,   \
                        album_text, pcdbfile)) ])   

I've been reading through the documentation on the addContextMenuItems function and from what I can tell I can't just call a function in my plugin with it, is that correct ?  I'd like to do something maybe cleaner like:

import playcount

                    if playcount == 0:
                        li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'),            \
                        (addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30372),   \
                        'playcount.updateKodiPlaycount( mtitle, itemurl, season_text, episode_text, playcount,   \
                        album_text, pcdbfile)') ])
                    elif playcount > 0:
                        li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'),            \
                        (addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30373),   \
                         'playcount.updateKodiPlaycount( mtitle, itemurl, season_text, episode_text, playcount,   \
                        album_text, pcdbfile)') ])


where playcount.updateKodiPlaycount is the function which updates the database and the uPNP server.  The documentation seems to indicate I can only call a script like above and not another function within the plugin..  Am I missing something or I am reading it right and that is correct that I can't call a function already in my plugin ?
that is indeed correct, it needs to be a script.

when kodi runs a plugin, it expects it to return a directory listing... which is obviously not the case here.
(2020-08-31, 02:39)ronie Wrote: [ -> ]that is indeed correct, it needs to be a script.

when kodi runs a plugin, it expects it to return a directory listing... which is obviously not the case here.

Thank you so much for all of your help.  I have the new functionality fully working now.  At the risk of exceeding my question quota, I do have a question regarding when calling a script the way I am:

if playcount == 0:
                        li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'),            \
                        (addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30372),   \
                        'XBMC.RunScript(special://home/addons/plugin.video.mezzmo/resources/lib/playcount.py,       \
                        {},{}, {}, {}, {}, {}, {})'.format(mtitle, itemurl, season_text, episode_text, playcount,   \
                        album_text, pcdbfile)) ])
                    elif playcount > 0:
                        li.addContextMenuItems([ (addon.getLocalizedString(30347), 'Container.Refresh'),            \
                        (addon.getLocalizedString(30346), 'Action(ParentDir)'), (addon.getLocalizedString(30373),   \
                        'XBMC.RunScript(special://home/addons/plugin.video.mezzmo/resources/lib/playcount.py,       \
                        {},{}, {}, {}, {}, {}, {})'.format(mtitle, itemurl, season_text, episode_text, playcount,   \
                        album_text, pcdbfile)) ])   

I end up with errors in the Kodi log:

2020-09-01 04:26:34.721 T:15632 WARNING: CPythonInvoker(271): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.

This is happening in both versions of my plugin under Kodi 18 and 19.  From what I've read in the forums this is normal and there isn't a way to prevent these errors.  Is that correct ?  I believe I saw where one person called their plugin again with a different mode setting as a way around it.  Not sure I want to go that route.


Jeff
nope, that is far from being correct... and Kodi doesn't issue that warning in the log just for fun ;-)

Step 1. first, XBMC.RunScript() is deprecated, you can simply use RunScript()

Step 2. you'll need to pass your addon id to the RunScript() command, and not the path to a .py file (this is why you get that warning in the log)
RunScript(plugin.video.mezzmo,{},{}....

Step 3. since your addon is a plugin (and not a script), it shouldn't really be run it using the RunScript() command...
to fix that, add another extension point in your addon.xml, which points to the playcount.py file (which is basically a helper script)

xml:
<extension point="xbmc.python.pluginsource" library="default.py">
    <provides>video audio image</provides>
</extension>
<extension point="xbmc.python.library" library="resources/lib/playcount.py"/>
(2020-09-01, 22:36)ronie Wrote: [ -> ]nope, that is far from being correct... and Kodi doesn't issue that warning in the log just for fun ;-)

Step 1. first, XBMC.RunScript() is deprecated, you can simply use RunScript()

Step 2. you'll need to pass your addon id to the RunScript() command, and not the path to a .py file (this is why you get that warning in the log)
RunScript(plugin.video.mezzmo,{},{}....

Step 3. since your addon is a plugin (and not a script), it shouldn't really be run it using the RunScript() command...
to fix that, add another extension point in your addon.xml, which points to the playcount.py file (which is basically a helper script)

xml:
<extension point="xbmc.python.pluginsource" library="default.py">
    <provides>video audio image</provides>
</extension>
<extension point="xbmc.python.library" library="resources/lib/playcount.py"/>
Thanks for clarifying the cause of the error.  In debug I can see more and see what you are saying.  With regards to adding another extension point, if I already have multiple extension points how does Kodi know which extension point to execute when it calls the plugin from the context menu or does it run them all ?  I looked through the documentation and can't quite discern this. 

Here's  my current extension points:

  <extension point="xbmc.python.pluginsource"
               library="default.py">
        <provides>video audio image</provides>
  </extension>
 
  <extension point="xbmc.service" start="startup"
               library="service.py">
        <provides>executable</provides>
  </extension>
 
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <minversion>1</minversion>
    <summary lang="en">Browse and play local video, music and photo media files managed by Mezzmo Media Server.</summary>
    <description lang="en">Browse and play local video, music and photo media files managed by Mezzmo Media Server.</description>
  </extension>

 
Jeff
when you use the RunScript() command, kodi first checks if there's a script-type extension point defined in your addon.xml
(this can be xbmc.python.script or xbmc.python.library). if it finds it, it will use that.

if it can't find such an extension point, it will issue a warning in the log and fallback to the first extension point that's defined in your addon.xml file.
Pages: 1 2