Skip to content

manoloesparta/playlist.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Playlist.py

Playlist.py

Version License Python

Another way for discovering new music

I tend to listen a lot of albums, but I have more than a 130 albums pending to listen you can find a track from each album in this playlist. So this little script was made to randomize the way to choose albums to listen :D

It selects randomly 100 albums out of the 130+, and from each selected album, it selects one song randomly, appending all the songs to this other playlist. This is the playlist I listen daily.

Requirements

git clone https://github.com/manoloesparta/playlist.py
cd playlist.py/
pip install -r requirements.txt

Usage

First you need to create your new Spotify app in this website in order to get your Client ID and Client ID Secret. Then initiate your own SpotifyUser object.

from playlist.spotify import SpotifyUser

username = ' your spotify username '
client_id = ' your client id '
client_secret = ' your client secret id '

spotify_user = SpotifyUser(username, client_id, client_secret)

Get the URIs of your playlist from where you are retrieving the albums and songs, and the one you want to append them. (In other words your playlist source and playlist goal)

from playlist.source import Source
from playlist.goal import Goal

playlist_src = ' your playlist source URI '
playlist_goal = ' your playlist goal URI '

source = Source(playlist_src, spotify_user)
goal = Goal(playlist_goal, spotify_user)

Just update the playlist goal with your Source object

goal.update(source)

Example

from playlist.spotify import SpotifyUser
from playlist.source import Source
from playlist.goal import Goal

username = 'genericusername'
client_id = '9589a322e8bss2a0bfg6achdaw3cfb02'
client_secret = 'cd0629546544c959ebabcd23fd0239b'
spotify_user = SpotifyUser(username, client_id, client_secret)

playlist_src = 'pq1x1iXehjl5gPuEWS54yc' 
source = Source(playlist_src, spotify_user)

playlist_goal = '45fdyrfrey2E0QBBP8teWi'
goal = Goal(playlist_goal, spotify_user)

goal.update(source)

All this data is invented

Docker

In order to build succesfully the docker image and run the src/main.py exactly as it is you need to build it with some enviroment variables. You can build it with this command:

docker build -t playlist.py \
--build-arg user='username' \
--build-arg id='8589a322e8b142a0bf76ac9da43cfb92' \
--build-arg secret='cd0629c79f544c959ebbbbb23fd0239b' \
--build-arg uri='http://google.com/' \
--build-arg src='1ofx1iXeCqb5gPuEWSanfc' \
--build-arg goal='0iYFyrLsby2E0QBBPs2xWi' .

For running the docker image:

docker run --rm -v $(pwd):/usr/src/ -it playlist.py bash

License

This project is licensed under the MIT License