auto syncing lyrics, canvas replaces album art (if available), fixed layout (margins, padding, etc.), refactored some code
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
from flask import Flask, render_template, request, url_for, redirect, send_from_directory
|
||||
import time
|
||||
import requests
|
||||
from urllib.parse import urlencode
|
||||
import webbrowser
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import _canvas as SpotifyCanvas
|
||||
import time
|
||||
import syncedlyrics
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -88,6 +88,7 @@ def callback():
|
||||
@app.route('/appdata')
|
||||
def appdata():
|
||||
global access_token
|
||||
stime = time.time()
|
||||
user_headers = {
|
||||
"Authorization": "Bearer " + access_token,
|
||||
"Content-Type": "application/json"
|
||||
@@ -96,9 +97,12 @@ def appdata():
|
||||
currently_playing = requests.get("https://api.spotify.com/v1/me/player/currently-playing", headers=user_headers)
|
||||
if currently_playing.content:
|
||||
if currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] == request.args.get('id'):
|
||||
return { 'progress_ms': currently_playing.json()["progress_ms"]
|
||||
print("QUICK" + str(time.time() - stime))
|
||||
return { 'progress_ms': currently_playing.json()["progress_ms"],
|
||||
}
|
||||
elif currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] != request.args.get('id'):
|
||||
elif currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] != request.args.get('id'):
|
||||
|
||||
print("FULL" + str(time.time() - stime))
|
||||
return { 'id': currently_playing.json()["item"]["id"],
|
||||
'name': currently_playing.json()["item"]["name"],
|
||||
'artist': currently_playing.json()["item"]["artists"][0]["name"],
|
||||
@@ -107,20 +111,19 @@ def appdata():
|
||||
'is_playing': currently_playing.json()["is_playing"],
|
||||
'progress_ms': currently_playing.json()["progress_ms"],
|
||||
'duration_ms': currently_playing.json()["item"]["duration_ms"],
|
||||
'is_liked': requests.get("https://api.spotify.com/v1/me/tracks/contains?ids=" + currently_playing.json()["item"]["id"], headers=user_headers).json()[0]
|
||||
'is_liked': requests.get("https://api.spotify.com/v1/me/tracks/contains?ids=" + currently_playing.json()["item"]["id"], headers=user_headers).json()[0],
|
||||
'canvas': False,
|
||||
'fetchlyrics': 'fetch'
|
||||
}
|
||||
elif currently_playing.json()["is_playing"] is False:
|
||||
return { 'name': "Not Playing",
|
||||
'is_playing': False
|
||||
return { 'is_playing': False
|
||||
}
|
||||
else:
|
||||
return { 'name': "Error",
|
||||
'artist': "Error"
|
||||
}
|
||||
else:
|
||||
return { 'name': "Not Playing",
|
||||
'image': "https://cdn.psychologytoday.com/sites/default/files/styles/article-inline-half-caption/public/field_blog_entry_images/2022-02/pause.png",
|
||||
'is_playing': False
|
||||
return { 'is_playing': False
|
||||
}
|
||||
|
||||
@app.route('/control', methods=['POST'])
|
||||
@@ -157,7 +160,26 @@ def control():
|
||||
def icons(filename):
|
||||
return send_from_directory('icons', filename)
|
||||
|
||||
|
||||
@app.route('/canvas')
|
||||
def canvas():
|
||||
print("CANVAS")
|
||||
id = request.args.get('id')
|
||||
try:
|
||||
return { 'canvas_url': SpotifyCanvas.get_canvas_for_track(SpotifyCanvas.get_access_token(), id) }
|
||||
except AttributeError:
|
||||
return { 'canvas_url': None }
|
||||
|
||||
@app.route('/lyrics')
|
||||
def lyrics():
|
||||
name = request.args.get('name')
|
||||
artist = request.args.get('artist')
|
||||
if name and artist is not None:
|
||||
full_lyrics = syncedlyrics.search("[" + name + "] [" + artist + "]")
|
||||
else:
|
||||
return { 'lyrics': '' }
|
||||
if full_lyrics is None:
|
||||
return { 'lyrics': "no lyrics" }
|
||||
return { 'lyrics': full_lyrics }
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port=8888, debug=True)
|
||||
Reference in New Issue
Block a user