Using playlists to create an internet radio station with JSON-RPC?

Hi,
Newbie here.
I am exploring the ways to add an internet radio station. I did not find the UI from Iris. There is one in the MusicBox-webClient extension, and I noticed that it creates a .m3u8 file in the share/mopidy/m3u file.

I tried manually adding a .m3u8 file in the folder and it appears in the ‘Playlists’ menu of the Iris web page.

So I tried to use JSON-RPC core.playlists.create, and it does create a file in the folder but it is an empty file. Any idea how I should use the API ?

This is the request body:
{“jsonrpc”: “2.0”, “id”: 1, “method”: “core.playlists.create”, “params”: {“name”:“my station 1”, “uri_scheme”:“http://…aac”}}

Thanks in advance !
canal

Did you take a look at mopidy.core — Core API — Mopidy 3.3.0 documentation yet? You need to add tracks to your playlist object (that you obtained from either calling create or lookup) and then save that object.

Thanks, I was trying to use the tracklist call, but could not figure out the JSON-RPC format. I have tried these few but all failed - ‘expected a list of tracks…’ :

{“jsonrpc”: “2.0”, “id”: 1, “method”: “core.tracklist.add”, “params”: {“tracks”:{“uri”:“http://…aac”, “name”:“Class 95”}}}

{“jsonrpc”: “2.0”, “id”: 1, “method”: “core.tracklist.add”, “params”: {“tracks”:[{“uri”:“http://…aac”, “name”:“…”}]}}

{“jsonrpc”: “2.0”, “id”: 1, “method”: “core.tracklist.add”, “params”: {“tracks”:{“track”:{“uri”:“http://…aac”, “name”:“…”}}}}

What’s the correct body to add a track ?

Ok,. I manage to ‘add’ a track, the missing parameter is “__ model__”. so the correct call should be:
{“jsonrpc”: “2.0”, “id”: 1, “method”: “core.tracklist.add”, “params”: {“tracks”:[{“__ model__”:“Track”, “uri”:“http://…aac”, “name”:“…”}]}}

The result shows successful:
{
“jsonrpc”: “2.0”,
“id”: 1,
“result”: [
{
“__ model__”: “TlTrack”,
“tlid”: 2,
“track”: {
“__ model__”: “Track”,
“uri”: “http://…aac”,
“name”: “…”
}
}
]
}

But now the question is, I can not find the ‘adding track to a playlist’ API. so I try to use playlist.save, with an embedded Track:

{“jsonrpc”: “2.0”, “id”: 1, “method”: “core.playlists.save”, “params”: {“__ model__”:“Playlist”, “uri”:“m3u:883%20Jia%20FM.m3u8”, “tracks”:[{“__ model__”:“Track”, “uri”:“http://…aac”, “name”:“…”}]}}

The error is:
{
“jsonrpc”: “2.0”,
“id”: null,
“error”: {
“code”: -32600,
“message”: “Invalid Request”,
“data”: “‘params’, if given, must be an array or an object”
}
}

appreciate any help !

Use lookup to get a Mopidy Track object rather than hand-crafting your own.

And do the same for the playlist. lookup the playlist you created to get the Mopidy Playlist object. Manually insert the Track where you want. Then save that modified Playlist object.

I figure out the stupid mistake I made in the request, the correct format is:

{“jsonrpc”: “2.0”, “id”: 1, “method”: “core.playlists.save”, “params”: {“playlist”: {“__ model__”:“Playlist”, “uri”: “…”, “tracks”:[{“__ model__”:“Track”, “uri”:“…”, “name”:“…”}]}}}

Now returns success:
{
“jsonrpc”: “2.0”,
“id”: 1,
“result”: {
“__ model__”: “Playlist”,
“uri”: “…”,
“name”: “…”,
“tracks”: [
{
“__ model__”: “Track”,
“uri”: “…”,
“name”: “…”
}
],
“last_modified”: 1664243785473
}
}

However, the strange thing is, using Iris, I do not see the playlist with the new track. The newly added track is displayed on ‘Now Playing’ page…

Personally I do API calls to let Mopidy create and return the models so I know they are correct but whatever works for you.

When a playlist is saved, Mopidy fires a playlist_changed event for clients (like Iris) to listen for and update their views. I would expect Iris supports this but maybe you need to manually refresh it somehow? Or maybe Iris is caching the old version, it does a lot of its own caching for streaming backends. Perhaps @jaedb can advise.

thanks @kingosticks for all the help. Confirmed that the track I added is indeed saved in the m3u file with the correct format. I did refresh the web page but still not shown. That’s fine, it is perfectly ok as long as the Mopidy server has saved the track and updated the playlist correctly.

I may develop my own client, when I have good understanding of the APs and if I have time … a mobile app first, maybe. May hack here and there.

Mopidy Mobile does not support adding stuff I want right now as far as I can tell. Am still learning, very new to this world…

many thanks !

I developed an add-on for musicbox webclient for editing playlists but for some reason I never released it. I should do that. Otherwise musicbox webclient has only a very limited support where you can add to a special “radio stations” playlist. Might actially be similar to what you are looking for.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.