Skip to content

jameslawlor/reddit-playlists

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

reddit-playlists

reddit-playlists is the python code behind the Reddit Playlists project. You can find the project main page along with the list of playlists generated by this code here.

Motivation

I wanted to create a new way to explore and discover new music, based on the power of collective content curation. There are hundreds of active music-related subreddits devoted to specific genres, bands etc. where members can post and upvote submissions. I decided to target the submissions that were for particular tracks, fortunately these are really common across all the music subreddits and the submissions generally follow a similar format and structure, an example is shown below.

Example

Taking the top track submissions in the last week from /r/Rock and adding them to a Spotify playlist. In the below example 3 of the 4 submissions are detected by the program as valid tracks, and they each follow the basic $ARTIST - $TRACK convention. These are then searched for on Spotify and added to the corresponding subreddit's playlist.

img.png

Setup

You can clone this repository with the command

git clone git@github.com:jameslawlor/reddit-playlists.git

Create a virtual environment and install the package requirements with pip install -r requirements.txt

You'll also need to create two new files to contain credentials for using the Spotify and Reddit APIs. Add these to the project root directory

  • praw.ini
  • spotipy.cfg

See the PRAW and Spotipy docs for how to set these up. They'll also show you how to create credentials for using the Spotify and Reddit APIs. If you're planning to share the code anywhere make sure you do not share the contents of these files! These have been added to the .gitignore file already but please be mindful of this.

Usage

The main program can run different tasks by the command python main.py --task $TASK where $TASK is one of:

  • get_subreddits_and_genres - scrape the list of music subreddits from the /r/Music wiki and adds them to a JSON file in data/subreddit_genre_sub_count/
  • create_empty_playlists - create an initial set of empty playlists using the output from the first task
  • update_playlists - Refresh the playlists with the previous week's top tracks. This is the task that is run weekly to maintain the Spotify playlists.
  • delete_playlists - delete all user's Spotify playlists matching some regex pattern (use carefully)
  • generate_subreddit_playlist_links_markdown_file - creates a markdown file listing all subreddits and linking to their corresponding playlists

The settings for these tasks are contained in the corresponding .yaml files in configs/.

Automation

The playlist updating is scheduled to run weekly via Github Actions and can be triggered manually. See code in the .github/workflows directory. It's also easy to set up email notifications in the event this fails through the Github UI.

Current issues and future development

This is an open project so if you spot a way to improve anything feel free to create a PR :)

  • There are a couple of issues where the wrong tracks can be added or valid tracks missed completely for various reasons, mainly because of the difficulty in handling the variability in submission format and due to remixes or covers and so on. Future development will probably focus on improving these problems.

  • At some point I would like to add support for archiving past playlists, currently they are overwritten entirely. I also think it could be useful to provide monthly top tracks for smaller subreddits that don't get many submissions.

  • Authentication with Spotify during the weekly cron job run is currently handled in a very hacky way due to the API credentials flow. Because the job runs via Github Actions and is containerised (can't save state in memory between runs) and is headless, the recommended authentication method would require user intervention and a browser redirect (manually copy pasting a URL essentially). After trying a few alternatives the only authentication method I found that seems to be compatible with this setup is to synthesise a cache file identical to what would be created if running locally. The script then reads from this (synthesised) cache by default and the user token is refreshed automatically. There is probably a smarter way so if you have any ideas please let me know.

About

reddit-playlists is created and maintained by James Lawlor. You can contact me via LinkedIn or Twitter.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published