Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function sendToPlaylist(selectedListens) {
- const playlistMbid = '1bf2a0c7-0fb9-459d-9b83-71da363f4a93'; // Your provided playlist MBID
- const JSPFPlaylistData = {
- playlist:{
- track: selectedListens.map(recordingMBID => {
- return {identifier: [`https://musicbrainz.org/recording/${recordingMBID}`]}
- })
- }
- }
- try {
- const response = await fetch(`https://api.listenbrainz.org/1/playlist/${playlistMbid}/item/add`, {
- method: 'POST',
- headers: {
- 'Authorization': `Token ${listenBrainzToken}`,
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify(JSPFPlaylistData)
- });
- if (response.ok) {
- alert('Successfully added to playlist!');
- } else {
- const responseText = await response.text(); // Get the error text if available
- console.error("Response Error Text:", responseText); // Log the error text
- throw new Error(`Failed to add to playlist: ${response.status} - ${responseText}`);
- }
- } catch (error) {
- alert(`Error: ${error.message}`);
- console.error('Error:', error);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment