From 7adb79881e3d27bd2cf279d73bff0de392b5245c Mon Sep 17 00:00:00 2001 From: brandon Date: Wed, 8 May 2024 14:57:45 -0700 Subject: [PATCH] Revert "revert 49cd2b87355a0031b1376f1842d894c19f0f0d67" This reverts commit d3a4e97180c4886fd16e67b0935718fa2d5746f2. redoing previous revert --- .syncedlyrics/musixmatch_token.json | 6 +++- spotifycontroller.py | 49 ++++++++++++------------- templates/webapp.html | 55 ++++++++++++----------------- 3 files changed, 53 insertions(+), 57 deletions(-) diff --git a/.syncedlyrics/musixmatch_token.json b/.syncedlyrics/musixmatch_token.json index b60e598..c5b0e8d 100644 --- a/.syncedlyrics/musixmatch_token.json +++ b/.syncedlyrics/musixmatch_token.json @@ -1 +1,5 @@ -{"token": "240508682dd31a29b369cb3e363b37522b3f583074e0a18384854b", "expiration_time": 1715204997} \ No newline at end of file +<<<<<<< HEAD +{"token": "240508682dd31a29b369cb3e363b37522b3f583074e0a18384854b", "expiration_time": 1715204997} +======= +{"token": "240507dc1c1d721b422f329d191594415da1e4aec72fa0405c547e", "expiration_time": 1715112558} +>>>>>>> parent of d3a4e97 (revert 49cd2b87355a0031b1376f1842d894c19f0f0d67) diff --git a/spotifycontroller.py b/spotifycontroller.py index da52687..cca6a56 100644 --- a/spotifycontroller.py +++ b/spotifycontroller.py @@ -105,31 +105,32 @@ def appdata(): # needs to add an if statement that says if song is not playing then, becuase when nothing is playing the json response is different. if currently_playing.content: - if currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] == request.args.get('id'): - print("QUICK" + str(time.time() - stime)) - return { 'progress_ms': currently_playing.json()["progress_ms"], + if "is_playing" in currently_playing.json(): + if currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] == request.args.get('id'): + print("QUICK" + str(time.time() - stime)) + return { 'progress_ms': currently_playing.json()["progress_ms"], + } + elif currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] != request.args.get('id'): + print("FULL" + str(time.time() - stime)) + return { 'id': currently_playing.json()["item"]["id"], + 'name': currently_playing.json()["item"]["name"], + 'artist': currently_playing.json()["item"]["artists"][0]["name"], + 'album': currently_playing.json()["item"]["album"]["name"], + 'image': currently_playing.json()["item"]["album"]["images"][0]["url"], + 'is_playing': currently_playing.json()["is_playing"], + 'progress_ms': currently_playing.json()["progress_ms"], + 'duration_ms': currently_playing.json()["item"]["duration_ms"], + 'is_liked': requests.get("https://api.spotify.com/v1/me/tracks/contains?ids=" + currently_playing.json()["item"]["id"], headers=user_headers).json()[0], + 'canvas': False, + 'gofetch': 'fetch' + } + elif currently_playing.json()["is_playing"] is False: + return { 'is_playing': False + } + else: + return { 'name': "Error", + 'artist': "Error" } - elif currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] != request.args.get('id'): - print("FULL" + str(time.time() - stime)) - return { 'id': currently_playing.json()["item"]["id"], - 'name': currently_playing.json()["item"]["name"], - 'artist': currently_playing.json()["item"]["artists"][0]["name"], - 'album': currently_playing.json()["item"]["album"]["name"], - 'image': currently_playing.json()["item"]["album"]["images"][0]["url"], - 'is_playing': currently_playing.json()["is_playing"], - 'progress_ms': currently_playing.json()["progress_ms"], - 'duration_ms': currently_playing.json()["item"]["duration_ms"], - 'is_liked': requests.get("https://api.spotify.com/v1/me/tracks/contains?ids=" + currently_playing.json()["item"]["id"], headers=user_headers).json()[0], - 'canvas': False, - 'fetchlyrics': 'fetch' - } - elif currently_playing.json()["is_playing"] is False: - return { 'is_playing': False - } - else: - return { 'name': "Error", - 'artist': "Error" - } else: return { 'is_playing': False } diff --git a/templates/webapp.html b/templates/webapp.html index b44b0f3..dfe2547 100644 --- a/templates/webapp.html +++ b/templates/webapp.html @@ -1,5 +1,5 @@ - + @@ -7,19 +7,17 @@ - +
@@ -188,8 +186,10 @@ document.getElementById('canvas_url').style.display = "none"; document.getElementById('image').style.display = "flex"; } - getColors(data['image']) - getLyrics(data['name'], data['artist'], data['progress_ms'], data['fetchlyrics']) + if (data['gofetch'] !== undefined) { + getColors(data['image']) + } + getLyrics(data['name'], data['artist'], data['progress_ms'], data['gofetch']) } }); } @@ -214,8 +214,8 @@ } }); } - function getLyrics(name, artist, progress_ms, fetchlyrics) { - if (lyrics == undefined || fetchlyrics !== undefined && name !== undefined) { + function getLyrics(name, artist, progress_ms, gofetch) { + if (lyrics == undefined || gofetch !== undefined && name !== undefined) { $('#lyric').text(''); $.ajax({ url: '/lyrics', @@ -243,7 +243,7 @@ const colorThief = new ColorThief(); const img = document.getElementById('image'); img.crossOrigin = 'Anonymous'; -//set property: + animatedBackground = document.querySelector('.animated-background'); document.documentElement.style .setProperty('--my-variable-name', '100px'); @@ -254,26 +254,17 @@ getComputedStyle(document.documentElement) .getPropertyValue('--my-variable-name'); // returns value if (img.complete) { const color = colorThief.getColor(img); - oldColor = getComputedStyle(document.documentElement) - .getPropertyValue('--end-color'); - document.documentElement.style - .setProperty('--start-color', oldColor); - document.documentElement.style - .setProperty('--end-color', color); - document.body.classList.add('animateBackground'); // document.body.style.backgroundColor = 'rgb(' + color + ')'; + // document.body.style.backgroundColor = 'rgb(' + color + ')'; + animatedBackground.style.setProperty('--color', 'rgb(' + color + ')'); + animatedBackground.classList.add('update-color'); getLuminance(color); } else { img.addEventListener('load', function() { const color = colorThief.getColor(img); - oldColor = getComputedStyle(document.documentElement) - .getPropertyValue('--end-color'); - document.documentElement.style - .setProperty('--start-color', oldColor); - document.documentElement.style - .setProperty('--end-color', color); - document.body.classList.add('animateBackground'); // document.body.style.backgroundColor = 'rgb(' + color + ')'; + animatedBackground.style.setProperty('--color', 'rgb(' + color + ')'); + animatedBackground.classList.add('update-color'); getLuminance(color); }); }