Public
Edited
Dec 27, 2023
Paused
Insert cell
Insert cell
html`

<h4>Todos</h4>

<ol>
<li>Add to last created playlist</li>
<li>Revamp the UI</li>
</ol>

`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// md`_OR_`
Insert cell
// viewof action_existingplaylist = text({
// value: lastCreatedPlaylistID,
// placeholder: "Existing playlist's Spotify URI",
// submit: "Add Recommendations to this playlist",
// description: "Add recommendations to an existing playlist"
// })
Insert cell
// {
// if (
// action_existingplaylist && recommendations?.tracks?.length
// // && lastCreatedPlaylistID != action_createplaylist
// ) {
// await addItemsToPlaylist(lastCreatedPlaylistID, recommendations);
// }
// }
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
recommendations = await recommendationAPI()
Insert cell
Insert cell
result_tracks = await searchAPI(seed_tracks, 'track')
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`#### Get custom made recommendataions`
Insert cell
Insert cell
md`#### Get all the songs ever played by a user`
Insert cell
md`#### Get User's Top Artists`
Insert cell
Insert cell
md`_Login Mechanism_`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
await hitAPI()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function addItemsToPlaylist(sPlaylistID, aItems) {
// is the ID a Spotify URI?
const _playlistID = sPlaylistID?.includes(':') ? sPlaylistID.split(':')[2] : sPlaylistID;

const sTracks = `?uris=${aItems?.tracks?.map(t => t.uri).join(',')}`;

const uri = `https://api.spotify.com/v1/playlists/${_playlistID}/tracks${sTracks}`;

return await hitAPI(uri, 'POST');
}
Insert cell
async function createNewPlaylistWithRecommendations(sPlaylistName) {

const uri = `https://api.spotify.com/v1/users/${spotifyProfile?.id}/playlists`;

const oPlaylist = await hitAPI(uri, 'POST', JSON.stringify({
name: sPlaylistName,
public: false
}));
mutable lastCreatedPlaylistID = oPlaylist.id;
await addItemsToPlaylist(oPlaylist.id, recommendations);
return oPlaylist;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { inputsGroup } from "@bumbeishvili/input-groups"
Insert cell
import {
slider,
text,
radio,
checkbox,
autoSelect,
button
} from "@jashkenas/inputs"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more