From 7f199b6886de17191b501917012037cdde662692 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 25 Feb 2024 00:20:44 +0100 Subject: [PATCH] Nomineren even opgeleukt En spotify.link shortlinks worden geaccepteerd. Mogelijk. --- playlist/spotify.py | 8 ++++++++ playlist/static/bsod.css | 3 ++- playlist/static/img/sound.png | Bin 0 -> 394 bytes playlist/static/style.css | 16 ++++++++++++++++ playlist/templates/Nominate.html | 21 +++++++++++++++------ playlist/views.py | 24 ++++++++++++++++++++---- 6 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 playlist/static/img/sound.png diff --git a/playlist/spotify.py b/playlist/spotify.py index 80b3074..30f7ba4 100644 --- a/playlist/spotify.py +++ b/playlist/spotify.py @@ -1,5 +1,6 @@ import requests import os +import re from datetime import datetime, timedelta from dotenv import load_dotenv @@ -34,6 +35,12 @@ class Spotify(): self.valid_until = datetime.now() + timedelta(seconds=data["expires_in"]-300) return self.token + def unshort(self, url): + """Converts a spotify.link url into a normal spotify ID""" + r = requests.get(url, allow_redirects=False) + r.raise_for_status() + return r.headers["Location"] + def get_song_info(self, spotify_id): token = self.get_token() url = 'https://api.spotify.com/v1/tracks/' + spotify_id @@ -42,4 +49,5 @@ class Spotify(): 'Authorization': 'Bearer ' + token } r = requests.get(url, headers=headers) + r.raise_for_status() return r.json() diff --git a/playlist/static/bsod.css b/playlist/static/bsod.css index 0431c82..1138fb2 100644 --- a/playlist/static/bsod.css +++ b/playlist/static/bsod.css @@ -19,7 +19,8 @@ body { #bsod { display: block; - width: 70vw; + width: max(70vw, 400px); + max-width: 800px; flex-shrink: 1; gap: 1rem; display: flex; diff --git a/playlist/static/img/sound.png b/playlist/static/img/sound.png new file mode 100644 index 0000000000000000000000000000000000000000..48fb1f352e4168ab3ce00741cb05d74b2003a99c GIT binary patch literal 394 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPF^mS!_#3sdHqOkl& zBhW^MR8JSj5RU7ny{CB_40xPt8?1TfTTirNSYYJ9$`cS}mhfM+K>4Ge|F*>p1xuI( zLu2bAvrT$dEe&{dR)^vEoRnoIA7foL3cn{^HU6pM$8_t=sbi0)<}g3GyiP)N>#4XI zU!+$C_3&p33hv&d@k$S9p=yb1L`h0wNvc(HQ7VvPFfuT-&^0jAH8Kk^Ft9Q;vNAT( oH88O9$>FVdQ&MBb@05BPO`2YX_ literal 0 HcmV?d00001 diff --git a/playlist/static/style.css b/playlist/static/style.css index fcc40d0..1b64d84 100644 --- a/playlist/static/style.css +++ b/playlist/static/style.css @@ -30,6 +30,22 @@ input[type=submit] { filter: contrast(1); } +input#spotify-input { + width: 100%; + margin-bottom: 10px; +} + +input#spotify-input + input[type=submit]{ + background-image: url(img/sound.png); + background-repeat:no-repeat; + padding: 4px 8px 4px 24px; + height: 16px; + min-width: 0; + background-position: 4px 50%; + font-weight: bold; + +} + #bsod, .hide { display: none; } diff --git a/playlist/templates/Nominate.html b/playlist/templates/Nominate.html index 9307cfa..70e3031 100644 --- a/playlist/templates/Nominate.html +++ b/playlist/templates/Nominate.html @@ -7,19 +7,28 @@ Nomineren {% block main-content %}
{% csrf_token %} - - +

Vul een spotify link in om een nummer te nomineren.

+

Deze link mag zowel naar open.spotify.com gaan als naar spotify.link

+ +
-{% if nominated %} +{% if nominated or error or warning %}