Python jsonrpc add track to playlist from file

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
bossanova808 Offline
Donor
Posts: 1,529
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #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!!
find quote
Mizaki Offline
Fan
Posts: 662
Joined: Apr 2011
Reputation: 12
Post: #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: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
find quote
bossanova808 Offline
Donor
Posts: 1,529
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #3
Now that, my friend, is some awesome help, right there.

Thanks!!
find quote
Mizaki Offline
Fan
Posts: 662
Joined: Apr 2011
Reputation: 12
Post: #4
Most welcome.

I've lost hours myself on trying to get syntax right. Much searching and swearing normally ensues Wink

[Image: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
find quote
bossanova808 Offline
Donor
Posts: 1,529
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #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 maybeConfused I don't know much about json yet...!
find quote
Mizaki Offline
Fan
Posts: 662
Joined: Apr 2011
Reputation: 12
Post: #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: watched-clearlogo.jpg]
AWXi - Ajax web interface. Wiki
find quote
giftie Online
Skilled Python Coder
Posts: 2,036
Joined: Mar 2010
Reputation: 35
Post: #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.

[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


find quote
bossanova808 Offline
Donor
Posts: 1,529
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #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 \\
find quote
bossanova808 Offline
Donor
Posts: 1,529
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #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...
find quote
bossanova808 Offline
Donor
Posts: 1,529
Joined: Sep 2009
Reputation: 20
Location: Melbourne, Australia
Post: #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.
find quote
Post Reply