yuioen
October 5, 2022, 6:16am
1
I’m using troi to get a list of recommended mbids for a user. Is there any already implemented way to have spotify or youtube playlist of these recommended songs ?
I’m trying to generate a playlist with the listenbrainz api but I’m struggling to get meaningful response to know why jspf playlist is not understood. '{"code":400,"error":"The browser (or proxy) sent a request that this server could not understand."}'
Is there some python code used somewhere to generate these jspf playlists followinf listenbrainz specification ?
Thx !
1 Like
yuioen
October 5, 2022, 6:20am
2
'use strict';
//29/09/22
include('helpers_xxx_basic_js.js');
include('helpers_xxx_prototypes.js');
include('helpers_xxx_tags.js');
include('helpers_xxx_web.js');
const SimpleCrypto = require('..\\helpers-external\\SimpleCrypto-js\\SimpleCrypto.min');
var regExListenBrainz = /^(https:\/\/listenbrainz.org\/)|(recording)|(playlist)|\//g;
const listenBrainz = {};
/*
Helpers
*/
listenBrainz.getMBIDs = async function getMBIDs(handleList, token, bLookupMBIDs = true) {
const tags = getTagsValuesV3(handleList, ['MUSICBRAINZ_TRACKID'], true).flat();
// Try to retrieve missing MBIDs
const missingIds = tags.multiIndexOf('');
const missingCount = missingIds.length;
This file has been truncated. show original
Maybe that solves your JSPF question (in javascript)
About getting a playlist, it can be done. Problem is there is no current exposed API to provide youtube links, so even if you manage to get a JSPF playlist, content resolution by Artist, title and MBID must be done outside listenbrainz. See this:
metabrainz:master
← regorxxx:add-data-foobar2000-playlist-manager
opened 07:48PM - 25 Sep 22 UTC
Adds new page to navbar (data menu) for playlists management. Includes a link to… [foobar2000 playlist manager ](https://github.com/regorxxx/Playlist-Manager-SMP)to sync playlists on ListenBrainz with local playlists (with content resolution) and Spotify [third party service connection](https://listenbrainz.org/profile/music-services/details/). Also a note about advanced usage related to[ content resolution following XSPF specs.](https://xspf.org/spec#34-content-resolver)
Rationale: if ListenBrainz is gonna make use of playlists (either user made, collaborative or bots), some kind of software support will be required... and it would be great to encourage it with its own page. This would be the first step.
Structure is mostly a clone of 'Adding data' tab.
That’s said, if a solution is given, I’m also interested
Btw, if you are asking how a JSPF playlist looks:
https://api.listenbrainz.org/1/playlist/8abf5d92-f4c2-41d1-9378-6380b5703616
So you should be able to replicate it yourself, there was a JSPF library somewhere.
(the repository at top has a JSPF/XSPF library in javascript)
yuioen
October 5, 2022, 7:26am
5
I generated the jspf playlist :
{'extension': {'https://musicbrainz.org/doc/jspf#playlist': {'creator': 'me'}},
'title': 'test',
'tracks': [
{'identifier': 'https://musicbrainz.org/recording/2b3cab04-1f35-423e-bb56-cfc9f31738cf',
'extension': {'https://musicbrainz.org/doc/jspf#track': {'added_by': 'Moi'}}},
{'identifier': 'https://musicbrainz.org/recording/d54669e6-1acd-4848-acf0-59a20c0972dd',
'extension': {'https://musicbrainz.org/doc/jspf#track': {'added_by': 'Moi'}}}]},
but the backend (https://api.listenbrainz.org/1/playlist/{playlist_mbid}/item/add ) raise {"code":400,"error":"The browser (or proxy) sent a request that this server could not understand."}
Seems like a flask error. Idk where the error is coming from :s
Hi! Can you share the code and logs of some of the HTTP requests (including headers) it is making? I can then take a look at it and try to debug.
On a quick search, it seems you maybe missing the Content-Type: application/json
header.
yuioen
October 5, 2022, 8:36am
8
Isabelxxx:
JSPF
thxxx
def add_mbid_to_playlist(mbids):
playlist_mbid = "783d06d9-7ce8-4b2e-aa4e-1827bd3f5bd3"
tracks = []
for mbid in mbids:
track_namespace_data = {"added_by" : "Moi"}
track = { "identifier" : f"https://musicbrainz.org/recording/{mbid}", "extension" : { "https://musicbrainz.org/doc/jspf#track" : track_namespace_data} }
tracks.append(track)
plt_ext = {"https://musicbrainz.org/doc/jspf#playlist" : {"creator": "me"}}
playlist_data = {"extension" : plt_ext, "title" : "test", "tracks" : tracks}
playlist = {"playlist" : playlist_data }
headers={"Authorization": "Token mytoken", "Content-Type": "application/json"}
response = requests.post(f"https://api.listenbrainz.org/1/playlist/{playlist_mbid}/item/add", data=playlist, headers=headers)
return response.text
validate_playlist from listenbrainz-server/listenbrainz/webserver/views/playlist_api.py at 4aa44b6caf561ac77e35a59966f7e75781223ee3 · metabrainz/listenbrainz-server · GitHub do not seem trigerred
We intend to add support for exporting playlists to spotify. Its a WIP, see Add spotify submission support by amCap1712 · Pull Request #66 · metabrainz/troi-recommendation-playground · GitHub for details. I have lightly tested it and it works for me. You can try it out and report any issues that you face.
The major thing missing is how to get spotify track ids from MBIDs or otherwise. We are working actively to kind of build a mapping from MBIDs to spotify ids that troi can query. troi can then add spotify tracks ids to the recordings in a playlist and submit it to spotify.
We currently haven’t explored exporting playlists to youtube.
1 Like
yuioen
October 5, 2022, 8:42am
10
okey thx you this is the main question I had. Do not bother trying to find out what went wrong in my code :s
Thanks a lot !
I tried out the code anyway to make sure there wasn’t something wrong on the server side. The issue is here"
requests.post(f"https://api.listenbrainz.org/1/playlist/{playlist_mbid}/item/add", data=playlist, headers=headers)
requests encodes the dict data as URL form and the body becomes playlist=extension&playlist=title&playlist=track
.
You should dump the dict to json before, so
requests.post(f"https://api.listenbrainz.org/1/playlist/{playlist_mbid}/item/add", data=json.dumps(playlist), headers=headers)
There’s also a typo in playlist_data dict, tracks
key should be track
. Fixing these two issues should make the code work if you need it.
2 Likes
yuioen
October 5, 2022, 9:48am
12
thx a looot It’s workiiiings o/ <3
yuioen
October 11, 2022, 10:01pm
14
I’ve been testing the recommendations and I think they are great !
there is diversity, but you can group the list with similar artist which allow to have some coherence in the styles and mood. This way you can play the playlist ordered but from a random point of the playlist
there is a good ratio of known and unknown songs
Maybe there is two much very famous songs, for me its okey I like it but maybe you could add an option to clean the playlist from some of them.
Thx !
3 Likes