Spotify and LyricGenius
Spotify is a music streaming service. To use Spotify’s API you must have a Spotify account. The ad free account has a monthly fee as opposed to the free account. However, either version will allow you to get an API key. On the other hand, LyricGenius is a cite of song lyrics. To retrieve information from either one must update their terminal.
Step 1: Terminal
In the terminal write …
pip install spotipyorpip install spotipy --upgradeandpip install lyricsgenius
Once on the website (link above) click My Dashboard
Sign into your Spotify account after clicking My Dashboard. Once logged in you’ll be given a Client_ID and a Client_Secret. It should look like this:
With the IDs the coding process may begin! Open Jupyter notebook, Python, Vscode, or another place of your choosing to code. The README on the following link lays out the code.
A light weight Python library for the Spotify Web API Spotipy's full documentation is online at Spotipy Documentation…
Use the following as a template for your code:
Now we’re going to walk through how to access the LyricGenius API just like we did above with the Spotify API.
lyricsgenius provides a simple interface to the song, artist, and lyrics data stored on Genius.com. lyricsgenius's full…
Once on the website (link above) click the Genius API (in blue) to receive your Client IDs.
LyricGenius asks for an APP WEBSITE URL. Inserting your GitHub account is one option. Once the Genius account provides you with an access token run this code, to find songs based on the artist of your choosing:
Run this code to find song lyrics:
“Am I throwing you off?” Nelly Furtado
“Didn’t think so” Nelly Furtado
Lets continue with some examples, demonstrating how to apply this knowledge.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
from spotipy.oauth2 import SpotifyClientCredentials
pd.options.display.max_columns = 120
Some of these imports should have already been applied. After importing and running the steps from above, a song dictionary was created to hold an accumulation of different songs and their popularities.
Within the dictionary, the song name is the key, and the popularity of the song is the value.
Spotify uses it’s own algorithm to figure out the song popularity.
One can use matplotlib to take the song dictionary and visualize it with a bar graph.
The artist dictionary will be used to keep a record of song names and their corresponding popularities. As you can see below, Beyoncé’s limit is larger because a couple of her songs repeated.
The artist dictionary is made into a DataFrame.
The column, artists, is added to the DataFrame.
How often do I work with DataFrames? The Weeknd asked, “Asked me if I do this every day, I said often.” I work with DataFrames on weekdays too.
Spotify Examples (continuation)
In matplotlib, plt.subplots() was used to create multiple graphs from the DataFrame df_artists. For loops can also be implemented.
From the Beyonce graph we can infer by the popularity power of her songs that she was able to shut down part of a Superbowl.
Last but not least, how to get song lyrics.
Further links to explore:
Search for an Item | Spotify for Developers
GET https://api.spotify.com/v1/search Authorization Required. A valid access token from the Spotify Accounts service…
Here is the blog that inspired me to write this blog: