mirror of
https://github.com/bnair123/MusicAnalyser.git
synced 2026-02-25 11:46:07 +00:00
feat: migrate to PostgreSQL and enhance playlist curation
- Migrate database from SQLite to PostgreSQL (100.91.248.114:5433) - Fix playlist curation to use actual top tracks instead of AI name matching - Add /playlists/history endpoint for historical playlist viewing - Add Playlist Archives section to frontend with expandable history - Add playlist-modify-* scopes to Spotify OAuth for playlist creation - Rewrite Genius client to use official API (fixes 403 scraping blocks) - Ensure playlists are created on Spotify before curation attempts - Add DATABASE.md documentation for PostgreSQL schema - Add migrations for PlaylistConfig and composition storage
This commit is contained in:
@@ -16,8 +16,9 @@ from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
# CONFIGURATION - You can hardcode these or input them when prompted
|
||||
SPOTIFY_CLIENT_ID = input("Enter your Spotify Client ID: ").strip()
|
||||
SPOTIFY_CLIENT_SECRET = input("Enter your Spotify Client Secret: ").strip()
|
||||
REDIRECT_URI = "http://localhost:8888/callback"
|
||||
SCOPE = "user-read-recently-played user-read-playback-state"
|
||||
REDIRECT_URI = "http://127.0.0.1:8888/callback"
|
||||
SCOPE = "user-read-recently-played user-read-playback-state playlist-modify-public playlist-modify-private"
|
||||
|
||||
|
||||
class RequestHandler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
@@ -36,6 +37,7 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
# Shut down server
|
||||
raise KeyboardInterrupt
|
||||
|
||||
|
||||
def get_token(code):
|
||||
url = "https://accounts.spotify.com/api/token"
|
||||
payload = {
|
||||
@@ -49,24 +51,27 @@ def get_token(code):
|
||||
response = requests.post(url, data=payload)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
print("\n" + "="*50)
|
||||
print("\n" + "=" * 50)
|
||||
print("SUCCESS! HERE ARE YOUR CREDENTIALS")
|
||||
print("="*50)
|
||||
print("=" * 50)
|
||||
print(f"\nSPOTIFY_REFRESH_TOKEN={data['refresh_token']}")
|
||||
print(f"SPOTIFY_CLIENT_ID={SPOTIFY_CLIENT_ID}")
|
||||
print(f"SPOTIFY_CLIENT_SECRET={SPOTIFY_CLIENT_SECRET}")
|
||||
print("\nSave these in your .env file or share them with the agent.")
|
||||
print("="*50 + "\n")
|
||||
print("=" * 50 + "\n")
|
||||
else:
|
||||
print("Error getting token:", response.text)
|
||||
|
||||
|
||||
def start_auth():
|
||||
auth_url = "https://accounts.spotify.com/authorize?" + urllib.parse.urlencode({
|
||||
"response_type": "code",
|
||||
"client_id": SPOTIFY_CLIENT_ID,
|
||||
"scope": SCOPE,
|
||||
"redirect_uri": REDIRECT_URI,
|
||||
})
|
||||
auth_url = "https://accounts.spotify.com/authorize?" + urllib.parse.urlencode(
|
||||
{
|
||||
"response_type": "code",
|
||||
"client_id": SPOTIFY_CLIENT_ID,
|
||||
"scope": SCOPE,
|
||||
"redirect_uri": REDIRECT_URI,
|
||||
}
|
||||
)
|
||||
|
||||
print(f"Opening browser to: {auth_url}")
|
||||
try:
|
||||
@@ -74,7 +79,7 @@ def start_auth():
|
||||
except:
|
||||
print(f"Could not open browser. Please manually visit: {auth_url}")
|
||||
|
||||
server_address = ('', 8888)
|
||||
server_address = ("", 8888)
|
||||
httpd = HTTPServer(server_address, RequestHandler)
|
||||
print("Listening on port 8888...")
|
||||
try:
|
||||
@@ -83,5 +88,6 @@ def start_auth():
|
||||
pass
|
||||
httpd.server_close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
start_auth()
|
||||
|
||||
Reference in New Issue
Block a user