Skip to content

Sortren/lastfm-loved-tracks-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Last.fm Loved Tracks To Spotify Playlist

Web application that allows the client to get all of the loved tracks from someone's Last.fm profile and make a playlist with it in Spotify

Technologies used:

Python

Flask

Typescript

React



How does it work in general?

  1. Client pass the exepcted username from Last.fm service to the form on the frontend.
  2. All of the loved tracks from that user are now fetched by the backend side and displayed for the client
  3. Client now clicks that he wants to create a playlist and pass all of the tracks to it, after clicking the button he has to be authorized by the OAuth2.
  4. Client gets redirected to the Spotify website to allow access for the app to playlist modifications
  5. After that process, all of the tracks are being sent to the Spotify created playlist.

Configuration

Create venv

python -m venv venv

Switch to it

./venv/Scripts/activate

Install required dependencies

pip install -r requirements.txt

.env file should look like this:

APP_DEBUG = True/False (if the app are run in the debug mode or not)
LASTFM_API_KEY = api key to the Last.fm service
SPOTIFY_CLIENT_ID= client id from dev dashboard in spotify
SPOTIFY_CLIENT_SECRET= client secret from dev dashboard in spotify
SPOTIFY_REDIRECT_URI=http://127.0.0.1:5000/api/v1/spotify-controller/temporary -> link to the page after successful OAuth2 Redirection

This will start the backend API

python main.py

API Documentation

I have used the Swagger (OpenAPI) from Flask-Restx module, to get auto-generated docs and proper args/req body in endpoints

To display the docs, after running up the server, get to the endpoint:

http://127.0.0.1:5000/api/v1/docs

You will see smth like this: image

You can easily check what is the expected request body or what are the expected arguments of particular endpoint image


OAuth2 Authorization Flow

To get authorized by the Spotify using my API, the specific flow has to be done

  1. GET request on /spotify-controller/authorize will return the prepared link to Spotify OAuth2 authorization website
  2. After passing credentials to Spotify and getting access to my app, you will be redirected to specified endpoint (mentioned in .env file). This endpoint will have the specific "code" received from the Spotify service in the queryparams.
  3. Pass the code from point 2 to the GET /spotify-controller/authorize-callback as a query parameter, if the proccess is successful you will be granted a permission to send requests to spotify via my API, in the response body you will receive the Bearer token which will be useful later
  4. Finally, when you have received the Bearer token, you can invoke the rest of the endpoints from that spotify-controller/, just pass it in the headers as "Authorization"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages