Inspiration

A great way to learn a new language is to listen to music in that language. For me, I love listening to foreign music, whether it be a language I'm trying to learn or not. Personally, I listen to music on Spotify, but it was always a pain to have to figure out what the song is called when it is written in a foreign language and I'm on the mobile app. This is why I created an API that would fetch the current track playing on my Spotify and it would link me to the lyrics or if I go directly on the Heroku hosted Flask application, it would have the lyrics in HTML.

What it does

Text Spotify uses Twilio SMS as a front end and when you text "lyrics" to the Twilio Number connected to the API, it will respond with the Genius link to that song if it exists on Genius. The API also uses Beautiful Soup web scraping on the Genius song link so the lyrics are directly available on the Heroku hosted app. Now I can learn more about the song and the language used and sing along (probably not).

How I built it

I fetched my user data from the Spotify API, which requires an authorization code in order to get the access token. After that, I used "lyricsgenius" library to scrape lyrics off the Genius website as they do not offer lyrics in their API. Finally, I deployed the Flask application that was handling the API calls and other backend to Heroku and linked up a Twilio number to it.

Challenges I ran into

My original idea was that the Twilio number would text me all the lyrics, with the song structure split up, but I quickly realized that was not possible as the max character limit was 160 characters and a typical song was around 3000, so that definitely was not going to work. I ended up having to settle with just the Genius link and the lyrics posted on the Heroku website whenever it is loaded.

Accomplishments that I'm proud of

This was the first time I built with Spotify APIs, Flask, and deployed to Heroku which was quite the learning experience.

What I learned

I learned to keep my virtual environment organized and how to create web apps with Flask. I also learned how to build APIs along with getting authorization codes and making access tokens. I became more familiar with the authorization flow and have a better understanding of how web apps/ APIs work.

What's next for Text Spotify API

The next steps would be to have the token auto refresh as the authorization was kind of funky to get working. I also need to clean up the front end of the web application because as of right now it is just plaintext. I'm also planning on incorporated google translate and layering the lyrics such that the user is able to see, for example, the chorus in their native language, further deepening their understanding :).

Share this project:

Updates