Giter Site home page Giter Site logo

spotify-top-200-playlist-generator's Introduction

spotify-top-200-playlist-generator

Generate Spotify top 200 playlist from Spotify Charts.

Powered by Spotipy.

How to Use

Fill config.yml with your own info:

user_id: your-spotify-account-id
redirect_uri: your-spotify-app-redirect-uri
generator:
# region_code: playlist_id
  global: your-global-top-200-playlist-id
  us: your-us-top-200-playlist-id

Create .env and set environment variables:

CLIENT_ID=your-spotify-app-client-id
CLIENT_SECRET=your-spotify-app-client-secret

Where to get user_id and playlist_id?

Click Copy Spotify URI in the image below and you will get text like this:

spotify:user:12135742379:playlist:6F61J2pfnBeVZkXfumFQIi

In this case, user_id is 12135742379 and playlist_id is 6F61J2pfnBeVZkXfumFQIi.

Where to get client_id, client_secret and redirect_uri?

Go here to create your own Spotify application and you will be given a Client ID and a Client Secret. Then, you can edit your redirect URL in app settings. We recommend using http://localhost:{PORT_NUMBER} as your redirect URL since this will let your spotify app automatically open the browser and authenticate the app if you have logged in your Spotify account in the same browser.

Periodically update with Github Actions.

Here is the workflow that can help you update your Top 200 playlists periodically. Sensitive information like client id and client secret should not be exposed. Therefore, we add them as secrets at Github, and set them as environment variables in the workflow. Also, since Github Actions works in a headless environment, it is impossible to use a browser for authentication. Our strategy is, we first authenticate the app locally, which will give us a .cache file that saves tokens. We create secret AUTH_CACHE that saves the content of .cache at Github and also set it as a environment variable in the runtime. In Python script, we fetch this environment variable and create a .cache file using this secret. This newly created .cache file by Python will be used for authentication.

Another thing is, tokens in .cache could be refreshed in the runtime. If we do not update AUTH_CACHE to keep up with the content of .cache, tokens saved in AUTH_CACHE could be expired. Therefore, after the playlists are updated, we have to write the content of .cache back to secret AUTH_CACHE. To write secrets of a Github repo, we need a token with specific scopes of permissions. First, we create a personal access token named TOKEN_WRITE_SECRETS with scopes as follows:

Copy the generated token, and add it to secrets. We also name this secret TOKEN_WRITE_SECRETS.

In total, we should have four secrets:

spotify-top-200-playlist-generator's People

Contributors

graysonliu avatar

Stargazers

 avatar

Watchers

James Cloos avatar  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.