From: Chris Fulljames Date: Sat, 22 Aug 2026 12:36:38 +0000 (-0400) Subject: Add private songs X-Git-Url: https://littlesong.place/gitweb/?a=commitdiff_plain;h=9ca4dbe30f5c94f9888a295102cfe95e0444d6b2;p=littlesongplace.git Add private songs --- diff --git a/src/littlesongplace/db.py b/src/littlesongplace/db.py index 3aae1bc..cdcac92 100644 --- a/src/littlesongplace/db.py +++ b/src/littlesongplace/db.py @@ -6,7 +6,7 @@ from flask import abort, g, current_app from . import datadir -DB_VERSION = 8 +DB_VERSION = 9 def get(): db = getattr(g, '_database', None) diff --git a/src/littlesongplace/songs.py b/src/littlesongplace/songs.py index 62b17b2..a590482 100644 --- a/src/littlesongplace/songs.py +++ b/src/littlesongplace/songs.py @@ -34,6 +34,7 @@ class Song: collaborators: list[str] user_has_pfp: bool hidden: bool + private: bool eventid: Optional[int] jamid: Optional[int] queueid: Optional[int] @@ -157,10 +158,13 @@ def _from_db(query, args=()): songid = sd["songid"] song_tags = sd["tags"].split(",") if sd["tags"] else [] song_collabs = sd["collaborators"].split(",") if sd["collaborators"] else [] + private = bool(sd["private"]) - # Song is hidden if it is still queued for import or was submitted to - # an event that hasn't ended yet - hidden = sd["queueid"] != None + # Song is hidden if it is: + # - private + # - still queued for import + # - submitted to an event that hasn't ended yet + hidden = private or (sd["queueid"] is not None) if sd["event_enddate"]: enddate = datetime.fromisoformat(sd["event_enddate"]) hidden |= datetime.now(timezone.utc) < enddate @@ -182,6 +186,7 @@ def _from_db(query, args=()): collaborators=song_collabs, user_has_pfp=users.user_has_pfp(sd["userid"]), hidden=hidden, + private=private, eventid=sd["eventid"], jamid=sd["jamid"], queueid=sd["queueid"], @@ -328,6 +333,7 @@ def update_song(): description = request.form["description"] upload_type = request.form["upload-type"] song_duration = request.form["song-duration"] + private = "private" in request.form # Will not be present if unchecked fade_out = "fade-out" in request.form # Will not be present if unchecked tags = [t.strip() for t in request.form["tags"].split(",") if t] collaborators = [c.strip() for c in request.form["collabs"].split(",") if c] @@ -362,10 +368,10 @@ def update_song(): # Update songs table db.query( """ - UPDATE songs SET title = ?, description = ? + UPDATE songs SET title = ?, description = ?, private = ? WHERE songid = ? """, - [title, description, songid]) + [title, description, private, songid]) # Update song_tags table db.query("delete from song_tags where songid = ?", [songid]) @@ -403,6 +409,7 @@ def create_song(): description = request.form["description"] upload_type = request.form["upload-type"] song_duration = request.form["song-duration"] + private = "private" in request.form # Will not be present if unchecked fade_out = "fade-out" in request.form # Will not be present if unchecked tags = [t.strip() for t in request.form["tags"].split(",") if t] collaborators = [c.strip() for c in request.form["collabs"].split(",") if c] @@ -425,11 +432,11 @@ def create_song(): timestamp = datetime.now(timezone.utc).isoformat() song_data = db.query( """ - INSERT INTO songs (userid, title, description, created, threadid, eventid) - VALUES (?, ?, ?, ?, ?, ?) + INSERT INTO songs (userid, title, description, created, threadid, eventid, private) + VALUES (?, ?, ?, ?, ?, ?, ?) RETURNING (songid) """, - [session["userid"], title, description, timestamp, threadid, eventid], + [session["userid"], title, description, timestamp, threadid, eventid, private], one=True) # Move file to permanent location diff --git a/src/littlesongplace/sql/schema.sql b/src/littlesongplace/sql/schema.sql index d40ff51..47c5b73 100644 --- a/src/littlesongplace/sql/schema.sql +++ b/src/littlesongplace/sql/schema.sql @@ -22,8 +22,10 @@ CREATE TABLE songs ( description TEXT, threadid INTEGER, eventid INTEGER, + queueid INTEGER, FOREIGN KEY(userid) REFERENCES users(userid), - FOREIGN KEY(eventid) REFERENCES jam_events(eventid) + FOREIGN KEY(eventid) REFERENCES jam_events(eventid), + FOREIGN KEY(queueid) REFERENCES import_queue(queueid) ON DELETE SET NULL ); CREATE INDEX idx_songs_by_user ON songs(userid); CREATE INDEX idx_songs_by_eventid ON songs(eventid); @@ -180,12 +182,14 @@ CREATE VIEW songs_view AS jam_events.jamid AS jamid, jam_events.enddate AS event_enddate, tags_agg.tags, - collaborators_agg.collaborators + collaborators_agg.collaborators, + import_queue.status AS queue_status FROM songs - INNER JOIN users ON songs.userid = users.userid - LEFT JOIN tags_agg ON tags_agg.songid = songs.songid - LEFT JOIN collaborators_agg ON collaborators_agg.songid = songs.songid - LEFT JOIN jam_events ON jam_events.eventid = songs.eventid; + INNER JOIN users USING (userid) + LEFT JOIN tags_agg USING (songid) + LEFT JOIN collaborators_agg USING (songid) + LEFT JOIN jam_events USING (eventid) + LEFT JOIN import_queue USING (queueid); DROP TABLE IF EXISTS users_push_subscriptions; CREATE TABLE users_push_subscriptions ( @@ -196,5 +200,16 @@ CREATE TABLE users_push_subscriptions ( FOREIGN KEY(userid) REFERENCES users(userid) ON DELETE CASCADE ); -PRAGMA user_version = 7; +DROP TABLE IF EXISTS import_queue; +CREATE TABLE import_queue ( + queueid INTEGER PRIMARY KEY AUTOINCREMENT, + created TEXT NOT NULL, + indreamsurl TEXT NOT NULL, + songid INTEGER NOT NULL REFERENCES songs(songid) ON DELETE CASCADE, + status INTEGER NOT NULL, + duration INTEGER NOT NULL, + fadeout INTEGER NOT NULL +); + +PRAGMA user_version = 8; diff --git a/src/littlesongplace/sql/schema_revert.sql b/src/littlesongplace/sql/schema_revert.sql index 19e44da..018e8e3 100644 --- a/src/littlesongplace/sql/schema_revert.sql +++ b/src/littlesongplace/sql/schema_revert.sql @@ -1,6 +1,5 @@ -DROP VIEW IF EXISTS songs_view; -ALTER TABLE songs DROP COLUMN queueid; -DROP TABLE IF EXISTS import_queue; -PRAGMA user_version = 7; +ALTER TABLE songs DROP COLUMN private; + +PRAGMA user_version = 8; diff --git a/src/littlesongplace/sql/schema_update.sql b/src/littlesongplace/sql/schema_update.sql index ac26d91..247b131 100644 --- a/src/littlesongplace/sql/schema_update.sql +++ b/src/littlesongplace/sql/schema_update.sql @@ -1,15 +1,5 @@ -ALTER TABLE songs ADD COLUMN queueid INTEGER REFERENCES import_queue(queueid) ON DELETE SET NULL; --- DROP TABLE IF EXISTS import_queue; -CREATE TABLE import_queue ( - queueid INTEGER PRIMARY KEY AUTOINCREMENT, - created TEXT NOT NULL, - indreamsurl TEXT NOT NULL, - songid INTEGER NOT NULL REFERENCES songs(songid) ON DELETE CASCADE, - status INTEGER NOT NULL, - duration INTEGER NOT NULL, - fadeout INTEGER NOT NULL -); +ALTER TABLE songs ADD COLUMN private INTEGER; DROP VIEW IF EXISTS songs_view; CREATE VIEW songs_view AS @@ -43,5 +33,5 @@ CREATE VIEW songs_view AS LEFT JOIN jam_events USING (eventid) LEFT JOIN import_queue USING (queueid); -PRAGMA user_version = 8; +PRAGMA user_version = 9; diff --git a/src/littlesongplace/templates/edit-song.html b/src/littlesongplace/templates/edit-song.html index 5dc7c1b..8a550c1 100644 --- a/src/littlesongplace/templates/edit-song.html +++ b/src/littlesongplace/templates/edit-song.html @@ -47,6 +47,10 @@ +
+ +

diff --git a/src/littlesongplace/templates/news.html b/src/littlesongplace/templates/news.html index a580a91..a1b9f1a 100644 --- a/src/littlesongplace/templates/news.html +++ b/src/littlesongplace/templates/news.html @@ -5,6 +5,13 @@ {% block body %}

site news

+ +

2026-08-22 - Private Songs

+

+You can now mark songs as private, so they will only be visible to you. This +works basically the same way as it does for playlists. +

+

2026-03-10 - New Email

The site finally has its own email address! No more gmail — for any diff --git a/src/littlesongplace/templates/song-macros.html b/src/littlesongplace/templates/song-macros.html index 7073dd6..fc8d946 100644 --- a/src/littlesongplace/templates/song-macros.html +++ b/src/littlesongplace/templates/song-macros.html @@ -19,7 +19,8 @@

- {%- if song.hidden %}[Hidden]{% endif %} + {%- if song.private %}[Private] + {%- elif song.hidden %}[Hidden]{% endif %} {%- if song.queue_status == 0 %}[Queue Pos: {{ song.get_queue_position() }}]{% endif %} {%- if song.queue_status == 1 %}[Importing Now]{% endif %} {%- if song.queue_status == 2 %}[Import Failed]{% endif %} diff --git a/src/littlesongplace/templates/song.html b/src/littlesongplace/templates/song.html index 86b1ef2..55ce97f 100644 --- a/src/littlesongplace/templates/song.html +++ b/src/littlesongplace/templates/song.html @@ -14,6 +14,8 @@

Song by {{ song_artist(song) }}

+{% if song.private %}

[Private]

{% endif %} +