auto reload on failure

This commit is contained in:
Brandon4466
2024-04-27 17:23:42 -07:00
parent ad989ad50b
commit cc25fcaa34
5 changed files with 40 additions and 11 deletions

Binary file not shown.

2
code
View File

@@ -1 +1 @@
AQDU_0NUgm9-EMYMDBYUTnBApWyYO6m4EDUExbHzjM_CcVkoGptsE69uePQ7ejw5NooRTCpQqIU7ZfOTfE5Nx8zj6amQBFRkgv7vMa5ViqCbH_hqos--D6mj-eG3jqW-sf-Oyq0vmPUaam6R0fB--ghWzM8EG8SRVQBGTnEN-OLf1PBX5I1sOS22GXrMud5BcFziAiYQxHn_GcnPXEyXigkHAsk60PFiWDUwW6fLdUKW2FtyJnnYH01al28eex1QEeqr2gg8e5ht9XGKfQej0ciFM62ESwIbpDZDi6bWdSk AQCZgUjpd41T5OxjgCR08o-WIKMoJVOkKQnnXWWyCMPfr9AF8OOauNn9wYPX4sFKpWxINeHmeimsNw7c2e1HVCu038drk_o9K-0rdgtG7QlQc02ENsbkJC5tjr3M40-oxdmoz203NA_qj1J_DyQBx6TA-FbHS8WXiDTIn9pB3IpVNCSCf8kubjn6MOvDU8w6uXyjwCDLUBN5ptfARe4yFEXKNlgxgQcbAsj0DPpS4owhvYbo-tAwINmyJPuO61-TUbQ6U5qWLN7A1UkhbAkX0kJfFd3WnCsGiDpQmgLmmb8

View File

@@ -89,10 +89,13 @@ def callback():
def appdata(): def appdata():
global access_token global access_token
stime = time.time() stime = time.time()
user_headers = { try:
"Authorization": "Bearer " + access_token, user_headers = {
"Content-Type": "application/json" "Authorization": "Bearer " + access_token,
} "Content-Type": "application/json"
}
except NameError:
return { 'reload': True }
currently_playing = requests.get("https://api.spotify.com/v1/me/player/currently-playing", headers=user_headers) currently_playing = requests.get("https://api.spotify.com/v1/me/player/currently-playing", headers=user_headers)
if currently_playing.content: if currently_playing.content:
@@ -100,8 +103,7 @@ def appdata():
print("QUICK" + str(time.time() - stime)) print("QUICK" + str(time.time() - stime))
return { 'progress_ms': currently_playing.json()["progress_ms"], 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'): elif currently_playing.json()["is_playing"] is True and currently_playing.json()["item"]["id"] != request.args.get('id'):
print("FULL" + str(time.time() - stime)) print("FULL" + str(time.time() - stime))
return { 'id': currently_playing.json()["item"]["id"], return { 'id': currently_playing.json()["item"]["id"],
'name': currently_playing.json()["item"]["name"], 'name': currently_playing.json()["item"]["name"],

View File

@@ -5,12 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SpotifyJS</title> <title>SpotifyJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/color-thief/2.3.0/color-thief.umd.js"></script>
<style> <style>
.progress-container { .progress-container {
width: 100%; width: 100%;
background-color: #ddd; background-color: #ddd;
} }
.progress-bar { .progress-bar {
width: 0%; width: 0%;
height: 4px; height: 4px;
@@ -51,6 +51,7 @@
.buttons { .buttons {
display: initial; display: initial;
padding-top: 10%; padding-top: 10%;
/* mix-blend-mode: difference; */
} }
.total { .total {
display: flex; display: flex;
@@ -86,7 +87,7 @@
</div> </div>
</div> </div>
<script> <script>
let id, is_playing, is_liked, duration_ms, canvas_url, lyrics; let id, is_playing, is_liked, duration_ms, canvas_url, lyrics, progress_ms;
// Function to update the values every second // Function to update the values every second
function updateValues() { function updateValues() {
$.ajax({ $.ajax({
@@ -117,6 +118,12 @@
if (data['duration_ms'] !== undefined) { if (data['duration_ms'] !== undefined) {
duration_ms = data['duration_ms']; duration_ms = data['duration_ms'];
} }
if (data['progress_ms'] !== undefined) {
progress_ms = data['progress_ms'];
}
if (data['reload'] == true) {
location.reload();
}
document.getElementById('progress_bar').style.width = (data['progress_ms'] / duration_ms) * 100 + '%'; document.getElementById('progress_bar').style.width = (data['progress_ms'] / duration_ms) * 100 + '%';
// document.getElementById('progress_bar').textContent = (Math.floor(data['progress_ms'] / (1000 * 60)) % 60) + ':' + (Math.floor((data['progress_ms'] / 1000) % 60)).toString().padStart(2, '0'); // document.getElementById('progress_bar').textContent = (Math.floor(data['progress_ms'] / (1000 * 60)) % 60) + ':' + (Math.floor((data['progress_ms'] / 1000) % 60)).toString().padStart(2, '0');
@@ -141,6 +148,7 @@
document.getElementById('canvas_url').style.display = "none"; document.getElementById('canvas_url').style.display = "none";
document.getElementById('image').style.display = ""; document.getElementById('image').style.display = "";
} }
getColors(data['image'])
getLyrics(data['name'], data['artist'], data['progress_ms'], data['fetchlyrics']) getLyrics(data['name'], data['artist'], data['progress_ms'], data['fetchlyrics'])
} }
}); });
@@ -191,6 +199,24 @@
} }
} }
} }
function getColors(image) {
const colorThief = new ColorThief();
const img = document.getElementById('image');
img.crossOrigin = 'Anonymous';
if (img.complete) {
const color = colorThief.getColor(img);
document.body.style.backgroundColor = 'rgb(' + color + ')';
} else {
img.addEventListener('load', function() {
const color = colorThief.getColor(img);
document.body.style.backgroundColor = 'rgb(' + color + ')';
});
}
}
// function getLuminance() {
// }
// BUTTONS // BUTTONS
$('#playpause').click(function() { $('#playpause').click(function() {
$.ajax({ $.ajax({
@@ -222,11 +248,12 @@
}); });
}); });
$('#previous').click(function() { $('#previous').click(function() {
console.log(progress_ms)
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: '/control', url: '/control',
// data: {command: (data['progress_ms'] < 5000) ? 'restart' : 'previous'}, // FIX THIS: IT DOESNT SEE THE DATA VARIABLE SO CANT CHECK THE PROGRESS MS // data: {command: (data['progress_ms'] < 5000) ? 'restart' : 'previous'}, // FIX THIS: IT DOESNT SEE THE DATA VARIABLE SO CANT CHECK THE PROGRESS MS
data: {command: (1 == 1) ? 'restart' : 'previous'}, data: {command: progress_ms > 5000 ? 'restart' : 'previous'},
success: function(response) { success: function(response) {
} }
}); });
@@ -250,4 +277,4 @@
}); });
</script> </script>
</body> </body>
</html> </html>