created: str
tags: list[str]
collaborators: list[str]
+ user_has_pfp: bool
def json(self):
return json.dumps(vars(self))
return song_comments
- def user_has_pfp(self):
- return (get_user_images_path(self.userid)/"pfp.jpg").exists()
-
@classmethod
def by_id(cls, songid):
songs = cls._from_db("select * from songs inner join users on songs.userid = users.userid where songid = ?", [songid])
song_tags = [t["tag"] for t in tags[sd["songid"]]]
song_collabs = [c["name"] for c in collabs[sd["songid"]]]
created = datetime.fromisoformat(sd["created"]).astimezone().strftime("%Y-%m-%d")
- songs.append(cls(sd["songid"], sd["userid"], sd["username"], sd["title"], sanitize_user_text(sd["description"]), created, song_tags, song_collabs))
-
+ user_has_pfp = (get_user_images_path(sd["userid"])/"pfp.jpg").exists()
+ songs.append(cls(sd["songid"], sd["userid"], sd["username"], sd["title"], sanitize_user_text(sd["description"]), created, song_tags, song_collabs, user_has_pfp))
return songs
@classmethod
// Play a new song from the list in the player
function play(event) {
- var songElement = event.target;
- while (!songElement.classList.contains("song"))
- {
- songElement = songElement.parentElement;
+ var songElement = event.target.closest(".song");
+
+ // Update song queue with songs on current page
+ m_allSongs = [];
+ for (const element of document.getElementsByClassName("song")) {
+ m_allSongs.push(element);
}
+
m_songIndex = m_allSongs.indexOf(songElement);
playCurrentSong();
}
audio.play();
var pfp = document.getElementById("player-pfp")
- pfp.style.display = "inline-block";
- pfp.src = `/pfp/${songData.userid}`
+ var albumImg;
+ if (songData.user_has_pfp) {
+ pfp.style.display = "inline-block";
+ pfp.src = `/pfp/${songData.userid}`;
+ albumImg = `/pfp/${songData.userid}`;
+ }
+ else {
+ pfp.style.display = "none";
+ albumImg = "/static/lsp_notes.png";
+ }
var title = document.getElementById("player-title");
title.textContent = songData.title;
var collabname = collaborators[i].substr(1, collaborators[i].length - 1);
var link = document.createElement("a");
link.href = `/users/${collabname}`;
- link.classList.add("profile-link")
+ link.classList.add("profile-link");
link.textContent = collabname;
collabs.appendChild(link);
}
}
}
- //collabs.textContent = songData.collaborators.join(", ")
-
-
if ("mediaSession" in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: songData.title,
artist: songData.username,
album: "Little Song Place",
- artwork: [{src: "/static/lsp_notes.png"}],
+ artwork: [{src: albumImg}],
});
+
navigator.mediaSession.setActionHandler('nexttrack', () => {
songNext();
});
document.getElementById("volume-slider").oninput = function(event) {
audio.volume = event.target.value;
}
-
- // Song queue
- for (const element of document.getElementsByClassName("song")) {
- m_allSongs.push(element);
- }
});
<h1>Site News</h1>
+<h2>2025-02-22 - Continuous Playback</h2>
+The song player now persists between pages as you navigate around the site, so
+the music isn't interrupted when you go to someone's profile or comment on a
+song. It will continue playing the songs from the original page until you
+click play on a new song.
+
<h2>2025-02-16 - Playlists</h2>
<p>
Do you need specific songs in a specific order? Have I got the feature for