spotify_actions/spotify_actions/search.py

31 lines
879 B
Python

"""
Utility methods for the Spotify query API
"""
from typing import Iterable
from spotify_model import Paging, SearchAlbum
from spotipy import Spotify
from .util import exhaust
def _search_albums(client: Spotify, search_str: str) -> Paging:
def _search(limit: int, offset: int) -> Paging:
return Paging(**client.search(search_str, limit=limit, offset=offset, type="album")["albums"])
return _search
def search_albums(client: Spotify, search_str: str) -> Iterable[SearchAlbum]:
"Display albums from a search string"
for item in exhaust(_search_albums(client, search_str)):
yield SearchAlbum(**item)
def search_label_albums(client: Spotify, search_str: str) -> Iterable[SearchAlbum]:
"Display albums from a particular label"
for item in exhaust(_search_albums(client, f'label:"{search_str}"')):
yield SearchAlbum(**item)