From 4e1f4e1dbd420e71c4a08d4009025828768d2a08 Mon Sep 17 00:00:00 2001 From: Chris Fulljames Date: Mon, 19 Jan 2026 16:26:57 -0500 Subject: [PATCH] Add fade out setting to queue --- src/littlesongplace/dreams_importer.py | 10 +++++----- src/littlesongplace/songs.py | 6 ++++-- src/littlesongplace/sql/schema_update.sql | 3 ++- test/test_dreams_importer.py | 4 +++- test/utils.py | 4 +++- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/littlesongplace/dreams_importer.py b/src/littlesongplace/dreams_importer.py index 82fd38b..cda0199 100644 --- a/src/littlesongplace/dreams_importer.py +++ b/src/littlesongplace/dreams_importer.py @@ -75,16 +75,16 @@ def delete_from_queue(queueid): db.query("DELETE FROM import_queue WHERE queueid = ?", [queueid]) current_app.logger.info(f"dreams_importer: Removed {queueid} from queue") -def add_to_queue(songid, indreams_url, duration): - print(songid, indreams_url) +def add_to_queue(songid, indreams_url, duration, fade_out): timestamp = datetime.now(timezone.utc).isoformat() + fade_out = fade_out in [True, "true", "True", "TRUE", 1] result = db.query( """ - INSERT INTO import_queue (created, indreamsurl, songid, status, duration) - VALUES (?, ?, ?, 0, ?) + INSERT INTO import_queue (created, indreamsurl, songid, status, duration, fadeout) + VALUES (?, ?, ?, 0, ?, ?) RETURNING queueid """, - [timestamp, indreams_url, songid, duration], + [timestamp, indreams_url, songid, duration, int(fade_out)], expect_one=True) queueid = result["queueid"] diff --git a/src/littlesongplace/songs.py b/src/littlesongplace/songs.py index 4adb2cb..c0d8475 100644 --- a/src/littlesongplace/songs.py +++ b/src/littlesongplace/songs.py @@ -323,6 +323,7 @@ def update_song(): description = request.form["description"] upload_type = request.form["upload-type"] song_duration = request.form["song-duration"] + fade_out = request.form["fade-out"] if "fade-out" in request.form else "False" tags = [t.strip() for t in request.form["tags"].split(",") if t] collaborators = [c.strip() for c in request.form["collabs"].split(",") if c] @@ -383,7 +384,7 @@ def update_song(): if upload_type == "dreams" and url: duration = duration_in_seconds(song_duration) - dreams_importer.add_to_queue(songid, url, duration) + dreams_importer.add_to_queue(songid, url, duration, fade_out) db.commit() flash_and_log(f"Successfully updated '{title}'", "success") @@ -397,6 +398,7 @@ def create_song(): description = request.form["description"] upload_type = request.form["upload-type"] song_duration = request.form["song-duration"] + fade_out = request.form["fade-out"] if "fade-out" in request.form else "False" tags = [t.strip() for t in request.form["tags"].split(",") if t] collaborators = [c.strip() for c in request.form["collabs"].split(",") if c] try: @@ -446,7 +448,7 @@ def create_song(): if upload_type == "dreams": duration = duration_in_seconds(song_duration) - dreams_importer.add_to_queue(songid, url, duration) + dreams_importer.add_to_queue(songid, url, duration, fade_out) db.commit() diff --git a/src/littlesongplace/sql/schema_update.sql b/src/littlesongplace/sql/schema_update.sql index a19e484..ac26d91 100644 --- a/src/littlesongplace/sql/schema_update.sql +++ b/src/littlesongplace/sql/schema_update.sql @@ -7,7 +7,8 @@ CREATE TABLE import_queue ( indreamsurl TEXT NOT NULL, songid INTEGER NOT NULL REFERENCES songs(songid) ON DELETE CASCADE, status INTEGER NOT NULL, - duration INTEGER NOT NULL + duration INTEGER NOT NULL, + fadeout INTEGER NOT NULL ); DROP VIEW IF EXISTS songs_view; diff --git a/test/test_dreams_importer.py b/test/test_dreams_importer.py index c272c16..52763fd 100644 --- a/test/test_dreams_importer.py +++ b/test/test_dreams_importer.py @@ -8,7 +8,8 @@ def test_import_failure(client, user): client, b"Queued for import from Dreams", upload_type="dreams", song_url=TEST_URL, - song_duration="3:19") + song_duration="3:19", + fade_out=True) response = client.get(f"/users/user") assert b"[Hidden]" in response.data assert b"[Queue Pos: 1]" in response.data @@ -19,6 +20,7 @@ def test_import_failure(client, user): assert response.json["next"]["songid"] == 1 assert response.json["next"]["queueid"] == 1 assert response.json["next"]["duration"] == 199 + assert response.json["next"]["fadeout"] == 1 # Now in progress response = client.get(f"/users/user") diff --git a/test/utils.py b/test/utils.py index effa87a..0fe1d3d 100644 --- a/test/utils.py +++ b/test/utils.py @@ -48,7 +48,8 @@ def create_user_song_and_playlist(client, playlist_type="private"): def upload_song( client, msg, error=False, songid=None, eventid=None, user="user", userid=1, filename=TEST_DATA/"sample-3s.mp3", - upload_type="file", song_url=None, song_duration=None, **kwargs): + upload_type="file", song_url=None, song_duration=None, fade_out=False, + **kwargs): song_file = None if filename: @@ -63,6 +64,7 @@ def upload_song( "upload-type": upload_type, "song-url": song_url, "song-duration": song_duration, + "fade-out": fade_out, } for k, v in kwargs.items(): data[k] = v -- 2.39.5