mirror of
https://github.com/Alvin-Zilverstand/novatorem.git
synced 2026-03-06 13:24:56 +01:00
Recently playing mod
This commit is contained in:
16
README.md
16
README.md
@@ -8,13 +8,11 @@
|
|||||||
<td width="50%">
|
<td width="50%">
|
||||||
|
|
||||||
Software Developer currently working on cool projects at [Cast](https://blacktrax.cast-soft.com/showcase/). Everything here is available under the [Unlicense](https://choosealicense.com/licenses/unlicense/)!
|
Software Developer currently working on cool projects at [Cast](https://blacktrax.cast-soft.com/showcase/). Everything here is available under the [Unlicense](https://choosealicense.com/licenses/unlicense/)!
|
||||||
<br><p align="center">
|
<br><p align="center">
|
||||||
[](https://novac.dev)
|
[](https://novac.dev)
|
||||||
[](https://mailhide.io/e/5ck1H)<br>
|
[](https://mailhide.io/e/5ck1H)<br>
|
||||||
[](https://open.spotify.com/user/omnitenebris)
|
[](https://open.spotify.com/user/omnitenebris)
|
||||||
[](https://github.com/novatorem)
|
[](https://github.com/novatorem)
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
[//]: <> (The ` ` is to have Aphelion take up more space)
|
|
||||||
@@ -1,31 +1,30 @@
|
|||||||
from flask import Flask, Response, jsonify, render_template
|
|
||||||
from base64 import b64encode
|
|
||||||
|
|
||||||
from dotenv import load_dotenv, find_dotenv
|
|
||||||
load_dotenv(find_dotenv())
|
|
||||||
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
import random
|
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())
|
||||||
|
|
||||||
SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
|
SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
|
||||||
SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID")
|
SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID")
|
||||||
SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN")
|
SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN")
|
||||||
|
|
||||||
# scope user-read-currently-playing/user-read-recently-played
|
# Scopes:
|
||||||
|
# user-read-currently-playing
|
||||||
|
# user-read-recently-played
|
||||||
SPOTIFY_URL_REFRESH_TOKEN = "https://accounts.spotify.com/api/token"
|
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_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"
|
SPOTIFY_URL_RECENTLY_PLAY = "https://api.spotify.com/v1/me/player/recently-played?limit=10"
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
def getAuth():
|
def getAuth():
|
||||||
return b64encode(f"{SPOTIFY_CLIENT_ID}:{SPOTIFY_SECRET_ID}".encode()).decode("ascii")
|
return b64encode(f"{SPOTIFY_CLIENT_ID}:{SPOTIFY_SECRET_ID}".encode()).decode("ascii")
|
||||||
|
|
||||||
|
|
||||||
def refreshToken():
|
def refreshToken():
|
||||||
data = {
|
data = {
|
||||||
"grant_type": "refresh_token",
|
"grant_type": "refresh_token",
|
||||||
@@ -48,11 +47,8 @@ def recentlyPlayed():
|
|||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
def nowPlaying():
|
def nowPlaying():
|
||||||
|
|
||||||
token = refreshToken()
|
token = refreshToken()
|
||||||
|
|
||||||
headers = {"Authorization": f"Bearer {token}"}
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
|
|
||||||
response = requests.get(SPOTIFY_URL_NOW_PLAYING, headers=headers)
|
response = requests.get(SPOTIFY_URL_NOW_PLAYING, headers=headers)
|
||||||
|
|
||||||
if response.status_code == 204:
|
if response.status_code == 204:
|
||||||
@@ -82,24 +78,24 @@ def makeSVG(data):
|
|||||||
barCSS = barGen(barCount)
|
barCSS = barGen(barCount)
|
||||||
|
|
||||||
if data == {}:
|
if data == {}:
|
||||||
content_bar = ""
|
#contentBar = ""
|
||||||
recent_plays = recentlyPlayed()
|
recentlyPlayed = recentlyPlayed()
|
||||||
size_recent_play = len(recent_plays["items"])
|
recentLength = len(recentlyPlayed["items"])
|
||||||
idx = random.randint(0, size_recent_play - 1)
|
itemIndex = random.randint(0, recentLength - 1)
|
||||||
item = recent_plays["items"][idx]["track"]
|
item = recentlyPlayed["items"][itemIndex]["track"]
|
||||||
else:
|
else:
|
||||||
item = data["item"]
|
item = data["item"]
|
||||||
|
|
||||||
img = loadImageB64(item["album"]["images"][1]["url"])
|
image = loadImageB64(item["album"]["images"][1]["url"])
|
||||||
artistName = item["artists"][0]["name"].replace("&", "&")
|
artistName = item["artists"][0]["name"].replace("&", "&")
|
||||||
songName = item["name"].replace("&", "&")
|
songName = item["name"].replace("&", "&")
|
||||||
|
|
||||||
dataDict = {
|
dataDict = {
|
||||||
"content_bar": contentBar,
|
"contentBar": contentBar,
|
||||||
"css_bar": barCSS,
|
"barCSS": barCSS,
|
||||||
"artist_name": artistName,
|
"artistName": artistName,
|
||||||
"song_name": songName,
|
"songName": songName,
|
||||||
"img": img,
|
"image": image
|
||||||
}
|
}
|
||||||
|
|
||||||
return render_template("spotify.html.j2", **dataDict)
|
return render_template("spotify.html.j2", **dataDict)
|
||||||
@@ -107,7 +103,6 @@ def makeSVG(data):
|
|||||||
@app.route("/", defaults={"path": ""})
|
@app.route("/", defaults={"path": ""})
|
||||||
@app.route("/<path:path>")
|
@app.route("/<path:path>")
|
||||||
def catch_all(path):
|
def catch_all(path):
|
||||||
|
|
||||||
data = nowPlaying()
|
data = nowPlaying()
|
||||||
svg = makeSVG(data)
|
svg = makeSVG(data)
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.cover {
|
.cover {
|
||||||
|
position: absolute;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
|
z-index: -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#bars {
|
#bars {
|
||||||
@@ -99,16 +101,14 @@
|
|||||||
<div class="main">
|
<div class="main">
|
||||||
<a class="art" href="{}" target="_BLANK">
|
<a class="art" href="{}" target="_BLANK">
|
||||||
<center>
|
<center>
|
||||||
<img src="https://source.unsplash.com/random/500x500" class="cover" />
|
<img src="https://source.unsplash.com/random/500x500" class="cover"/>
|
||||||
</center>
|
</center>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<div class="song">Song</div>
|
<div class="song">Song</div>
|
||||||
<div class="artist">Arist</div>
|
<div class="artist">Arist</div>
|
||||||
<div id="bars">
|
<div id="bars">Bars</div>
|
||||||
{{content_bar|safe}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,9 @@
|
|||||||
color: #666;
|
color: #666;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-top: 3px;
|
margin-top: 3px;
|
||||||
white-space:nowrap;
|
white-space: nowrap;
|
||||||
overflow:hidden;
|
overflow: hidden;
|
||||||
text-overflow:ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.artist {
|
.artist {
|
||||||
@@ -53,6 +53,7 @@
|
|||||||
color: #b3b3b3;
|
color: #b3b3b3;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
|
margin-top: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo {
|
.logo {
|
||||||
@@ -97,19 +98,19 @@
|
|||||||
|
|
||||||
{{css_bar|safe}}
|
{{css_bar|safe}}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<a class="art" href="{}" target="_BLANK">
|
<a class="art" href="{}" target="_BLANK">
|
||||||
<center>
|
<center>
|
||||||
<img src="data:image/png;base64, {{img}}" class="cover" />
|
<img src="data:image/png;base64, {{image}}" class="cover" />
|
||||||
</center>
|
</center>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div class="text">
|
<div class="text">
|
||||||
<div class="song">{{song_name}}</div>
|
<div class="song">{{songName}}</div>
|
||||||
<div class="artist">{{artist_name}}</div>
|
<div class="artist">{{artistName}}</div>
|
||||||
<div id="bars">
|
<div id="bars">
|
||||||
{{content_bar|safe}}
|
{{contentBar|safe}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.5 KiB |
Reference in New Issue
Block a user