Web demo: https://epsil.github.io/spotgen/
npm install -g spotgen
Note that on some systems, it might be necessary to prepend the
npm command with
The generator can now be invoked from the command line as
spotgen (see usage).
spotgen input.txt output.txt
input.txt is a text file containing a generator string, invoking any of the commands described below.
output.txt will contain the generator's output, a list of Spotify URIs which can be imported into Spotify.
Alternatively, one can pass a generator string as a single argument. In that case, the Spotify URIs are written to standard output:
spotgen "#artist Bowery Electric" spotgen "#similar Beach House\n#similar Hooverphonic" spotgen http://www.last.fm/user/username/library
Make sure to surround the string with quotes (
") if it contains spaces or special characters. Line breaks can be expressed as
One can also run the generator with no arguments and enter commands interactively. This saves one the trouble of quoting strings and escaping newlines.
For more information, type
To import the playlist into Spotify:
The generator effectively defines a "mini-language" for creating Spotify playlists. One can create a playlist in many ways: on the basis of track titles, album titles, artist names, similar artists, top tracks or webpages.
Below follows a list of generator commands.
The generator can scrape data from web pages. (Note that this functionality is only available in the command-line version.)
The generator can be instructed to fetch data from Last.fm's webpages simply by supplying the page's address. For example, to create a playlist of artists similar to an artist, add the line:
To create a playlist of a user's recently played tracks:
To fetch multiple pages in succession, add a number parameter:
This is functionally identical to:
http://www.last.fm/user/username/library http://www.last.fm/user/username/library?page=2 http://www.last.fm/user/username/library?page=3 http://www.last.fm/user/username/library?page=4 http://www.last.fm/user/username/library?page=5
Note that Last.fm displays listening history in reverse chronological order. To create a chronological playlist, add the
To scrape a Pitchfork list:
To scrape a Rate Your Music chart:
To scrape a Reddit forum:
To scrape a comments thread:
To convert a YouTube playlist:
To retrieve the top 10 tracks of an artist, pass the following to the generator:
#top Aphex Twin
The generator will output a playlist consisting of the ten most popular tracks of Aphex Twin, which can then be imported into Spotify.
All of the commands listed here can be used multiple times. For example:
#top Aphex Twin #top Beach House
This will create a playlist consisting of the top tracks of Aphex Twin, followed by the top tracks of Beach House.
To retrieve only the top 5 tracks, use
To retrieve all tracks, use
To find similar artists:
#similar Aphex Twin
This will generate a 100-track playlist consisting of the 5 most popular tracks from the 20 most similar artists to Aphex Twin.
To retrieve more tracks, use
To add an album:
#album Biosphere - Substrata
Alternatively, use the album's Spotify link or Spotify URI:
To add all the albums of an artist:
#artist Beach House
Alternatively, use the artist's Spotify link or Spotify URI:
Note that this command can be rather slow, as it attempts to retrieve every single track by the artist, including tracks from collaboration and compilation albums. A fast alternative is the
To add all the tracks of a playlist:
username is the owner of the playlist and
playlistid is the ID of the playlist.
Alternatively, use the playlist's Spotify link or Spotify URI:
To add a single track to the playlist, add a line on the form
ARTIST - TRACK:
Beach House - Walk in the Park Beach House - Irene Beach House - Other People Beach House - Troublemaker Beach House - Wishes
Alternatively, use the track's Spotify link or Spotify URI:
By default, the generator automatically removes duplicate tracks. To allow duplicates, add the line:
To reverse the order of the tracks, add the line:
To shuffle the order of the tracks, add the line:
One can reorder the tracks with the
#order by command. One can order on any track attribute, such as
album, etc. For example, to order the tracks by Spotify popularity, use
#order by popularity:
#order by popularity #artist Beach House
One can also leverage Spotify's analytic algorithms and order on the basis of audio features such as
tempo, etc. For example, to screen for instrumental tracks:
#order by instrumentalness #artist Beach House
This moves instrumental tracks towards the beginning of the playlist and vocal tracks towards the end. To do the opposite, add the
#order by instrumentalness #reverse #artist Beach House
The generator also provides Last.fm support. To order by Last.fm playcount, add the line
#order by lastfm:
#order by lastfm #artist Beach House
To order by Last.fm user playcount, add the Last.fm username at the end:
#order by lastfm username #artist Beach House
To sort the ordered tracks into groups, use
#order by lastfm #group by artist #similar Beach House
This will create a Last.fm-ordered playlist of artists similar to Beach House, where tracks from the same artists are grouped together.
To group the tracks and then interleave them, use
#order by popularity #alternate by artist #similar Beach House #similar Hooverphonic
This will create a Last.fm-ordered playlist of artists similar to Beach House and Hooverphonic, with each track having a different artist from the previous track.
The generator understands Spotify links and Spotify URIs. These are usually obtained by opening the item in Spotify and choosing More -> Share (click on the
The following example creates a new playlist out of an existing playlist, applying the
#order command in the process:
#order by popularity https://open.spotify.com/user/redditlistentothis/playlist/6TMNC59e1TuFFE48tJ9V2D
Another method is to select the playlist's tracks in Spotify, copy them, and then paste them into a text file. This produces a list of Spotify track links:
https://open.spotify.com/track/4oNXgGnumnu5oIXXyP8StH https://open.spotify.com/track/7rAjeWkQM6cLqbPjZtXxl2 https://open.spotify.com/track/2Nt4Uw91pQLXSJ28SttDdF ...
Spotify URIs are the default output format of the generator. They look like this:
spotify:track:4oNXgGnumnu5oIXXyP8StH spotify:track:7rAjeWkQM6cLqbPjZtXxl2 spotify:track:2Nt4Uw91pQLXSJ28SttDdF ...
One can also import M3U playlists (with the file extension
.m3u8), provided they contain
EXTM3U metadata. That is, the playlist should be on the form:
#EXTM3U #EXTINF:404,Desire Lines - Deerhunter Deerhunter/Halcyon Digest/06 Desire Lines.mp3 #EXTINF:230,Saved By Old Times - Deerhunter Deerhunter/Microcastle/10 Saved By Old Times.mp3 #EXTINF:202,Agoraphobia - Deerhunter Deerhunter/Microcastle/02 Agoraphobia.mp3 #EXTINF:133,Revival - Deerhunter Deerhunter/Halcyon Digest/03 Revival.mp3 #EXTINF:264,Twilight at Carbon Lake - Deerhunter Deerhunter/Microcastle/12 Twilight at Carbon Lake.mp3
The generator translates this to:
Deerhunter - Desire Lines Deerhunter - Saved By Old Times Deerhunter - Agoraphobia Deerhunter - Revival Deerhunter - Twilight at Carbon Lake
The generator can read and write the CSV format used by Exportify:
spotify:track:3jZ0GKAZiDMya0dZPrw8zq,Desire Lines,Deerhunter,Halcyon Digest,1,6,404413,, spotify:track:20DDHYR4vZqDwHyNFLwkXI,Saved By Old Times,Deerhunter,Microcastle,1,10,230226,, spotify:track:2SpHd4lGMrJMIQDf92V6VP,Agoraphobia,Deerhunter,Microcastle,1,2,202640,, spotify:track:30wvVTkqA4Fp5ZCG0xGof7,Revival,Deerhunter,Halcyon Digest,1,3,133666,, spotify:track:6vtwbm7YGkTwTINdrcXV5I,Twilight At Carbon Lake,Deerhunter,Microcastle,1,12,263986,,
To output to this format, add the line
#csv Deerhunter - Desire Lines Deerhunter - Saved By Old Times Deerhunter - Agoraphobia Deerhunter - Revival Deerhunter - Twilight at Carbon Lake
CSV files have the advantage of being editable with a spreadsheet editor such as Microsoft Excel or LibreOffice Calc. They are also future-proof, as they contain additional info to the Spotify URIs. (The URIs might, conceivably, change or become outdated. On the other hand, the title, artist and album of a track can be used to find that track on any music streaming service.)
The generator is available as a single-page application running in the browser. It is hosted at https://epsil.github.io/spotgen/.
The generator code runs entirely on the client side. However, because of restrictions in Spotify's authentication service, the user first has to log in with their Spotify account. Despite the warning, the application does not access any private data. (Alternatively, the command-line version can be used without logging in.)
It is also possible to run the web demo locally:
npm run http
This will start up a
http-server instance at http://localhost:9000/.
Note that Spotify's authentication service requires the web demo to be hosted at a whitelisted address. This is the reason for running
http-server at port 9000 (merely opening
index.html in a browser will not work).
For more information about authentication, see the official Spotify Web API documentation.
The web demo is built with Browserify, which goes to show that the library is browserifiable.
The generator is also available as a library that can be included in another project. To install it in the project's
npm install --save spotgen
The following example demonstrates how to use the library:
var Generator =var spotgen = '#top Beach House\n#top Deer Hunter'spotgen
generate() method returns a promise that contains the Spotify URIs, represented as a newline-separated string. To access this value, use the
then() callback as shown.
Note that if one is writing one's own application for Spotify, then one should register the application and obtain a client ID and client secret key. These are passed to the
Generator class like so:
var spotgen = '#top Beach House' clientId clientKey
The generator will then use these values to acquire an access token for web API requests. If one already has a token, then one can pass that to
Generator as well:
var spotgen = '#top Beach House' clientId clientKey token
Instead of installing the package with
npm, one can fetch the source code from GitHub:
git clone https://github.com/epsil/spotgen.git
Then fetch all depencies with
cd spotgen npm install
Then create a global package link with
The package includes a test suite. To run it, type: