From 8848d3a493cc1766373a49f9861c3fa823402289 Mon Sep 17 00:00:00 2001 From: codey Date: Sun, 27 Apr 2025 08:27:08 -0400 Subject: [PATCH] bugfix: datatables search for radio queue was returning incorrect queue positions for items once a filter/query was provided (numbering/index was based on the filtered resultset) --- endpoints/radio.py | 8 ++++---- utils/radio_util.py | 26 +++++++++++++------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/endpoints/radio.py b/endpoints/radio.py index 9c528d2..f0f4fb2 100644 --- a/endpoints/radio.py +++ b/endpoints/radio.py @@ -128,9 +128,9 @@ class Radio(FastAPI): start: int = int(data.start) end: int = start + 20 search: Optional[str] = data.search - + orig_queue: list[dict] = self.radio_util.active_playlist if not search: - queue_full: list = self.radio_util.active_playlist + queue_full: list = orig_queue else: queue_full: list = self.radio_util.datatables_search(data.search) queue: list = queue_full[start:end] @@ -138,7 +138,7 @@ class Radio(FastAPI): for x, item in enumerate(queue): queue_out.append( { - "pos": queue_full.index(item), + "pos": orig_queue.index(item), "id": item.get("id"), "uuid": item.get("uuid"), "artist": item.get("artist"), @@ -150,7 +150,7 @@ class Radio(FastAPI): } ) fallback_playlist_len: int = len( - self.radio_util.active_playlist + orig_queue ) # Used if search term is provided out_json = { "draw": data.draw, diff --git a/utils/radio_util.py b/utils/radio_util.py index 92854c5..d489907 100644 --- a/utils/radio_util.py +++ b/utils/radio_util.py @@ -50,12 +50,12 @@ class RadioUtil: "/usr/local/share", "sqlite_dbs", "track_album_art.db" ) self.playback_genres: list[str] = [ - "post-hardcore", - "post hardcore", - "metalcore", - "deathcore", - "edm", - "electronic", + # "post-hardcore", + # "post hardcore", + # "metalcore", + # "deathcore", + # "edm", + # "electronic", ] self.active_playlist: list[dict] = [] self.playlist_loaded: bool = False @@ -118,7 +118,7 @@ class RadioUtil: filter (str): The filter query to fuzzy match with Returns: - list[str]: List of matching playlist items (if any are found) + list[dict]: List of matching playlist items (if any are found) """ filter = filter.strip().lower() matched: list[dict] = [] @@ -335,10 +335,10 @@ class RadioUtil: LIMITED GENRES """ - db_query: str = ( - 'SELECT distinct(LOWER(TRIM(artist)) || " - " || LOWER(TRIM(song))), (TRIM(artist) || " - " || TRIM(song))' - "AS artistdashsong, id, artist, song, album, file_path, duration FROM tracks" - ) + # db_query: str = ( + # 'SELECT distinct(LOWER(TRIM(artist)) || " - " || LOWER(TRIM(song))), (TRIM(artist) || " - " || TRIM(song))' + # "AS artistdashsong, id, artist, song, album, file_path, duration FROM tracks" + # ) """ LIMITED TO ONE/SMALL SUBSET OF GENRES @@ -351,8 +351,8 @@ class RadioUtil: LIMITED TO ONE/SOME ARTISTS... """ - # db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, album, file_path, duration FROM tracks\ - # WHERE (artist LIKE "%outline in color%") AND (NOT song LIKE "%%stripped%%" AND NOT song LIKE "%(2022)%" AND NOT song LIKE "%(live%%" AND NOT song LIKE "%%acoustic%%" AND NOT song LIKE "%%instrumental%%" AND NOT song LIKE "%%remix%%" AND NOT song LIKE "%%reimagined%%" AND NOT song LIKE "%%alternative%%" AND NOT song LIKE "%%unzipped%%") GROUP BY artistdashsong ORDER BY RANDOM()' # ORDER BY album ASC, id ASC' + db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, album, file_path, duration FROM tracks\ + WHERE (artist LIKE "%chunk!%") AND (NOT song LIKE "%%stripped%%" AND NOT song LIKE "%(2022)%" AND NOT song LIKE "%(live%%" AND NOT song LIKE "%%acoustic%%" AND NOT song LIKE "%%instrumental%%" AND NOT song LIKE "%%remix%%" AND NOT song LIKE "%%reimagined%%" AND NOT song LIKE "%%alternative%%" AND NOT song LIKE "%%unzipped%%") GROUP BY artistdashsong ORDER BY RANDOM()' # ORDER BY album ASC, id ASC' # db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, album, genre, file_path, duration FROM tracks\ # WHERE (artist LIKE "%sullivan king%" OR artist LIKE "%kayzo%" OR artist LIKE "%adventure club%") AND (NOT song LIKE "%%stripped%%" AND NOT song LIKE "%(2022)%" AND NOT song LIKE "%(live%%" AND NOT song LIKE "%%acoustic%%" AND NOT song LIKE "%%instrumental%%" AND NOT song LIKE "%%remix%%" AND NOT song LIKE "%%reimagined%%" AND NOT song LIKE "%%alternative%%" AND NOT song LIKE "%%unzipped%%") GROUP BY artistdashsong ORDER BY RANDOM()'# ORDER BY album ASC, id ASC'