Browse Source

Mini mode

add-license-1
novatorem 5 years ago
parent
commit
27fa33aa2f
2 changed files with 17 additions and 26 deletions
  1. +4
    -13
      api/spotify-playing.py
  2. +13
    -13
      api/templates/spotify.html.j2

+ 4
- 13
api/spotify-playing.py View File

@ -23,12 +23,10 @@ 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",
"refresh_token": SPOTIFY_REFRESH_TOKEN, "refresh_token": SPOTIFY_REFRESH_TOKEN,
@ -39,8 +37,7 @@ def refreshToken():
response = requests.post(SPOTIFY_URL_REFRESH_TOKEN, data=data, headers=headers) response = requests.post(SPOTIFY_URL_REFRESH_TOKEN, data=data, headers=headers)
return response.json()["access_token"] return response.json()["access_token"]
def get_recently_play():
def recentlyPlayed():
token = refreshToken() token = refreshToken()
headers = {"Authorization": f"Bearer {token}"} headers = {"Authorization": f"Bearer {token}"}
response = requests.get(SPOTIFY_URL_RECENTLY_PLAY, headers=headers) response = requests.get(SPOTIFY_URL_RECENTLY_PLAY, headers=headers)
@ -67,8 +64,7 @@ def barGen(barCount=85):
barCSS = "" barCSS = ""
left = 1 left = 1
for i in range(1, barCount + 1): for i in range(1, barCount + 1):
anim = random.randint(350, 500)
anim = random.randint(1000, 1350)
barCSS += ".bar:nth-child({}) {{ left: {}px; animation-duration: {}ms; }}".format( barCSS += ".bar:nth-child({}) {{ left: {}px; animation-duration: {}ms; }}".format(
i, left, anim i, left, anim
) )
@ -81,15 +77,13 @@ def loadImageB64(url):
return b64encode(resposne.content).decode("ascii") return b64encode(resposne.content).decode("ascii")
def makeSVG(data): def makeSVG(data):
height = 445
barCount = 85
barCount = 82
contentBar = "".join(["<div class='bar'></div>" for i in range(barCount)]) contentBar = "".join(["<div class='bar'></div>" for i in range(barCount)])
barCSS = barGen(barCount) barCSS = barGen(barCount)
if data == {}: if data == {}:
content_bar = "" content_bar = ""
recent_plays = get_recently_play()
recent_plays = recentlyPlayed()
size_recent_play = len(recent_plays["items"]) size_recent_play = len(recent_plays["items"])
idx = random.randint(0, size_recent_play - 1) idx = random.randint(0, size_recent_play - 1)
item = recent_plays["items"][idx]["track"] item = recent_plays["items"][idx]["track"]
@ -99,11 +93,8 @@ def makeSVG(data):
img = loadImageB64(item["album"]["images"][1]["url"]) img = loadImageB64(item["album"]["images"][1]["url"])
artistName = item["artists"][0]["name"].replace("&", "&amp;") artistName = item["artists"][0]["name"].replace("&", "&amp;")
songName = item["name"].replace("&", "&amp;") songName = item["name"].replace("&", "&amp;")
url = item["external_urls"]["spotify"]
dataDict = { dataDict = {
"height": height,
"num_bar": barCount,
"content_bar": contentBar, "content_bar": contentBar,
"css_bar": barCSS, "css_bar": barCSS,
"artist_name": artistName, "artist_name": artistName,


+ 13
- 13
api/templates/spotify.html.j2 View File

@ -1,5 +1,5 @@
<svg width="580" height="233" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<foreignObject width="580" height="233">
<svg width="580" height="133" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<foreignObject width="580" height="133">
<div xmlns="http://www.w3.org/1999/xhtml" class="container"> <div xmlns="http://www.w3.org/1999/xhtml" class="container">
<style> <style>
div { div {
@ -30,23 +30,23 @@
.art { .art {
float: left; float: left;
width: 44%;
margin-left: -15px;
width: 24%;
margin-left: -5px;
} }
.artist {
.song {
font-size: 24px; font-size: 24px;
color: #b3b3b3;
color: #666;
text-align: left; text-align: left;
margin-top: 5px;
margin-bottom: 5px;
margin-top: 3px;
} }
.song {
font-size: 28px;
color: #666;
.artist {
font-size: 20px;
color: #b3b3b3;
text-align: left; text-align: left;
margin-top: 60px;
margin-top: -3px;
margin-bottom: 5px;
} }
.logo { .logo {
@ -67,7 +67,7 @@
} }
.bar { .bar {
background: #53b14f;
background: #1DB954cc;
bottom: 1px; bottom: 1px;
height: 3px; height: 3px;
position: absolute; position: absolute;


Loading…
Cancel
Save