[RELEASE] xbmcswift2 - plugin framework
#1
Not really a release since it's been out for while Smile Just posting it here for the first time though.

xbmcswift2 is a mini framework to enable rapid development of XBMC plugins. It enables you to run your plugins on the command line (in a limited fashion) for testing and handles most of the url routing so you don't have to deal with query strings and parameters. I think it also had a tendency to force authors to write clean and well seperated code, which makes debugging and maintenance much easier in the long run.

It started as xbmcswift (no "2") awhile back and there were a few early adopters that found it in the repos Wink The project began as a way to abstract a lot of the boilerplate code that I found myself writing. Eventually, I wanted to make some changes that were backwards incompatible, so now the current version is "xbmcswift2". Check out the documentation for some example code. There is also a page in the docs which lists addons already using xbmcswift2, so you can take a look at their source.

Project page on github (issues, comments, etc): https://github.com/jbeluch/xbmcswift2
Documentation: http://www.xbmcswift.com/en/latest/index.html

(Or if you have xam installed, you can do xam depends script.module.xbmcswift2 to list addons which use xbmcswift2)

Also thanks to sphere, takoi and beenje for patches and suggestions.

Here's the My Zen TV addon from sphere which uses xbmcswift2:

Code:
from xbmcswift2 import Plugin
import resources.lib.scraper as scraper

__addon_id__ = 'plugin.video.myzen_tv'
__addon_name__ = 'Myzen.tv'

plugin = Plugin(__addon_name__, __addon_id__, __file__)


@plugin.route('/')
def show_free_videos():
    videos = scraper.get_free_videos()
    for video in videos:
        video['path'] = plugin.url_for('play_video', path=video['path'])
        video['is_playable'] = True
    return plugin.finish(videos)


@plugin.route('/play/<path>')
def play_video(path):
    rtmp_params = scraper.get_rtmp_params(path)

    def xbmc_output(rtmp_params):
        return (
            '%(rtmp_url)s '
            'app=%(app)s '
            'swfUrl=%(swf_url)s '
            'playpath=%(playpath)s '
        ) % rtmp_params

    playback_url = xbmc_output(rtmp_params)
    return plugin.set_resolved_url(playback_url)

if __name__ == '__main__':
    try:
        plugin.run()
    except scraper.NetworkError:
        log('NetworkError')
Reply
#2
Many nice features and abstractions that give clean and readable code.
Makes it very easy to write a new plugin.
I really recommend it :-)

Nice work!
xbmc.log: /Users/<username>/Library/Logs/xbmc.log
Always read the XBMC online-manual, FAQ and search the forum before posting.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#3
Sweet, will try it
Reply
#4
thanks for the framework! i just created my first plugin using this!!
Reply
#5
I am already wanting to enhance and release 2nd version of my plugin.

I have some questions about part of xbmcswift2

#1 for items=[{.... 'info': { 'plot'..... is there a way to add aired date and other information and also allow the mediainfo or mediainfo2 viewing when listing the videos ?

#2 the api that I am working with has api's to pull subtitles in various languages. does xbmcswift2 have any api's for subtitles

tia
Reply
#6
(2012-12-10, 02:21)jlim0930 Wrote: thanks for the framework! i just created my first plugin using this!!

Congrats on your first plugin. Be careful, it's addicting Wink Is your plugin in the repo?

(2012-12-10, 03:05)jlim0930 Wrote: I have some questions about part of xbmcswift2

#1 for items=[{.... 'info': { 'plot'..... is there a way to add aired date and other information and also allow the mediainfo or mediainfo2 viewing when listing the videos ?

#2 the api that I am working with has api's to pull subtitles in various languages. does xbmcswift2 have any api's for subtitles

1) If I understand you correctly, you want to change the view mode. The built-in function Container.SetViewMode(id) handles this, however the id parameter can be skin specific. xbmcswift2 does offer a helper if you know the id, you can add {'view_mode': 500} to your item dictionary. See http://www.xbmcswift.com/en/latest/api.h...gin.finish for more info.

2) xbmcswift2 does not currently have an api for subtitles. See http://forum.xbmc.org/showthread.php?tid=146403 for a possible solution. Although, now that you are the second person to ask, perhaps I'll add it to the TODO list.
Reply
#7
I tried installing this on Windows 7, python 2.7 and all the required dependencies and it doesn't work for me. Is this compatible with windows? if not, any plans on implementing windows support? Or Windows with MinGW / Cygwin?
Image
Reply
#8
Are there any examples how to use ListItem?
(I am going to replace existing context menu with my own one)
Reply
#9
(2013-01-05, 07:01)akuiraz Wrote: I tried installing this on Windows 7, python 2.7 and all the required dependencies and it doesn't work for me. Is this compatible with windows? if not, any plans on implementing windows support? Or Windows with MinGW / Cygwin?

Hmm, haven't specifically tested on windows. Will try to get a VM up and test it out over the next few days.
(2013-01-06, 15:59)void0 Wrote: Are there any examples how to use ListItem?
(I am going to replace existing context menu with my own one)

Typically you don't have to deal with ListItem objects directly, you just deal with dicts. So a playable item looks like:

Code:
item = {
    'label': 'My Video',
    'path': 'http://example.com/video.mp4',
    'is_playable': True
}

To change the context menu, you can also include a key 'context_menu'. I need to update the context menu documentation online, but for now, see one of sphere's addons to see how the context menu can be used. Also, here is a list of other addons which use xbmcswift2 to look for more examples. Let me know if you need more info.
Reply
#10
Regarding context menus: how can I remove existing menu items?
For example in this code I am adding new menu item "Show account info", but how can I remove default ones?

Code:
def _get_context_menu():
    menu = [(
        "Show account info",
        "XBMC.RunPlugin({0})".format(plugin.url_for("show_account_info")),
    )]
    return menu

def _add_videos(media):
    for item in media:
        yield {"label": item["Name"],
               "path": _get_streaming_url(item["Streams"]),
               "thumbnail": _get_preview_url(item["Previews"]),
               "info": {
                   "title": "test title",
                   "duration": str(item["Metadata"]["Duration"]),
                   "date": str(item["ModifiedDate"])
               },
               "context_menu": _get_context_menu(),
               "is_playable": True}
Reply
#11
You can't
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#12
(2013-01-06, 23:16)Martijn Wrote: You can't
You can (without xbmcswift).
See "replaceItems" keyword in addContextMenuItems():
Code:
addContextMenuItems([(label, action,)*], replaceItems) -- Adds item(s) to the context menu for media lists.

items               : list - [(label, action,)*] A list of tuples consisting of label and action pairs.
  - label           : string or unicode - item's label.
  - action          : string or unicode - any built-in function to perform.
replaceItems        : [opt] bool - True=only your items will show/False=your items will be added to context menu(Default).
But this isn't implemented in the last released xbmcswift2 yet. See here.

regards,
sphere
My GitHub. My Add-ons:
Image
Reply
#13
(2013-01-06, 23:16)Martijn Wrote: You can't

That's bad, because some default menu items won't work properly in my case, e.g. adding video file to favorites doesn't make sense, because url to video file contains also ticket that expires in 30 min if I don't use it.
Reply
#14
(2013-01-06, 23:39)sphere Wrote: You can (without xbmcswift).
See "replaceItems" keyword in addContextMenuItems():

Thanks, I will try this out
Reply
#15
BTW, I need to cache login objects, do you know how it is possible?
Reply

Logout Mark Read Team Forum Stats Members Help
[RELEASE] xbmcswift2 - plugin framework2