Hipster cred! I have it, you want it. No way to build it up faster than to be into something before it becomes popular. You may have been wondering how you might be able to pull a random list of fifteen infrequently listened to bands and document the fact that you knew of them before it became all about the money. Well lucky for you we have what you need.
Note: if you see a band in this list and object to their placement, you are functioning at a higher hipster level than this blog accounts for and can add that feather to your fedora.
Setting Up the Spotify API
Before this script will be able to run at all we will need to set up an API(Application Program Interface) using this link. This will give us the client ID and let us set a redirect URI(Uniform Resource Identifier) for after we authenticate. Seen below is what this screen looks like after I use cutting edge blurring technology to hide my actual IDs.
With this created, you can now generate an access request. The request has to contain the following:
Client ID - Identification number generated by Spotify
Redirect URI - URI that the browser will go to after you authenticate.
Response Type - How you want the Spotify servers to respond to the request
Scope - Permissions you are requesting
Opening Your Spotify Hipster Playlist
Here is how our URI request looks. $clientID should be replaced with your client ID after you register your application with Spotify
If you copy the above URL into a web browser it will respond with your access token inside the address bar. We could manually copy that over like we are animals, or we can use PowerShell to build our own browser on the fly that will have the token we need in an object. Let’s check in with Kris for a product demo to see how he might perform such a task.
Compelling stuff Kris, thanks for stopping by.
Running this will bring you to a login screen for Spotify. Once your credentials are in it will take you to some fantastic artwork by Jonathan Lindgren.
Feel free to bask in its glory, but to move forward with the script you will eventually have to close this browser.
Once you close that browser, your access token will be in $Browser.Url.Fragment. It will take a little work to clean up that data to make it usable. First, you need to use regular expressions to strip everything but the token value. Then, you need to specify the token type and create a header variable.
That is it. Just use different variations of that command and it will let you grab your account, build a playlist, grab every genre, and get the three least listened to bands for each one.
Now that we have all the steps lets take a look at the completed script.
Final note, should you want to do something useful with these commands the format would be the same. Just know that I used these commands before they were cool.
Jordan had spent his life wondering why tasks he didn’t like to do had no options to complete themselves. Eventually he had to make that happen on his own. It turned out that he enjoyed making tasks complete themselves, and PDQ thought that is something he should talk about on the internet while drinking most Thursdays on the PDQ webcast.