Consolidate album search selectors
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
"""
|
||||
Utility methods for the Spotify query API
|
||||
"""
|
||||
from typing import Iterable
|
||||
from typing import Iterable, Optional
|
||||
|
||||
from spotify_model import Paging, SearchAlbum
|
||||
from spotipy import Spotify
|
||||
@ -16,22 +16,20 @@ def _search_albums(client: Spotify, search_str: str) -> Paging:
|
||||
return _search
|
||||
|
||||
|
||||
def search_albums(client: Spotify, search_str: str) -> Iterable[SearchAlbum]:
|
||||
def search_albums(
|
||||
client: Spotify, search_str: Optional[str] = None, artist: Optional[str] = None, label: Optional[str] = None
|
||||
) -> Iterable[SearchAlbum]:
|
||||
"Display albums from a search string"
|
||||
|
||||
for item in exhaust(_search_albums(client, search_str)):
|
||||
yield SearchAlbum(**item)
|
||||
|
||||
|
||||
def search_albums_artist(client: Spotify, artist_name: str) -> Iterable[SearchAlbum]:
|
||||
"Display albums from a particular artist"
|
||||
|
||||
for item in exhaust(_search_albums(client, f'artist:"{artist_name}"')):
|
||||
yield SearchAlbum(**item)
|
||||
|
||||
|
||||
def search_albums_label(client: Spotify, label_name: str) -> Iterable[SearchAlbum]:
|
||||
"Display albums from a particular label"
|
||||
|
||||
for item in exhaust(_search_albums(client, f'label:"{label_name}"')):
|
||||
query_items = [
|
||||
search_str,
|
||||
f'artist:"{artist}"' if artist is not None else None,
|
||||
f'label:"{label}"' if label is not None else None,
|
||||
]
|
||||
query_str = " ".join([i for i in query_items if i is not None])
|
||||
|
||||
if not query_str:
|
||||
return
|
||||
|
||||
for item in exhaust(_search_albums(client, query_str)):
|
||||
yield SearchAlbum(**item)
|
||||
|
@ -10,7 +10,7 @@ from typing import Iterable
|
||||
from spotify_model import ReleaseDatePrecision, SearchAlbum
|
||||
|
||||
|
||||
def album_released_after(albums: Iterable[SearchAlbum], released_after: date) -> Iterable[SearchAlbum]:
|
||||
def temporal_released_after(albums: Iterable[SearchAlbum], released_after: date) -> Iterable[SearchAlbum]:
|
||||
"""
|
||||
Filter albums to after a specific release date.
|
||||
|
||||
|
Reference in New Issue
Block a user