A tool for finding Spotify tracks and albums from names mentioned in text.
Project description
Song Scrounger
A little tool for creating Spotify playlists based on song and album names mentioned in text, like this webpage.
import asyncio
from song_scrounger.song_scrounger import SongScrounger
from song_scrounger.spotify_client import SpotifyClient
from song_scrounger.util import get_spotify_creds, get_spotify_bearer_token
async def main():
spotify_client_id, spotify_secret_key = get_spotify_creds()
spotify_bearer_token = get_spotify_bearer_token()
spotify_client = SpotifyClient(spotify_client_id, spotify_secret_key, spotify_bearer_token)
song_scrounger = SongScrounger(spotify_client)
# assuming the file is in the current working directory
songs = await song_scrounger.find_songs("example_containing_songs.txt")
all_songs = [song for song_name, matching_songs in songs.items() for song in matching_songs]
spotify_uris = [song.spotify_uri for song in all_songs]
playlist_name = "My New Playlist of Songs Created with Song Scrounger"
await spotify_client.create_playlist(playlist_name, spotify_uris)
# assuming the file is in the current working directory
albums = await song_scrounger.find_albums("example_containing_albums.txt")
all_albums = [album for album_name, matching_albums in albums.items() for album in matching_albums]
spotify_uris = [song.spotify_uri for album in all_albums for song in album.songs]
playlist_name = "My New Playlist of Albums Created with Song Scrounger"
await spotify_client.create_playlist(playlist_name, spotify_uris)
if __name__ == "__main__":
asyncio.run(main())
Assuming you have:
- Created a file in the same directory called
example_containing_songs.txt
(see example below) - Created a Spotify Developer account and a Spotify Application to get a authentication credentials (client ID and a secret key).
- Retrieved a Bearer Token with permissions to create playlists on your account.
- Set the environment variables
SPOTIFY_CLIENT_ID
,SPOTIFY_SECRET_KEY
, andSPOTIFY_BEARER_TOKEN
.
Example Input File
The contents of example_containing_songs.txt
might look like:
Does anybody remember Rock 'n' Roll? Rock music? You know, "be-bop-a-lula," and "my baby love," and "psycho killer, qu'est-ce que c'est"? Remember when it was rebellious to crank your bedroom stereo (or phonograph) to maximum on a Hendrix or Black Sabbath tune? How about standing around at a High School dance, making fun of the band as it tried to play a Stones or U2 song, while quietly dreading the moment when the inevitable slow dance number would begin? Was it "Loving You" by Elvis this time? Or was that another era, somebody else's life?
The contents of example_containing_albums.txt
might look like (taken from The Best Albums of 2020):
Mary Lattimore: "Silver Ladders" Listening to Mary Lattimore’s Silver Ladders feels like blinking awake on New Year’s Day: There’s some melancholy over what has passed mixed with buzzing wonder at what lies ahead. The harpist’s ambient compositions are somber but whimsical, submerging her careful plucks in murky pools of reverb and synth. She recorded the album with Slowdive’s Neil Halstead at his studio in the coastal English county of Cornwall, and cites the quiet minutiae of seaside life—cream tea, a pub quiz, the Sunday roast—as inspiration for the music. In turn, each twinkling note relays the bittersweet tranquility of memories gone by. –Vrinda Jagota
Creating a Spotify Developer App
You'll need:
- Spotify Developer app
- sign up at Spotify for Developers
- create a new app to get client ID and secret key
- Spotify (Premium) account to call user-specific API methods:
spotify_client.create_empty_playlist()
spotify_client.add_tracks()
Then you can take these steps to set up authentication for use by song_scrounger
:
- Add the following redirect URI for your app:
https://localhost:5000
- Set environment variables
SPOTIFY_CLIENT_ID
andSPOTIFY_SECRET_KEY
with your credentials- e.g.
export SPOTIFY_SECRET_KEY="your-secret-key"
- e.g.
- Get a bearer token:
- Navigate to the following URL, with your client ID replaced:
https://accounts.spotify.com/en/authorize?client_id=<your-client-id>&redirect_uri=https:%2F%2Flocalhost:5000&scope=streaming,user-read-playback-state,user-read-email,user-read-private,playlist-modify-public&response_type=token&show_dialog=true
- Click Agree
- You'll be redirected to a URL that looks like:
https://localhost:5000/#access_token=BQBjyGh4htNbiDcPrS9YpsIks9qfVQRr1cIJcWdeqVw4rVbU5XgcHVe74BJfU3jOuU-OyX7ssgQCLflbwoMpWt_uWE-Nu8VV5u4AcqBrRoZ1659H4Bb28GK-dgXKzMXZzEV07_UKAIH2Rhq5IS7m8AlehLbp_aoxtTTelUr-lwkZ6iWUNrHXeSK5Gc89nFxWYG4&token_type=Bearer&expires_in=3600
- Copy the value of
access_token
- Navigate to the following URL, with your client ID replaced:
- Set environment variable
SPOTIFY_BEARER_TOKEN
with your new bearer token, which should be good for 1 hour
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file songscrounger-0.2.3.tar.gz
.
File metadata
- Download URL: songscrounger-0.2.3.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
21226324517f940044cc548304df7e15ce1fb55a64e078a3d4e113dda66c67ad
|
|
MD5 |
21091566f353f5fbdc28249866666eee
|
|
BLAKE2b-256 |
2681fb079e2f42da72a85e27f845a479916f57595fd699979fcb21f26141418c
|
File details
Details for the file songscrounger-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: songscrounger-0.2.3-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
86ac63f6c9a68c9d34b50028d80a6c3402499cec5c10ef5f5547731c1bfe4baa
|
|
MD5 |
ccc704728a6f94ff01d32981f092bf79
|
|
BLAKE2b-256 |
0cffab4b8c7560d4f204ab470a7ea532494e02347a67c83413ddbebf451a2135
|