From f269d8579d30288c9e490e488a8e4c7bc98c038d Mon Sep 17 00:00:00 2001 From: stjet <49297268+stjet@users.noreply.github.com> Date: Tue, 25 Jun 2024 03:54:29 +0000 Subject: [PATCH] history, playlist, copy password --- static/password/index.html | 2 +- templates/player.html | 52 +++++++++++++++++++++++++++++++++++++- templates/stats.html | 3 +++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/static/password/index.html b/static/password/index.html index 2c1525f..91b3c74 100644 --- a/static/password/index.html +++ b/static/password/index.html @@ -10,7 +10,7 @@
- +
diff --git a/templates/player.html b/templates/player.html index 55fb8bd..ab11931 100644 --- a/templates/player.html +++ b/templates/player.html @@ -68,10 +68,14 @@
-

queue

+

queue

empty

+ + +
+
@@ -109,6 +113,7 @@ const songs = Array.from(document.getElementById("songs").children).map((c) => c.innerText); let playable_songs = songs; let played = []; + let history = []; //like played but with more info let queue = []; let queue_id_counter = 0; let show_title = false; @@ -120,6 +125,13 @@ //"ended" event function next_song() { + if (audio_ele.currentSrc !== "") { + history.push({ + name: played[played.length - 1], + length: audio_ele.duration, + ended: audio_ele.currentTime, + }); + } captions_box.innerHTML = ""; const not_played = playable_songs.filter((song) => !played.includes(song)); if (not_played.length === 0) return; @@ -220,6 +232,44 @@ } filter_select_all(); + + //playlist file format is just newline separated artist-song + + function download_queue_as_playlist() { + let a = document.createElement("A"); + a.href = `data:text/plain;charset=utf-8,${encodeURIComponent(queue.map((q) => q[0]).join("\n"))}`; + a.download = "queue.playlist"; + a.style.display = "none"; + document.body.appendChild(a); + a.click(); + } + + function upload_playlist() { + let reader = new FileReader(); + reader.readAsText(document.getElementById("playlist-upload").files[0]); + reader.addEventListener("load", () => { + let playlist_songs = reader.result.split("\n"); + let randomized = []; + while (randomized.length < playlist_songs.length) { + let rand = Math.floor(Math.random() * playlist_songs.length); + if (!randomized.includes(playlist_songs[rand])) { + randomized.push(playlist_songs[rand]); + } + } + for (const n of randomized) { + add_to_queue(n); + } + }); + } + + function download_history() { + let a = document.createElement("A"); + a.href = `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(history))}`; + a.download = "queue.playlist"; + a.style.display = "none"; + document.body.appendChild(a); + a.click(); + } diff --git a/templates/stats.html b/templates/stats.html index 411c585..a5d0ccc 100644 --- a/templates/stats.html +++ b/templates/stats.html @@ -18,6 +18,9 @@

Songs: [[ songs_count ]]

Subtitled Songs: [[ sub_count ]]

+
+ +