radio widget changes

This commit is contained in:
codey 2025-03-18 09:39:20 -04:00
parent e30ae2460d
commit 796c8cd913
2 changed files with 14 additions and 10 deletions

View File

@ -69,7 +69,7 @@ class Misc(FastAPI):
return Response(content=f.read(), return Response(content=f.read(),
media_type="image/png") media_type="image/png")
async def get_radio_np(self) -> str: async def get_radio_np(self) -> tuple[str, str, str]:
""" """
Get radio now playing Get radio now playing
Args: Args:
@ -78,10 +78,11 @@ class Misc(FastAPI):
str: Radio now playing in artist - song format str: Radio now playing in artist - song format
""" """
artistsong: Optional[str] = self.radio.radio_util.now_playing['artistsong'] np: dict = self.radio.radio_util.now_playing
if not isinstance(artistsong, str): artistsong: str = np.get('artistsong', 'N/A - N/A')
return "N/A - N/A" album: str = np.get('album', 'N/A')
return artistsong genre: str = np.get('genre', 'N/A')
return (artistsong, album, genre)
async def homepage_redis_widget(self) -> JSONResponse: async def homepage_redis_widget(self) -> JSONResponse:
@ -137,12 +138,15 @@ class Misc(FastAPI):
""" """
Homepage Radio Widget Handler Homepage Radio Widget Handler
""" """
radio_np: str = await self.get_radio_np() radio_np: tuple = await self.get_radio_np()
if not radio_np: if not radio_np:
return JSONResponse(status_code=500, content={ return JSONResponse(status_code=500, content={
'err': True, 'err': True,
'errorText': 'General failure.', 'errorText': 'General failure.',
}) })
(artistsong, album, genre) = radio_np
return JSONResponse(content={ return JSONResponse(content={
'now_playing': await self.get_radio_np(), 'now_playing': artistsong,
'album': album,
'genre': genre,
}) })

View File

@ -147,7 +147,7 @@ class RadioUtil:
""" """
db_query: str = """SELECT distinct(LOWER(TRIM(artist)) || " - " || LOWER(TRIM(song))), (TRIM(artist) || " - " || TRIM(song)) AS artistdashsong, id, artist, song, album, genre, 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, genre, file_path, duration FROM tracks\
WHERE id >= 74284 AND (genre LIKE "%metalcore%"\ WHERE id >= 67166 AND (genre LIKE "%metalcore%"\
OR genre LIKE "%rock%"\ OR genre LIKE "%rock%"\
OR genre LIKE "%pop punk%"\ OR genre LIKE "%pop punk%"\
OR genre LIKE "%math rock%"\ OR genre LIKE "%math rock%"\
@ -187,14 +187,14 @@ class RadioUtil:
""" """
# db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, album, genre, file_path, duration FROM tracks\ # db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, album, genre, file_path, duration FROM tracks\
# WHERE genre like "%edm%" OR genre LIKE "%electronic%"' # WHERE genre like "%hip hop%" OR genre LIKE "%rap%" OR genre LIKE "%edm%" OR genre LIKE "%trap%"'
""" """
LIMITED TO ONE/SOME ARTISTS... LIMITED TO ONE/SOME ARTISTS...
""" """
# db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, album, genre, file_path, duration FROM tracks\ # db_query = 'SELECT distinct(artist || " - " || song) AS artistdashsong, id, artist, song, album, genre, file_path, duration FROM tracks\
# WHERE (artist LIKE "%lmfao%" OR artist LIKE "%fire from the gods%" OR artist LIKE "%nothing, nowhere%") AND (NOT song LIKE "%%stripped%%" AND NOT song LIKE "%%live%%" AND NOT song LIKE "%%reimagined%%" AND NOT song LIKE "%%alternative%%" AND NOT song LIKE "%%unzipped%%") GROUP BY artistdashsong ORDER BY RANDOM()' # WHERE (artist LIKE "%more of myself to kill%" OR artist LIKE "%tethered%") AND (NOT song LIKE "%%stripped%%" 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 artist DESC, album DESC, id ASC'
async with sqlite3.connect(self.active_playlist_path, async with sqlite3.connect(self.active_playlist_path,
timeout=2) as db_conn: timeout=2) as db_conn: