Python jsonrpc add track to playlist from file
#1
Hi

in my addon I want to add an a dummy track to the audio playlist (and set the mode to repeat) as a workaround for the fact that xbmc addon windows don't fully absorb events and pass them on to the underlying player. This means my add on (which controls an external audio player) - raises annoying 'Playlist can't find next item to play' messages - I'd rather I add a dummy track with my add on name 'Xsqueeze Now Playing.mp3' and put the playlist to repeat so that it gives a better message/no message.

So, in short, I need to, in Python - add a track to the music playlist, and set the playlist to repeat.

I am at this but it doesn't parse:

Code:
result = xbmc.executeJSONRPC('{ "jsonrpc": "2.0", "method": "Playlist.Add", "id": 1, "params": {"Playlist.Item": "' + constants.DUMMYAUDIO + '"}}')
where constants.DUMMYAUDIO is the xbmc translated path to the file...

I think I am close...any ideas?

And on the second front - can the playlist be programmatically be set to repeat?

I guess I need to clear it first as well, thinking about it - and maybe clear it on exit as well.

Help appreciated - the jsonrpc docks are not replete with examples!!
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
#2
Hi,

Hopefully these should help.

Here is an example:
Code:
{"jsonrpc": "2.0", "method": "Playlist.Add", "params": { "item": {"file": "pathandfilename"}, "playlistid": 0 }, "id": 1}
Repeat:
Code:
{"jsonrpc": "2.0", "method": "Player.Repeat", "params": { "playerid": 0, "state": "all" }, "id": 1}
Clear audio playlist:
Code:
{"jsonrpc": "2.0", "method": "Playlist.Clear", "params": { "playlistid": 0 }, "id": 1}

Also, this I find most useful for looking at a single call:
Code:
{ "jsonrpc": "2.0", "method": "JSONRPC.Introspect", "params": { "filter": { "id": "AudioLibrary.GetSongs", "type": "method" } }, "id": 1 }

The first two you should be able to batch by placing them in square brackets I believe but I've not tried it yet myself.

If you have a search over the JSONRPC thread you might find some examples. Or you can check out lib.xbmc.js from AWXi. I have most calls in there. Smile
Image
AWXi - Ajax web interface. Wiki
Reply
#3
Now that, my friend, is some awesome help, right there.

Thanks!!
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
#4
Most welcome.

I've lost hours myself on trying to get syntax right. Much searching and swearing normally ensues Wink
Image
AWXi - Ajax web interface. Wiki
Reply
#5
I have tried this btu I think maybe I need to escape the filename or similar...I'm on windows for developing anwya, and I passed
C:\directory\file.mp3

...this is from Python. I guess I need to do something to this as I think maybe the slashes or whatever are annoying it. If I pass 'blah' it accepts it but tells me it's invalid, so I am pretty sure...do I need url_encode it maybeHuh I don't know much about json yet...!
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
#6
Probably need to escape the slashes. IIRC Windows accepts *nix slashes so if you use those it should work on *nix and Windows. So you could use the relative path in your addon etc.

This is with javascript but the regex should be the same.
Code:
string.replace(/\\/g, "\\\\")
Image
AWXi - Ajax web interface. Wiki
Reply
#7
As Mizaki has said, you will need to escape the slashes(C:\directory\file.mp3 becomes C:\\directory\\file.mp3) but you can try just using forward slashes which is valid for python(maybe XBMC) so the path would be C:/directory/file.mp3.
Reply
#8
Yep, thanks, jut got it to work about a minute ago -

Code:
DUMMYAUDIO = xbmc.translatePath(os.path.join( AUDIO_PATH, "XSqueeze.mp3")).replace( "\\", "/" )

...the replace is required and makes \\ -> / - which work fine on Windows anyway, so one wonders why pythone bothers with \\
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
#9
Is there a list anywhere of what playlist ids are what? I have tried 0 and 1, they don't seem to work. The json reutrns OK but if I activate either the video playlist window or the musicplaylisteditor (something I've never found before!) - the current playlist is always blank...
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
#10
Scratch that, they are on the music playlist. But I strill get my plalsit error so I guess addon windows default to the video playlist, and that probably uisn't working as I am adding an MP3...will try a dummy video instead.
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
#11
GRRRR

Ok, I have valid, playable videos & audios on the playlists now but no matter what when me addon receives ACTION_NEXT_ITEM it errors with can't find next item on playlist to play error (even though I grab that event and pass on to my external player, it's the event fall through that gives this error). If I manually go to the video playlist I can skip between the elements and it plays each one without error.

What playlist do custom WindowXMLs addons refer to then?? Is there some some of generic playlist I am missing??
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
#12
It aint pictures either !!

0 = audio
1 = video
2 = pictures

..I just found that stupid 'show' button in the docs - stupid me!
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

Logout Mark Read Team Forum Stats Members Help
Python jsonrpc add track to playlist from file0