Skip to content

Instantly share code, notes, and snippets.

@geekbleek
Created March 6, 2017 18:26
Show Gist options
  • Save geekbleek/d10488a9715e75568f77511e8a680df3 to your computer and use it in GitHub Desktop.
Save geekbleek/d10488a9715e75568f77511e8a680df3 to your computer and use it in GitHub Desktop.
Create a Spotify playlist from r/listenToThis

DataFire Dataflow: Create a Spotify playlist from r/listenToThis

Create a new playlist every day using suggestions from Reddit

View on DataFire

About

This Dataflow will retrieve the top links from r/listenToThis, a place for Reddit users to suggest new music.

After extracting artists and song titles, it will search Spotify for the listed tracks and create a new playlist. A great way to discover new music!

Setup

You'll need to connect your Spotify account on the Settings tab

// GET https://api.spotify.com/v1/me
function request(data) {
return {}
}
// GET http://www.reddit.com/r/{subreddit}/.rss
function request() {
return {subreddit: 'listentothis'}
}
// GET https://api.spotify.com/v1/search
function request(data) {
var tracks = data[1].feed.entries.slice(0, 10);
return tracks.map(function(entry) {
return {
type: "track",
q: entry.title.replace(/\[.*\]/g, '').replace(/\(.*\)/g, ''),
}
})
}
// POST https://api.spotify.com/v1/users/{user_id}/playlists
function request(data) {
return {
user_id: data[0].id,
body: {
name: "r/listentothis for " + new Date().toISOString().slice(0,10),
}
}
}
// POST https://api.spotify.com/v1/users/{user_id}/playlists/{playlist_id}/tracks
function request(data) {
return {
user_id: data[0].id,
playlist_id: data[3].id,
uris: data[2].filter(function(searchResults) {
return searchResults.tracks.items.length;
}).map(function(searchResults) {
return searchResults.tracks.items[0].uri;
})
.join(',')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment