How can I get the name of current playlist ?
#1
My intention is to write a script that would save the music playlist selected, current track and seek time when Kodi exits and resume playback from where left off when Kodi is lauched once again. Inability to fetch the name of currently selected playlist has proven to be a show stopper for me.

I have spent hours and hours trying to find a way to get the name of the current playlist, there just don't seem to be an answer. In the process I learned that this was possible with HTTP API, which is deprecated now. I also searched for a way to resume playback, I can see a lot of people asking and trying for it but none have been successful ?! I have explored the venues of JSON RPC, built-in functions, commands etc. but to no avail, unless I missed something. The whole process has been quite frustrating not to mention the hours wasted to get silly something done !

Can any one help shed some light on this, please ? If this is the wrong forum could you please suggest a right one ? I wasn't sure if I should post this on the developer's forum so, I thought I'd try here first.

Thanks.
Reply
#2
Bump ?
Reply
#3
I think you can use the JSON-RPC API to first get the active player (Player.GetActivePlayers), then with that player you can get the properties (Player.GetProperties), and one of the properties is the playlist ID (Player.Property.Value), then with that you can get the playlist Name (Playlist.GetProperties), if you need it.

One of the other player properties is Playlist Position (Player.GetProperties) and another is the Player Position Percentage.

Then there is the XBMC Resume addon.
Reply
#4
Thanks a lot for the response Karnagious.

I had already explored the possibility of obtaining playlist name through JSON and had tried the methods you listed. Apparently Playlist.GetProperties returns a Playlist.Property.Name, the name of which is misleading. It actually supports an enum of two members - "size" and "type".

Unfortunately playlistid returned by Player.GetProperties is always "0" regardless of which playlist is current and thus cannot be used.

What I learned through googling is that it was possible with HTTP API which was deprecated and not supported anymore.

The "XBMC Resume" seemingly is outdated and extinct as the download links are dead. I found a few others which are either outdated or do not save and resume playlist.

I even tried creating a service addon which would monitor Kodi and save the name of the playlist that was playing before Kodi shuts down. I gave up as I couldn't find any built in functions or the action id that would get me the playlist name.

Seems like I have hit a dead end. It is shocking as, this is something very much possible with only a few lines of code and yet it was never felt as a necessity.

I guess I will have to settle with hitting buttons on my remote to manually load and play the playlist I need.

Any other ideas ?
Reply
#5
Yeah, I think playlist id from Player.GetProperties is going to be 0 for audio or 1 for video.

You could simply get all the items in the current playlist, and store those. It doesnt really matter to the user whether the song list is loaded from a playlist or is loaded manually by your addon when Kodi restarts.

But if you wanted the playlist name then you could use the list from above to find it.

First, get all the playlists from the special://profile/playlists/music/ folder.
Next, use Files.GetDirectory to get the contents of each of them in turn.
Get the songid's from the playlist add it to a set, and check if that set matches the "currently playing" one from above.

If it doesn't, move on to the next playlist file.

If none of them match, then the playlist might be one the user constructed manually and should be stored anyway.
Reply
#6
You and I think alike, Karnagious !

I actually thought of that, that is use Playlist.GetItems on all playlists and unique sort the paths and cache them in a file and everytime shutdown.py is called, call Playlist.GetItems once again and unique sort the list and compare it with one of the previously cached lists and figure out which one is playing.

I actually have some playlists in which the same artist duplicated as I am creating playlists by genre and also by my favourite artists. So the above will take care of this but, will fall short if I add new playlists unless I run my script to recreate the cache.

Being mostly a C/C++ guy and with very limited python skills, this will take some effort which I will have to defer.

The developers should seriously consider adding this feature.

Thanks again.
Reply
#7
Did you know you can pass Files.GetDirectory a Playlist and it will return to you the contents?
Reply
#8
I am guessing that, you are suggesting to use Files.GetDirectory to get the list of files to use for the cache. Yes, I am aware of it, but I'd rather use the Agent Ransack to copy paste the directories list to create my cache. But then, I will have to use the Playlist.GetItems to get contents of the currently playing playlist as, using Files.GetDirectory requires knowing the name of the current playlist.

I was talking about the script that actually uses Playlist.GetItems and creates a unique and sorted list of directories and compare it against the cached lists. That is going to take a bit of effort which I will defer.
Reply
#9
Hi AlexBw,

I'm trying to do the exact same thing as you are (and experiencing the exact same issue, by the way...).
Just curious - did you by chance managed to make it work?
If so, could you please share the result?

Thanks in advance...
Reply
#10
Hi Jblook,

No, there was no way I could get it done. I filed a feature request for playback resume here. If you want you could add yourself to the request.

I did manage to get what i want after much toiling. For that I had to assign keyboard shortcuts ctrl+(0-9) for my playlists and load the playlist I want with the assigned keyboard shortcut. That way I would know which playlist is loaded and thus save the playlist info to a file and resume later when that playlist gets loaded the next time.

I could elaborate a bit more if you need.
Reply

Logout Mark Read Team Forum Stats Members Help
How can I get the name of current playlist ?0