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