mirror of
https://github.com/Alvin-Zilverstand/novatorem.git
synced 2026-03-06 02:57:12 +01:00
Hidden EQ Bar option
This commit is contained in:
@@ -1,31 +1,30 @@
|
||||
from flask import Flask, Response, jsonify, render_template
|
||||
from base64 import b64encode
|
||||
import os
|
||||
import json
|
||||
import random
|
||||
import requests
|
||||
|
||||
from base64 import b64encode
|
||||
from dotenv import load_dotenv, find_dotenv
|
||||
from flask import Flask, Response, jsonify, render_template
|
||||
|
||||
load_dotenv(find_dotenv())
|
||||
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
|
||||
# Spotify:
|
||||
# user-read-currently-playing
|
||||
# user-read-recently-played
|
||||
SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
|
||||
SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID")
|
||||
SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN")
|
||||
|
||||
# scope user-read-currently-playing/user-read-recently-played
|
||||
SPOTIFY_URL_REFRESH_TOKEN = "https://accounts.spotify.com/api/token"
|
||||
SPOTIFY_URL_NOW_PLAYING = "https://api.spotify.com/v1/me/player/currently-playing"
|
||||
SPOTIFY_URL_RECENTLY_PLAY = "https://api.spotify.com/v1/me/player/recently-played?limit=10"
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
def getAuth():
|
||||
return b64encode(f"{SPOTIFY_CLIENT_ID}:{SPOTIFY_SECRET_ID}".encode()).decode("ascii")
|
||||
|
||||
|
||||
def refreshToken():
|
||||
data = {
|
||||
"grant_type": "refresh_token",
|
||||
@@ -48,11 +47,8 @@ def recentlyPlayed():
|
||||
return response.json()
|
||||
|
||||
def nowPlaying():
|
||||
|
||||
token = refreshToken()
|
||||
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
response = requests.get(SPOTIFY_URL_NOW_PLAYING, headers=headers)
|
||||
|
||||
if response.status_code == 204:
|
||||
@@ -82,11 +78,11 @@ def makeSVG(data):
|
||||
barCSS = barGen(barCount)
|
||||
|
||||
if data == {}:
|
||||
content_bar = ""
|
||||
recent_plays = recentlyPlayed()
|
||||
size_recent_play = len(recent_plays["items"])
|
||||
idx = random.randint(0, size_recent_play - 1)
|
||||
item = recent_plays["items"][idx]["track"]
|
||||
#contentBar = "" #Shows/Hides the EQ bar if no song is currently playing
|
||||
recentPlays = recentlyPlayed()
|
||||
recentPlaysLength = len(recentPlays["items"])
|
||||
itemIndex = random.randint(0, recentPlaysLength - 1)
|
||||
item = recentPlays["items"][itemIndex]["track"]
|
||||
else:
|
||||
item = data["item"]
|
||||
|
||||
@@ -95,11 +91,11 @@ def makeSVG(data):
|
||||
songName = item["name"].replace("&", "&")
|
||||
|
||||
dataDict = {
|
||||
"content_bar": contentBar,
|
||||
"css_bar": barCSS,
|
||||
"artist_name": artistName,
|
||||
"song_name": songName,
|
||||
"img": img,
|
||||
"contentBar": contentBar,
|
||||
"barCSS": barCSS,
|
||||
"artistName": artistName,
|
||||
"songName": songName,
|
||||
"image": image,
|
||||
}
|
||||
|
||||
return render_template("spotify.html.j2", **dataDict)
|
||||
@@ -107,7 +103,6 @@ def makeSVG(data):
|
||||
@app.route("/", defaults={"path": ""})
|
||||
@app.route("/<path:path>")
|
||||
def catch_all(path):
|
||||
|
||||
data = nowPlaying()
|
||||
svg = makeSVG(data)
|
||||
|
||||
|
||||
@@ -95,21 +95,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
{{css_bar|safe}}
|
||||
{{barCSS|safe}}
|
||||
</style>
|
||||
|
||||
<div class="main">
|
||||
<a class="art" href="{}" target="_BLANK">
|
||||
<center>
|
||||
<img src="data:image/png;base64, {{img}}" class="cover" />
|
||||
<img src="data:image/png;base64, {{image}}" class="cover" />
|
||||
</center>
|
||||
</a>
|
||||
|
||||
<div class="text">
|
||||
<div class="song">{{song_name}}</div>
|
||||
<div class="artist">{{artist_name}}</div>
|
||||
<div class="song">{{songName}}</div>
|
||||
<div class="artist">{{artistName}}</div>
|
||||
<div id="bars">
|
||||
{{content_bar|safe}}
|
||||
{{contentBar|safe}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Reference in New Issue
Block a user