misc
This commit is contained in:
@ -3,7 +3,7 @@ import traceback
|
||||
import time
|
||||
import datetime
|
||||
import os
|
||||
import asyncio
|
||||
import random
|
||||
from uuid import uuid4 as uuid
|
||||
from typing import Union, Optional, Iterable
|
||||
from aiohttp import ClientSession, ClientTimeout
|
||||
@ -20,13 +20,10 @@ non_alnum: Pattern = regex.compile(r"[^a-zA-Z0-9]")
|
||||
|
||||
"""
|
||||
TODO:
|
||||
- Album art rework
|
||||
- get_genre should only be called once for load_playlist, rework get_genre to (optionally) accept a list of artists,
|
||||
and return (optionally) a list instead of an str
|
||||
- Allow tracks to be queried again based on genre; unable to query tracks based on genre presently,
|
||||
as genre was moved outside track_file_map to artist_genre_map
|
||||
and return (optionally) a list instead of an str
|
||||
- Ask GPT when we encounter an untagged (no genre defined) artist, automation is needed for this tedious task
|
||||
- etc..
|
||||
- etc..
|
||||
"""
|
||||
|
||||
|
||||
@ -93,7 +90,7 @@ class RadioUtil:
|
||||
"""
|
||||
return str(datetime.timedelta(seconds=s)).split(".", maxsplit=1)[0]
|
||||
|
||||
async def trackdb_typeahead(self, query: str) -> Optional[list[str]]:
|
||||
def trackdb_typeahead(self, query: str) -> Optional[list[str]]:
|
||||
"""
|
||||
Query track db for typeahead
|
||||
Args:
|
||||
@ -338,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 GROUP BY artistdashsong ORDER BY RANDOM()"
|
||||
# )
|
||||
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
|
||||
@ -354,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 "%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, 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, 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'
|
||||
@ -385,12 +382,33 @@ class RadioUtil:
|
||||
"file_path": r["file_path"],
|
||||
"duration": r["duration"],
|
||||
}
|
||||
for r in results
|
||||
for r in results if r not in self.active_playlist
|
||||
]
|
||||
logging.info(
|
||||
"Populated active playlists with %s items",
|
||||
len(self.active_playlist),
|
||||
)
|
||||
|
||||
random.shuffle(self.active_playlist)
|
||||
|
||||
"""Dedupe"""
|
||||
logging.info("Removing duplicate tracks...")
|
||||
dedupe_processed = []
|
||||
for item in self.active_playlist:
|
||||
artistsongabc: str = non_alnum.sub('', item.get('artistsong', None))
|
||||
if not artistsongabc:
|
||||
logging.info("Missing artistsong: %s", item)
|
||||
continue
|
||||
if artistsongabc in dedupe_processed:
|
||||
self.active_playlist.remove(item)
|
||||
dedupe_processed.append(artistsongabc)
|
||||
|
||||
logging.info(
|
||||
"Duplicates removed." "New playlist size: %s",
|
||||
len(self.active_playlist))
|
||||
|
||||
logging.info("Playlist: %s", [str(a.get('artistsong', '')) for a in self.active_playlist])
|
||||
|
||||
if self.playback_genres:
|
||||
new_playlist: list[dict] = []
|
||||
logging.info("Limiting playback genres")
|
||||
@ -400,6 +418,8 @@ class RadioUtil:
|
||||
for genre in self.playback_genres:
|
||||
genre = genre.strip().lower()
|
||||
if genre in item_genres:
|
||||
if item in new_playlist:
|
||||
continue
|
||||
new_playlist.append(item)
|
||||
matched_genre = True
|
||||
continue
|
||||
|
Reference in New Issue
Block a user