Work in Progress - Context Item Addons

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Fice Offline
Member
Posts: 70
Joined: Jan 2010
Reputation: 3
Post: #1
Hi there,

I'm currently working on a new addon extension point called Context Item Addons.
The goal of this is to add context items to list items not populated from addons. (Like asked for in here)

Pull Request
My Development Branch

I wanted the addon author to have a lot of flexibility to specify when the context item should be visible so I decided to use the already implemented Visibility Expressions for Skins.
NOTE: aditionally to everything you can do in skins, you can also use "addon.hasSetting(settingname)" which works on boolean addon settings. I plan to also add support for non boolean settings.

This is how it would look like in your addon.xml
Code:
<extension point="xbmc.context" library="addon.py" visible="{VISIBILITY_EXPRESSION}">
      <label>The label to display</label>
      <label lang="de">Localized german label</label>
  </extension>

Check it out
This is already working. There are mostly some TODO's left concerning special cases (what to do when a context item addon gets automatically updated when it is currently displayed... and stuff like that) but basically it should be save (as safe as nightlies can be Wink ) to check it out and test it.
If you're on a mac your lucky. Just checkout my branch and compile or if you want I can upload a dmg.
if you're on any other os, you can still checkout my branch but you probably have add the following files to your project/build process:
  • xbmc/GUIContextMenuManager.cpp
  • xbmc/GUIContextMenuManager.h
  • xbmc/IGUIContextItem.cpp
  • xbmc/IGUIContextItem.h
  • xbmc/addons/ContextItemAddon.cpp
  • xbmc/addons/ContextItemAddon.h
If you have done so, please feel free to submit a pull request...


What I want to know from you as an addon developer

- First of all I want to know your ideas for context item addons and especially when those should be visible. I'm pretty sure that my current PR is pretty limited as you cannot actually add a context item just for e.g. Movies because i haven seen a way to query that information from the visibility expression. So what I want to find out is what new Expression should be exposed so you guys can actually usefull context item addons.

- You can disable the build-in context items for content addons. If you have done this, could you explain why you disabled them? I want to figure out when context item addons should be available to list items populate by addons.

- If you're a skinner / or have more knowledge of the visibility expressions than I do, please let me know If the list of new proposed expression at the end of this thread is in fact already possible...

- And of course Bugs...
Here is a list of Bugs i know about:
  • In some Views the context addon items are added in the middle. My goal is that context item addons should always be at the bottom, while the core ones are at the top. One way to fix it would be a lot of code duplication... should be easy but I'm looking for a more elegant way, so please just ignore that for now Wink

Some examples I thought of

Right now there are a lot of scripts floating around that need special skin support (Actors Biography, Home Theatre Experience, All those "Download additional metadata" addons).
For the home Theatre Experience we need to find out if the current item is a movie.
For the actors biography we need to find out if the current item is a actors node.
For the cd-art downloader script we need to know if the current item is a album.
That why I think it is reasonable to add a new visibility condition like ListItem.IsType(season) that would return true or false. (Seems related but haven't read it yet)
Another Idea would be "Ripd DVD/BluRay" Context Item addons. This one should only be visible on DVD/BluRay drives...


New Visibility Expressions to Expose
I will try to maintain a list of what is needed to make your suggested addons work...
  • Add possibility to check of a strng (or label) matches a regex patter. Useful to check if a items path comes from a specific website (regardles of the addon that provides the item). Code Example:
    Code:
    visibility="matchesRegex(listitem.path, {REG_EX})"
(This post was last modified: 2012-11-08 20:32 by Fice.)
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 802
Joined: Oct 2010
Reputation: 16
Post: #2
Found this on my way to respond to your github comment =)
Re: My reason for asking for regex based visibility expressions. In android, you have intent filters which basically try to match uri's being called internally. When an action is requested by the user, it's done so through a uri called an intent. All apps have a list of intent filters. When the user requests an action, all apps with an intent filter that matches the currently-being-called uri are presented in a list so the user can then choose which capable app they want to handle the action.

To apply this concept to Xbmc, let's say I have an addon which posts YouTube videos to Facebook. I could set my context menu visibility regex to match list items which contain YouTube links. Then, no matter which addon I'm using, if it lists a piece of YouTube content, I can post it to Facebook using my addon from the context menu.

Hope that all makes sense
find quote
Fice Offline
Member
Posts: 70
Joined: Jan 2010
Reputation: 3
Post: #3
perhaps we could achieve this by exposing some regex functionality in the visibility expressions... like
Code:
visibility="matchesRegex(listitem.path, {REG_EX})"
That way we can have your regex based style while also having additional control.

I think i remember it is possible to test a string if it beginsWith or EndWith a string... perhabs this would already be enough for your use case?

Why do I think we should have additional control:
What if you want to add a context item just to the favourites dialog? It is not based on the URL of the items. Right now you can do
Code:
visibility="Window.IsActive(window)"
If you go just by the url is a "*.avi" file a movie or a tv episode?

One problem I have right now is how to deal with context item addons on items populated by another addon. Right now addons can disable the default xbmc context items and with my PR this also disables all context item addons. Thats why I want to know the reasons why someone would disable them and how we should deal with this situation.
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 802
Joined: Oct 2010
Reputation: 16
Post: #4
yes, I definitely meant this as an additional, not a replacement.
Begins with and ends with alone don't quite cover it as there's no way to know where in the list item url the addon will place the YouTube url you're looking for
find quote
giftie Offline
Skilled Python Coder
Posts: 2,330
Joined: Mar 2010
Reputation: 53
Location: Calgary, Alberta
Post: #5
(2012-11-08 18:12)Fice Wrote:  Some examples I thought of

Right now there are a lot of scripts floating around that need special skin support (Actors Biography, Home Theatre Experience, All those "Download additional metadata" addons).
For the home Theatre Experience we need to find out if the current item is a movie.
For the actors biography we need to find out if the current item is a actors node.
For the cd-art downloader script we need to know if the current item is a album.
That why I think it is reasonable to add a new visibility condition like ListItem.IsType(season) that would return true or false. (Seems related but haven't read it yet)
Another Idea would be "Ripd DVD/BluRay" Context Item addons. This one should only be visible on DVD/BluRay drives...
The 'Container.Content(parameter) ' Boolean Condition would be usable for these instances(except for DVD/BluRay)

So if I was to use this for Cinema Experience, I would need to have my addon.xml file like this:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.cinema.experience" name="Cinema Experience" version="2.0.57" provider-name="nuka1195-giftie-ackbarr">
    <requires>
        <import addon="xbmc.python" version="2.0"/>
    </requires>
    <extension point="xbmc.python.script" library="addon.py"/>
    <extension point="xbmc.context" library="play.py" visible="Container.Content(movies)"
        <label>Play</label>
    </extension>
    <extension point="xbmc.addon.metadata">
        <platform>all</platform>
        <summary>Re-create a full movie theater experience.</summary>
        <disclaimer>This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License *see license.txt</disclaimer>
        <description>Play trailers, slideshows, intro videos, outro videos: To re-create a movie theater experience in the comfort of your home.</description>
        <description lang="es">Reproduce Avances, presentaciones, videos de intro, videos de outro: Para recrear una experiencia como si estuvieses en una sala de Cine en la comodidad de tu casa.</description>
    </extension>
</addon>
Or do I need to drop the original extension point, which would not be a problem, as it would remove it from the Programs screen where it has no use.

Would it also be possible to have two context menu items in one addon.xml file? For example:
Code:
<extension point="xbmc.context" library="play.py" visible="Container.Content(movies)"
        <label>Play</label>
    </extension>
        <extension point="xbmc.context" library="queue.py" visible="Container.Content(movies)"
        <label>Queue</label>
    </extension>

Also would it possible to implement the use of localized strings for label? For example, to use localization in an add-on's skin you would use the following:
Code:
<label>$ADDON[script.cdartmanager 32121]</label>
This pulls the string with the id of 32121 from the add-on's Language files.

[Image: e4f63e45ba34fe4695b3bb08eb2499d8e4ee484e...4c076g.jpg]
For troubleshooting and bug reporting please make sure you read this first you can also use XBMC Log Uploader Script.
Cinema Experience
Cinema Experience Wiki
cdART Manager
fanart.tv


(This post was last modified: 2012-11-09 03:00 by giftie.)
find quote
Fice Offline
Member
Posts: 70
Joined: Jan 2010
Reputation: 3
Post: #6
Quote:The 'Container.Content(parameter) ' Boolean Condition would be usable for these instances(except for DVD/BluRay)
Yes and no. As i understand it, container.content returns what the majority of the content is. so Container.content(pictures) would return true if you open the context menu in the picture section, even if you have currently selected a home video.
I don't know what the plans are with the new system to add you own sections in your library and if it is planned that you can mix movies and tv-shows, but then would be a item.content() thingie useful.

Quote:Or do I need to drop the original extension point, which would not be a problem, as it would remove it from the Programs screen where it has no use.
I haven't tested it with several extension points but it should work either way. (Btw. my plan was to try it on your Cinema Experience Script this weekend).

Quote:Would it also be possible to have two context menu items in one addon.xml file?
Unfortunately not. This is not by design but sth. the current addon handling of xbmc prevents. You cannot have two of the same extension points in one addon.

Quote:Also would it possible to implement the use of localized strings for label?
I'm just using the same functions that were already implemented for the other translatable strings in the addons.xml. I haven't actually looked at the implementation but I guess it is not possible. When starting to implement this i actually wanted to use sth like:
Code:
<extension point="xbmc.context" library="play.py" label="{STRING_OR_ID}">

but decided against it due to consistency, but I'm ok with changing it.

Btw: As of right now, the .py script called by my PR will not get any parameters. I guess it would be a reasonable idea to actually pass the selected item?
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 802
Joined: Oct 2010
Reputation: 16
Post: #7
(2012-11-09 10:45)Fice Wrote:  
Quote:Would it also be possible to have two context menu items in one addon.xml file?
Unfortunately not. This is not by design but sth. the current addon handling of xbmc prevents. You cannot have two of the same extension points in one addon.

Quote:Also would it possible to implement the use of localized strings for label?
I'm just using the same functions that were already implemented for the other translatable strings in the addons.xml. I haven't actually looked at the implementation but I guess it is not possible. When starting to implement this i actually wanted to use sth like:
Code:
<extension point="xbmc.context" library="play.py" label="{STRING_OR_ID}">

but decided against it due to consistency, but I'm ok with changing it.

Btw: As of right now, the .py script called by my PR will not get any parameters. I guess it would be a reasonable idea to actually pass the selected item?

If the python script could receive a reference to the list item, the script could decide whether or not to add certain items based on the list item's url. That would alleviate the need for having regex support in the PR, although it would just be moved into python (and thus it would be faster if done in C, but only noticeably so in large lists)

This brings up an interesting thought though. How would this handle changing list item properties? Some addons create list items, then go back and back-fill list item properties such as artwork and etc (so that the list is displayed quickly, but the slow-to-aquire metadata is added as it's available)
find quote
Fice Offline
Member
Posts: 70
Joined: Jan 2010
Reputation: 3
Post: #8
I didn't mean to pass the list item to the python script in order to determine visibility (as i think it would take way too long to load/parse/execute several python scripts just for that and the context menu should definitely be fast and responsive).
I just meant when the user selected a context item and hit enter, that the plugin should then get the ListItem. Because it feels like it can take a second or 2 until python scripts actually start running. So imagine the following use case:
You open the context item on the 5th list item.
Select the "Queue on upnp client" context item.
And directly after the context menu closes, you go ahead to the 7th list item to also queue this one.
Now if the python scripts starts delayed (again, the loading/parsing/thread creation takes time) and would query for the selected item now, it would get the wrong list item.

I see two solutions:
a) don't close the context item until after the context item script was executed (probably not the best solution when there are context item addons that are quite complex and take a lot of time to finish). This would probably require to execute a python script in the current thread instead of creating one. (I think some dev had this on his todo list, but i can't find the thread right now).
b) Keep asynchron but supply the context item addon with the list item.

Right now i think version b is the better solution (probably also easier).
I tried to implement that behaviour yesterday but ran into some complications. Currently it seem's that you can only pass strings as parameters to a python script. Will need to look closer how i can actually achieve what i want.

Second thing I was doing was trying to set up a Addon Repo for the context items (so i can actually test what happens when you update a context item while the context menu is open) and so i can move the test context items out of the PR becaus they should not go into core.
But I ran into some problems... does anyone of you have any experience with that?
here is the addon repo: https://github.com/Fice/xbmc_contextItems_repo
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 802
Joined: Oct 2010
Reputation: 16
Post: #9
Possibly, what's the problem? =)
find quote
Fice Offline
Member
Posts: 70
Joined: Jan 2010
Reputation: 3
Post: #10
I am not at my development machine right now, but i remember a message like "Addon has not the appropriate format" (or sth. along those lines.) when I tried to install the contextItem.repo.zip...
I also remember that the contextItem.repo.zip had an additional invisible file in it (this always happens when zipping sth. from the context menu of mac's finder... you have to use the command line to get rid of those)... I know I fixed it, but I'm not sure what the error message was after that.

Will report back tomorrow with some more information on this.

Btw: some automatisation that automatically recreates the addons.xml and the .md5 file after commiting to a addon repo would be nice... has anyone done some scripting in that regards?
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 802
Joined: Oct 2010
Reputation: 16
Post: #11
Yeah there's a python script around somewhere. Check to make sure that the top level of the directory is not the default.py and etc. The top level should just be a folder called script.video.something
find quote
Robotica Offline
Banned
Posts: 1,202
Joined: Aug 2010
Post: #12
Hi Fice,

Is this PR stalled since the context menu cleanup is not moving forward?
find quote
Fice Offline
Member
Posts: 70
Joined: Jan 2010
Reputation: 3
Post: #13
well, seems that way, but a xbmc dev can probably say more about that.

@xbmc devs: Is the context menu cleanup still in the decision phase? If not, is someone already working on it? Perhaps i could lend a hand (or two) Wink
find quote
Martijn Offline
Team-XBMC
Posts: 10,263
Joined: Jul 2011
Reputation: 154
Location: Dawn of time
Post: #14
(2013-04-11 20:41)Fice Wrote:  well, seems that way, but a xbmc dev can probably say more about that.

@xbmc devs: Is the context menu cleanup still in the decision phase? If not, is someone already working on it? Perhaps i could lend a hand (or two) ;)

We have other things to do atm but it should still be done.
find quote
Fice Offline
Member
Posts: 70
Joined: Jan 2010
Reputation: 3
Post: #15
I totally understand, my post was mostly meant as an inquiry if I can help in some way Wink
find quote
Post Reply