This program will search for spotify tracks posted in the HipHopHeads subreddit and add them to a playlist of your choice. HipHopHeads is a subreddit dedicated to everything hiphop, including the latest mixtapes, videos, news, and anything else hip hop related from your favorite artists. You can utilize this program as a means to finding the hottest new hiphop music of the current period. This program is a python script does not run like a tradition npm package install; however, it still does require you to clone the repository locally for crediential configuration detailled later.
Flask has recently been added to the project. You can read up on how to get it setup here.
This project uses Python3 and requires either a macOS and/or Linux. Windows is not sufficent for this program. You can download Linux through Windows by downloading wsl.
This app is to be downloaded and run on your machine. To do this, you will need to register your local copy of the app with spotify by creating a Spotify developer account.
Tutorial to setup a Spotify developer account
- Connect Spotify Developer to your Spotify account by logging in or creating a free Spotify account here.
- Enter your personal dashboard and click the green “Create a Client ID” button to fill out the form to create an app or in our case integrate with our app
- Once you fill out the form, return to your dashboard click on the new app you just created and you should see the necessary details for the information needed(listed below).
You will need to register your app and obtain the following information:
- client id
- client secret
- your spotify username
- playlist id of the playlist you want to add the tracks to
- the url you want to redirect to for authentication, i.e. http://google.com/
- this must be added under your app settings > Redirect URIs
You will also need to setup a reddit instance with praw. Here's a useful guide I used to do this.
Download a local copy of the project for the next steps with the following command:
git clone https://github.com/skandakumaran/fresh_script.git
To set up your credentials, create a new file called credentials.json
in the root of the project with the following contents:
{
"spotify": {
"username": "[Spotify username]",
"client_id": "[Spotify client id]",
"client_secret": "[Spotify client secret]",
"redirect": "[redirect uri]"
},
"reddit": {
"username": "[reddit username]",
"client_id": "[praw client id]",
"client_secret": "[praw client secret]"
}
}
This project uses a dependency manager called pipenv. Follow the instructions to install it here.
The project dependencies are listed in a Pipfile. Using pipenv, you can install all the dependencies with the following commands:
cd fresh_script
pipenv install
Pipenv uses virtualenv to create a python environment with all the dependencies listed in the Pipfile. Before running the fresh.py script, you must first activate the environment:
pipenv shell
If you wish to deactivate the environment use the command
exit
Running the program is simple. The first time you run it, you will be asked for your Spotify credientials which will be saved to a config file for ease of use in the future. Choose to sort results by hot or new, enter a post limit, and then enjoy.
python3 fresh.py
The following arguments can be passed to the script
Short | Long | Type | Description |
---|---|---|---|
-s | --sort | string | Sort by hot, new, rising, random_rising, controversion or top |
-l | --limit | int | How many posts to grab |
-t | --threshold | int | Only posts with score above threshold |
-f | --fresh | bool | Only add tracks with the [FRESH] tag |
-ia | --include-albums | bool | Include tracks from albums |
-v | --verbose | bool | Output songs being added and other info |
-p | --playlists | bool | List, add, or remove playlists to add songs to |
We can use cron to automatically run the script periodically in order to keep it up-to-date. You will need either a macOS computer or Linux server to use cron.
- Follow the
running the script
instructions to make sure your.config.ini
file is generated with the required parameters - Run
crontab -e
to open the cron editor, which is similar to vim - Use the following format to create a line for your cron
For example, you would do the following to run this everyday at 9AM
* * * * * command to be executed - - - - - | | | | | | | | | ----- Day of week (0 - 7) (Sunday=0 or 7) | | | ------- Month (1 - 12) | | --------- Day of month (1 - 31) | ----------- Hour (0 - 23) ------------- Minute (0 - 59)
0 9 * * * python /home/jsmith/fresh.py
- is assumed to mean every sequence of the period. In this instance on minute 0 of hour 9 are specified; however, the day, month, and day of week are *, allowing for the sequence to be automatically ran agnostic of those period changes.
I appreciate any help and support. Feel free to fork and create a pull request