Files
novatorem/api/spotify.py

188 lines
16 KiB
Python
Raw Permalink Normal View History

Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
from io import BytesIO
2020-08-23 11:23:09 -04:00
import os
import json
import random
import requests
2020-08-15 22:22:39 -04:00
Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
from colorthief import ColorThief
2020-08-23 11:23:09 -04:00
from base64 import b64encode
2020-08-23 11:18:07 -04:00
from dotenv import load_dotenv, find_dotenv
2022-12-12 10:52:17 -05:00
from flask import Flask, Response, render_template, request
2020-08-15 22:22:39 -04:00
2020-08-23 11:23:09 -04:00
load_dotenv(find_dotenv())
2020-08-23 11:18:07 -04:00
2020-09-01 19:13:53 -04:00
# Spotify scopes:
2020-08-23 11:23:09 -04:00
# user-read-currently-playing
# user-read-recently-played
2021-01-28 19:27:25 +01:00
PLACEHOLDER_IMAGE = "iVBORw0KGgoAAAANSUhEUgAAA4QAAAOEBAMAAAALYOIIAAAAFVBMVEXm5ub///8AAAAxMTG+vr6RkZFfX1/R+IhpAAAfE0lEQVR42uzdS3fayBaGYVUHZ1w6AY+zSoYxAZsxxDhjQ8DjGBv//59wBPgeB5fu2rvevfqc1V93LzvSg6Sq2pKI4kPZ6FBE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TJJp9bn5JG78DPGU3mGzKGQlu+/2kljDIbnlmZhBu1hJkN+0IJfUZuSSSSMDXMNC5NZJ5Ive5ec0YmYVbDqUhCv3vxF0IJI5NpXLoQSej3kP2tVMJshkOJhJ5fGzoUS5jOD/3Ppd9FEvo9WXhuS/y9+79qFPVfa+uLJBx5Drdz/6LY7F8MbP7xb63dvXm24nu9M92IKI3Q+g63s384HmNnPr96eBin9f7lUePxw8N2vntztzHVHpTeX+onkdD3BYjZnqDcTZHTk+V8dTdOfD4g44vV/NG8mu299F7olkfo+6qLPxnOnLHtzNc3d1m7PclkPZ9Pzf7nlb69nn38W4GEX7zXnnx/sr0q8jbf5GG7nr58FkrbXs+pxQ95hN7vsEyM10/urh+KPyaWMq5K316/K8ZZdYSV9bGWvvv19vOf3Ml+8vxnjSfb6GUYW8b2el0OH99dIqrl67108dmzW/ZX6S99nWxnJW6v1wxfIGGGl6qbYz+qU9FLe8crU9r2XnpfL0QRZnh93nn8rze9RuW+S+v9sTh/vsu62PZ6betCHGGG9+Ins4+ex0gHoL9dxZWs5ubQ/iu2vUuVhFm+OPT8gy8E6Vb72vOXQ3G9ew14we312dg/4gj/y7If/7rBy97UA7
Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
PLACEHOLDER_URL = "https://source.unsplash.com/random/300x300/?aerial"
2020-08-15 22:22:39 -04:00
SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID")
SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID")
SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN")
SPOTIFY_TOKEN = ""
2021-01-28 19:27:25 +01:00
2021-07-11 08:49:18 +03:00
FALLBACK_THEME = "spotify.html.j2"
2020-09-01 19:13:53 -04:00
REFRESH_TOKEN_URL = "https://accounts.spotify.com/api/token"
NOW_PLAYING_URL = "https://api.spotify.com/v1/me/player/currently-playing"
RECENTLY_PLAYING_URL = (
"https://api.spotify.com/v1/me/player/recently-played?limit=10"
)
2020-08-15 22:22:39 -04:00
app = Flask(__name__)
2020-09-01 19:13:53 -04:00
2020-08-15 22:22:39 -04:00
def getAuth():
2020-09-01 19:13:53 -04:00
return b64encode(f"{SPOTIFY_CLIENT_ID}:{SPOTIFY_SECRET_ID}".encode()).decode(
"ascii"
)
2020-08-15 22:22:39 -04:00
def refreshToken():
data = {
"grant_type": "refresh_token",
"refresh_token": SPOTIFY_REFRESH_TOKEN,
}
headers = {"Authorization": "Basic {}".format(getAuth())}
response = requests.post(
REFRESH_TOKEN_URL, data=data, headers=headers).json()
2020-09-11 17:18:40 -04:00
try:
return response["access_token"]
2020-09-11 17:18:40 -04:00
except KeyError:
print(json.dumps(response))
2020-09-11 17:18:40 -04:00
print("\n---\n")
raise KeyError(str(response))
2020-08-15 22:22:39 -04:00
2020-09-01 19:13:53 -04:00
def get(url):
global SPOTIFY_TOKEN
2020-08-15 22:22:39 -04:00
if (SPOTIFY_TOKEN == ""):
SPOTIFY_TOKEN = refreshToken()
2020-08-15 22:22:39 -04:00
response = requests.get(
url, headers={"Authorization": f"Bearer {SPOTIFY_TOKEN}"})
2020-09-01 19:13:53 -04:00
if response.status_code == 401:
SPOTIFY_TOKEN = refreshToken()
response = requests.get(
url, headers={"Authorization": f"Bearer {SPOTIFY_TOKEN}"}).json()
return response
elif response.status_code == 204:
raise Exception(f"{url} returned no data.")
else:
return response.json()
2020-08-15 22:22:39 -04:00
2020-09-01 19:13:53 -04:00
2020-08-15 22:22:39 -04:00
def barGen(barCount):
barCSS = ""
left = 1
for i in range(1, barCount + 1):
anim = random.randint(500, 1000)
# below code generates random cubic-bezier values
x1 = random.random()
y1 = random.random()*2
x2 = random.random()
y2 = random.random()*2
2020-09-01 19:13:53 -04:00
barCSS += (
".bar:nth-child({}) {{ left: {}px; animation-duration: 15s, {}ms; animation-timing-function: ease, cubic-bezier({},{},{},{}); }}".format(
i, left, anim, x1, y1, x2, y2
2020-09-01 19:13:53 -04:00
)
2020-08-15 22:22:39 -04:00
)
left += 4
return barCSS
Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
def gradientGen(albumArtURL, color_count):
colortheif = ColorThief(BytesIO(requests.get(albumArtURL).content))
palette = colortheif.get_palette(color_count)
return palette
2021-07-11 08:49:18 +03:00
def getTemplate():
try:
file = open("api/templates.json", "r")
templates = json.loads(file.read())
2021-07-11 08:49:18 +03:00
return templates["templates"][templates["current-theme"]]
except Exception as e:
2022-12-12 10:52:17 -05:00
print(f"Failed to load templates.\r\n```{e}```")
2021-07-11 08:49:18 +03:00
return FALLBACK_THEME
2020-08-15 22:22:39 -04:00
def loadImageB64(url):
response = requests.get(url)
return b64encode(response.content).decode("ascii")
2020-08-15 22:22:39 -04:00
2020-09-01 19:13:53 -04:00
def makeSVG(data, background_color, border_color):
2020-08-23 13:08:24 -04:00
barCount = 84
contentBar = "".join(["<div class='bar'></div>" for _ in range(barCount)])
2020-08-15 22:22:39 -04:00
barCSS = barGen(barCount)
if not "is_playing" in data:
Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
#contentBar = "" #Shows/Hides the EQ bar if no song is currently playing
currentStatus = "Recently played:"
recentPlays = get(RECENTLY_PLAYING_URL)
2020-08-23 11:23:09 -04:00
recentPlaysLength = len(recentPlays["items"])
itemIndex = random.randint(0, recentPlaysLength - 1)
item = recentPlays["items"][itemIndex]["track"]
2020-08-15 22:22:39 -04:00
else:
item = data["item"]
2020-08-25 19:21:33 -04:00
currentStatus = "Vibing to:"
if item["album"]["images"] == []:
image = PLACEHOLDER_IMAGE
Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
barPalette = gradientGen(PLACEHOLDER_URL, 4)
songPalette = gradientGen(PLACEHOLDER_URL, 2)
else:
image = loadImageB64(item["album"]["images"][1]["url"])
Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
barPalette = gradientGen(item["album"]["images"][1]["url"], 4)
songPalette = gradientGen(item["album"]["images"][1]["url"], 2)
2020-08-15 22:22:39 -04:00
artistName = item["artists"][0]["name"].replace("&", "&amp;")
songName = item["name"].replace("&", "&amp;")
songURI = item["external_urls"]["spotify"]
artistURI = item["artists"][0]["external_urls"]["spotify"]
2020-08-15 22:22:39 -04:00
dataDict = {
2020-08-23 11:23:09 -04:00
"contentBar": contentBar,
"barCSS": barCSS,
"artistName": artistName,
"songName": songName,
"songURI": songURI,
"artistURI": artistURI,
2020-08-23 11:23:09 -04:00
"image": image,
2020-09-01 19:13:53 -04:00
"status": currentStatus,
"background_color": background_color,
Sync changes from master branch (#67) * Fixes index out of bounds bug and adds global placeholder variable * Adds placeholder image * Update spotify.html.j2 * Easy way to add more thems, added a dark theme * Easy theme selection * Themes and Templates setup guide * Themes and Templates (#1) * Update templates.json * Update templates.json * Update templates.json * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update spotify.py * Update templates.json * Add spotify link for song and artist - Added Spotify link to song title - Added Spotify logo svg that takes the user to Spotify to listen to the currently playing song - Added Spotify link to song artist * Added support for Docker - Updated SetUp.md with a "Run locally with Docker" section - Moved requirements.txt to the root of the repo since some hosting services require the file to be there (eg. Heroku https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-python) * Apply codefactor.io suggestions - Use specific python docker image (less error prone) - Use '--no-cache-dir' flag in pip since pip cache makes docker images larger * Prepare for Heroku deployment - Heroku will bind the app to $PORT - Add parameter to API to be able to customize the background color of the svg - Add parameter to API to be able to customize the border color of the svg - Add SetUp.md section on how to customize your card with URL parameters Update SetUp.md with a section on how to customize the card * Updated setup instructions and removed default spotify logo * Change mail provider to custom built one * Give Kudos in README * Update eq if currently listening to or not * Preview spotify logo * Add header * Give room for header change color of status for contrast * Update currentStatus * Test height proporty * change colors + margin * Add gradient to eq * Add background to bars * Give transparency fill to bars * Re-add background to bars to evaluate interactions * Fix background for all bars to apply gradients * Fix syntax error * Zoom in background for gradient scroll * Slow animation of gradient * Set gradient animation to run first, then sound * Modify zoom of bar background * absolute bar travel time * remove alternate animation for bars * uncenter start background position * remove sound animation for debug * Zoom out background * remove random.radient * Remove debug * Only randomize sound animation duration * Speed up and add more bars * Actually speed them up * ZOOOOOM * change bar animation to ease * Slow down bar speeds * Update README.md * set bar animation to ease-out * Set bars to ease in * Speed up gradient animation * Speed up gradient animation * Get only last played song if not listening * Fix syntax error on itemIndex declaration * Generate random bezier for bar animations * Expand speed window for bars * Pan time window to favor fast * add preview and prepare for PR * Add preview and prepare for PR * change preview.mp4 to .gif * Split away from table * General improvements - Refresh token only when it expires (saves 1 request most of the time) - Apply suggestions from python lsp-server * Add album-cover related gradients (#66) * Visualize light theme * sync with gradients branch most likely will revert * Sorry light mode I am too tired for you * Hope to add average color for the gradient * nth child for all bar in bars real bar foobar bar! * Make the EQ bar colors be based upon the album cover * Fix req.txt * silly imports, why are you so... you * Give the song title a nice gradient * textPalette -> songPalette * Dark mode compatibility * prevent .env changes from being made to the docker image, unless running locally * Add gradient to the text in the song name, attempt animation * remove animation from text * frantic commenting * Why does this work on a contianer from my computer but not on vercel * aha! * Add in some nice animations for the colors * Add in some nice animations for the text colors * Add glow keyframes for the text * remove glow animation * remove text shadow entirely * force commit to rebuild vercel? * undo last change,(literally nothing) * Speed up artist gradient * Only set the barPalette if there is no song currently playing Attempt to set songPalette to the recently playing url, but there may be a requirement for a barPalette * Give barPalette some love * Add placeholder URL if no image exists * Enable personalized changes * Enable personalized changes * Revert personalized changes * Revert margin change --------- Co-authored-by: Lloyd Owen <2387296o@student.gla.ac.uk> Co-authored-by: Andrew Novac <anovaec@gmail.com> Co-authored-by: Ethan Shoham <69990209+Ethan-S-Dev@users.noreply.github.com> Co-authored-by: Ethan Shoham <ethan380s@gmail.com> Co-authored-by: AlexandrosAlexiou <alex.alexiouu@gmail.com> Co-authored-by: Alexander Hamilton <65139378+GalexY727@users.noreply.github.com> Co-authored-by: Alexander Hamilton <a.hamilton72006@gmail.com>
2023-06-01 20:51:41 -04:00
"border_color": border_color,
"barPalette": barPalette,
"songPalette": songPalette
2020-08-15 22:22:39 -04:00
}
2021-07-11 08:49:18 +03:00
return render_template(getTemplate(), **dataDict)
2020-08-15 22:22:39 -04:00
2020-09-01 19:13:53 -04:00
2020-08-15 22:22:39 -04:00
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
@app.route('/with_parameters')
2020-08-15 22:22:39 -04:00
def catch_all(path):
background_color = request.args.get('background_color') or "181414"
border_color = request.args.get('border_color') or "181414"
try:
data = get(NOW_PLAYING_URL)
except Exception:
data = get(RECENTLY_PLAYING_URL)
svg = makeSVG(data, background_color, border_color)
2020-08-15 22:22:39 -04:00
resp = Response(svg, mimetype="image/svg+xml")
resp.headers["Cache-Control"] = "s-maxage=1"
return resp
2020-09-01 19:13:53 -04:00
2020-08-15 22:22:39 -04:00
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True, port=os.getenv("PORT") or 5000)