Loading Smart Playlists via Python API
#1
Question 
Hi All,

I stumbled accross a problem that I hope some-one could assist me with.

If I have a smart playlist (SmartTest1.xsp) that works OK in XBMC and is very simple, so something like:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="songs">
    <name>SmartTest1</name>
    <match>all</match>
    <rule field="album" operator="contains">
        <value>Now</value>
    </rule>
</smartplaylist>

And then I try to load this in python using:

Code:
xbmcPlaylist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
xbmcPlaylist.load(playlistFile)

I get the error:

Code:
EXCEPTION: Not a valid playlist

This works OK for playlists in the m3u format.

Looking at the API docs it states:

Code:
load(filename) -- Load a playlist.
    clear current playlist and copy items from the file to this Playlist
    filename can be like .pls or .m3u ...
    returns False if unable to load playlist, True otherwise.

I wasn't quite sure what the "..." implies - I had assumed that this means all playlist that XBMC supports - is this not the case? Am I missing a step somewhere?

Thanks

Rob
Reply
#2
I hit that issue as well. I dont think playlist means the same thing anymore. I think it only refers to the active playlist (the one currently loaded and ready to play).

Anyway, I used the JSON API to clear the existing playlist, get the contents of the playlist file, and then load each item into the 'active' playlist ("id" = 1) before playing.

placeholder is my path/playlist

Code:
'{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": { "directory": %s, "media": "video"  },  "id": 1}' % (placeholder)
Reply
#3
Hi Karnagious,

Thanks for the suggestion, I have tried the following as suggested:

Code:
json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": { "directory": "%s", "media": "music" },  "id": 1}' % (playlistFile))

However I am getting a parse error:

Code:
DEBUG: JSONRPC: Incoming request: {"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": { "directory": "C:\XBMC\XBMC-12.2\portable_data\userdata\playlists\music\SmartTest1.xsp", "media": "music" },  "id": 1}

ERROR: JSONRPC: Failed to parse '{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": { "directory": "C:\XBMC\XBMC-12.2\portable_data\userdata\playlists\music\SmartTest1.xsp", "media": "music" },  "id": 1}'

DEBUG: {u'jsonrpc': u'2.0', u'id': None, u'error': {u'message': u'Parse error.', u'code': -32700}}

Any ideas?

Thank you for your help!

Rob
Reply
#4
My playlist name came from what was returns with this query:

{"jsonrpc": "2.0", "method": "Files.GetDirectory", "params": {"directory": "special://profile/playlists/nusic/", "media": "music"}, "id": 1}


Just try the playlist name instead of the path. I was going by offline code, so I probably had that wrong.
Reply
#5
That's brilliant!

Works with the special:// path (the filename on it's own doesn't appear to work)

Should give me what I am after.

Thank you

Rob
Reply

Logout Mark Read Team Forum Stats Members Help
Loading Smart Playlists via Python API0