zachpmanson / penultimate-guitar

A streamlined Ultimate Guitar client with Spotify integration
https://pg.zachmanson.com
MIT License
6 stars 5 forks source link

Allow Spotify playlist import to generate a folder of tabs #7

Closed zachpmanson closed 1 year ago

zachpmanson commented 1 year ago

Relies on #6

zachpmanson commented 1 year ago

Have created a spotify app with a clientid and secret. Using these can request a bearer token

import base64
import requests

client_id = "id"
client_secret = "secret"

# Concatenate the client ID and client secret separated by a colon
client_creds = f"{client_id}:{client_secret}"

# Base64 encode the client credentials string
creds_b64 = base64.b64encode(client_creds.encode()).decode()

# Set up the POST request headers and body
auth_header = {"Authorization": f"Basic {creds_b64}"}
auth_body = {"grant_type": "client_credentials"}#, "scope": "playlist-read-collaborative"}

# Send the POST request to get the access token
response = requests.post("https://accounts.spotify.com/api/token", headers=auth_header, data=auth_body)
# Parse the JSON response and extract the access token
access_token = response.json()["access_token"]

print(access_token)

access_token can be used to retrieve playlist items.

curl "https://api.spotify.com/v1/playlists/1FpPujVhClWvEhRNy519Sk/tracks" -H "Authorization: Bearer  <access_token>"

No particular scope is required to read in public playlist items.

zachpmanson commented 1 year ago

Spotify side of this integration is done, now need match the playlist items with UG tabs (the real hard part)