Giter Club home page Giter Club logo

genre-ify's Introduction

genre-ify

A quick and dirty ruby script to create new Spotify playlists from existing playlists based on music genre.

Purpose

I have "eclectic taste" in music, so generally when I make a playlist I just throw anything I like in there and then set it to shuffle. However, sometimes I find myself wishing I could sort my playlists by genre so that I could listen to all the tracks that are "classic rock" or "deep house". Unfortunately, Spotify doesn't include genre info on a track by track basis. So what this script does (only using libraries that come bundled with ruby) is grab all of the track ids from a specified playlist and put them in a database, then it fetches the artists associated with those tracks (artists have genres, tracks don't), then it matches those genres back to the tracks. Finally, it will ask you to select a genre to create a new playlist from. It will grab the tracks that match that genre from your existing playlist and create a new one. It's not a perfect solution. The genres can be crazy specific, so if you choose one of those you might only generate a playlist with a handful of tracks in it.

Usage

From your command line run:

	ruby genre-ify.rb
  1. Go to Spotify's Interactive API Console and generate an oauth token that has all the permission scopes: https://developer.spotify.com/web-api/console/post-playlist-tracks/ Copy this token, and enter it when prompted by the script.

  2. Enter your spotify username

  3. Enter the ID of the playlist you want to break down. You can get the ID by right clicking on a playlist and choosing "copy spotify uri". The ID will look like this: 0Zw7uKAwbM810t2isqVahR

  4. Once the script has fetched all the relevant info, it will spit out a list of genres. Enter one and hit return. This part of the script uses an SQL like clause. For example: "select track_id from spotify_playlist_tracks where genres like '%rock%';" This would actually match anything in the genre list that has rock in it. So, soft rock, hard rock, progressive rock, etc. You can tweak the query to make it more restrictive.

  5. Enter a name for your new playlist.


Some color commentary on the script. Initially I had created this script so that you would need to enter your own Spotify App ID and Secret Key. Then using that I would generate a token. This was fine for pulling track and artist info, but in order to get a token with enough permissions to create a playlist the user would need to login to spotify and grant access. That meant I would need to handle providing an interface for a user to login and also catch the redirect from the oauth callback, which was more complicated than I wanted...plus I'm lazy. Having the user generate a token from the interactive web console was just easier.

genre-ify's People

Contributors

amione avatar

Stargazers

wolf109909 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.