small optimization for filtering
This commit is contained in:
parent
f18a9da4a0
commit
5d2de1471f
@ -275,14 +275,16 @@ class RadioUtil:
|
||||
"""
|
||||
try:
|
||||
artist = artist.strip()
|
||||
query: str = "SELECT genre FROM artist_genre WHERE artist LIKE ? COLLATE NOCASE"
|
||||
query: str = (
|
||||
"SELECT genre FROM artist_genre WHERE artist LIKE ? COLLATE NOCASE"
|
||||
)
|
||||
params: tuple[str] = (f"%%{artist}%%",)
|
||||
async with sqlite3.connect(self.artist_genre_db_path, timeout=2) as _db:
|
||||
_db.row_factory = sqlite3.Row
|
||||
async with await _db.execute(query, params) as _cursor:
|
||||
res = await _cursor.fetchone()
|
||||
if not res:
|
||||
return "Not Found" # Exception suppressed
|
||||
return "Not Found" # Exception suppressed
|
||||
# raise RadioException(
|
||||
# f"Could not locate {artist} in artist_genre_map db."
|
||||
# )
|
||||
@ -358,15 +360,19 @@ class RadioUtil:
|
||||
len(self.active_playlist),
|
||||
)
|
||||
if self.playback_genres:
|
||||
new_playlist: list[dict] = []
|
||||
new_playlist: list[dict] = []
|
||||
logging.info("Limiting playback genres")
|
||||
for x, item in enumerate(self.active_playlist):
|
||||
for item in self.active_playlist:
|
||||
matched_genre: bool = False
|
||||
item_genres: str = item.get("genre", "").strip().lower()
|
||||
for genre in self.playback_genres:
|
||||
genre = genre.strip().lower()
|
||||
if genre in item_genres:
|
||||
new_playlist.append(item)
|
||||
matched_genre = True
|
||||
continue
|
||||
if matched_genre:
|
||||
continue
|
||||
self.active_playlist = new_playlist
|
||||
logging.info(
|
||||
"%s items remain for playback after filtering",
|
||||
|
Loading…
x
Reference in New Issue
Block a user