Nomineren even opgeleukt

En spotify.link shortlinks worden geaccepteerd. Mogelijk.
This commit is contained in:
2024-02-25 00:20:44 +01:00
parent b9e0177c98
commit 7f199b6886
6 changed files with 61 additions and 11 deletions
+20 -4
View File
@@ -45,13 +45,23 @@ class NominateView(LoginRequiredMixin, View):
def get(self, request):
return TemplateResponse(request, "Nominate.html", {})
def post(self, request):
spotify_link = self.request.POST['spotify_link']
m = re.match(r"^https:\/\/open.spotify.com\/track\/(\w+)\??", spotify_link)
spotify_id = m.group(1)
try:
spotify_link = self.request.POST['spotify_link']
# Short url?
if re.match(r"^https:\/\/spotify.link.*", spotify_link):
spotify_link = spt.unshort(spotify_link)
m = re.match(r"^https:\/\/open.spotify.com\/track\/([a-zA-Z0-9]+)\??", spotify_link)
spotify_id = m.group(1)
except:
return TemplateResponse(request, "Nominate.html", {"error": "Geef een geldige spotify link op!"})
try:
track = Track.all_tracks.get(pk=spotify_id)
if track.old:
track.old = False
track.save()
return TemplateResponse(request, "Nominate.html", {
"warning": "Hey een klassieker.",
"nominated": track
@@ -61,7 +71,13 @@ class NominateView(LoginRequiredMixin, View):
"nominated": track
})
except Track.DoesNotExist:
json = spt.get_song_info(spotify_id)
try:
json = spt.get_song_info(spotify_id)
except:
return TemplateResponse(request, "Nominate.html", {"error": "Fout bij het ophalen van het liedje."})
print(json)
print("hey")
# Album artists
album_artists = []