XBMC python library
#1
Hi.

I could not find an existing one, so I developped a library which allow xbmc remote control in python over http json API.
It should supports all commands listed here : http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v6

It's installable throuht pip :
Code:
# pip install xbmc

And sources are located on github : https://github.com/jcsaaddupuy/python-xbmc , released under WTFPL licence.

Usages examples :
Code:
# Navigate throught windows
xbmc.GUI.ActivateWindow({"window":"home"})
xbmc.GUI.ActivateWindow({"window":"weather"})

Code:
# Show some notifiations :
xbmc.GUI.ShowNotification({"title":"Title", "message":"Hello notif"})



Code:
#Library interaction
xbmc.VideoLibrary.Scan()
xbmc.VideoLibrary.Clean()


See readme for more examples.

I hope someone will find it usefull.


Edit: added some usage examples
Reply
#2
Won't your library namespace clash with the standard xbmc python stuff:
http://mirrors.xbmc.org/docs/python-docs/

Might want to call it xbmc-json or something?

A nicer python interface to the json is not a bad thing, though, I guess, although a lot of it is accessible more directly through the standard python library, no?
Addons I wrote &/or maintain:
OzWeather (Australian BOM weather) | Check Previous Episode | Playback Resumer | Unpause Jumpback | XSqueezeDisplay | (Legacy - XSqueeze & XZen)
Sorry, no help w/out a *full debug log*.
Reply
#3
Hi.
Unless I'm mistaken, the python module you pointed is meant to be used inside the XBMC environement, like for scripts and add-ons executed by XBMC itself.

The lib I developped does not aim to replace it in any ways, it is meant to be used as a client library (let's say, from your house automation or any kind of script)

Of course, everything is accessible with standard python libs (it's just json over http after all), the lib just wrap calls to XBMC object/methods in a more object programming way.
Reply
#4
No you're right obvioussly, but my point was it's often easy to use the json stuff inside an addon as well - indeed sometimes it's the only way. You can do it currently but your way is nice and neat... so it would be better to namespace it in a compatible way so it can be used in both contexts.
Addons I wrote &/or maintain:
OzWeather (Australian BOM weather) | Check Previous Episode | Playback Resumer | Unpause Jumpback | XSqueezeDisplay | (Legacy - XSqueeze & XZen)
Sorry, no help w/out a *full debug log*.
Reply
#5
Hi.

I did not even thought to use it in a script or an add-on, I bellieved that modules provided by XBMC was self suffisants.

You are totally right.
I will rename the module, "xmbc-json" seems to be a good name Smile
Reply
#6
Python module has been renamed to xbmcjson
Package has been renamed to xbmc-json

Sources are still in the same repo, named python-xbmc.

Please report issues on github!
Reply
#7
Ha. I'd just started working on exactly the same idea. Looks like you beat me to it...
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#8
I should add that what I'm working on was nowhere near as neat or as clever as this!

However, I was trying to simplify the process so that the user wouldn't need to know the JSON params formatting. e.g. to send a notification my class would work like this:
Code:
xbmcjson.ShowNotification("Title", "Hello nofif")
rather than:
Code:
xbmc.GUI.ShowNotification({"title":"Title", "message":"Hello notif"})

This does make the my code less flexible than j2cx's, but it may also help people build some basic functions into their programs.

I'll keep going on the code, if only for my own learning experience!

el_P
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#9
Hi el_Paraguayo!
For the parameters, I did it too (by playing with **kwargs), but it seems that I've broken it at a moment.
It's clear that it's nicer Smile
Do you have the code of your lib online like a github or something? I woul like to keep an eye on it if you are ok.

I'm also writing a command line client, based on my previous library (https://github.com/jcsaaddupuy/xbmc-client)
It's in an very early development stage (like I started it today) but the base is here.
Reply
#10
I haven't put the code on github yet as it's also still in early development. However, I'll happily upload it later on.

The trouble I've got at the moment is I don't have much spare time.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#11
This is as far as I've got so far: https://github.com/elParaguayo/SimpleXBMCJSON

Plenty more to do I think... I may also "borrow" your authentication code!
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#12
Feel free to borrow whatever you need!

You may also want to look at how I managed JSON RPC methods arguments as python arguments using **kwargs (I fixed it after your previous remark). It's usefull to get a dict with name and values for each python parameters. It may not be appropriate for each usecasse (like for your method AudioGetAlbums where parameters are complex)

I'll keep in mind the AutoVivification stuff, that's a simple but great stuff Smile
Reply
#13
Thanks - still learning python slowly - never tried the **kwargs before but I'll look into it.

Autovivification is a very useful piece of code I found on StackOverflow that just stops you getting a key error when you try to created nested dicts without creating each level first.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#14
Still working on this slowly.

Am looking to incorporate parameters such as filter etc. This is currently working as follows:
Code:
f = Filter.FILTER("title", "contains", "Star")
print simplexbmcjson.GetMovies(myfilter=f)

Also allows for complex filters:
Code:
f = Filter.OR([Filter.FILTER("title", "contains", "Star"), Filter.FILTER("title", "contains", "Alien")])
print simplexbmcjson.GetMovies(myfilter=f)

Seems to be working ok.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#15
jc2x,

I tried your code with authentication and kept getting a 401 error. I forked your code and changed that part to use some code that was posted elsewhere on the forum.

I've also added some additional code that, when you initialise the object for the first time it pings xbmc and sets a value for whether it received a response or not. This means you can do something like this:
Code:
from xbmcjson import XBMC
client = XBMC("http://192.168.0.1:8080/jsonrpc", "xbmcusername", "password")

if client:
  client.Player.GetActivePlayers()

I have submitted a pull request on github if you want to look at the code.

el_P
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply

Logout Mark Read Team Forum Stats Members Help
XBMC python library0