ИС
Size: a a a
ИС
ИС
ZE
M
b
def search(
self,
q: str = None,
search_type: SEARCH_TYPE = SEARCH_TYPE.TRACK,
market: Optional[str] = None,
limit: int = 20,
offset: int = 0,
include_external: str = None,
) -> Result:
if limit > 50 or limit < 0:
raise ValueError("Limit should be less or equal 50")
query = {
"q": q,
"type": search_type,
"limit": 50 if limit == 0 else limit,
"offset": offset,
"market": market,
"include_external": include_external,
}
response = self.get("/search", params=query)
result = Result(
albums=[
Album(_album) for _album in response.albums.get("items", [])
],
tracks=[
Track(_track) for _track in response.tracks.get("items", [])
],
artists=[
Artist(_artist)
for _artist in response.artists.get("items", [])
],
next_albums=response.albums.next,
next_tracks=response.tracks.next,
next_artists=response.artists.next,
)
total_results = result
if limit == 0:
while True:
next_res = None
if search_type == SEARCH_TYPE.TRACK:
next_res = result.next_tracks
elif search_type == SEARCH_TYPE.ARTIST:
next_res = result.next_artists
elif search_type == SEARCH_TYPE.ALBUM:
next_res = result.next_albums
if next_res:
result = self.next(next_res)
if search_type == SEARCH_TYPE.TRACK:
total_results.tracks = (
total_results.tracks + result.tracks
)
elif search_type == SEARCH_TYPE.ARTIST:
total_results.artists = (
total_results.artists + result.artists
)
elif search_type == SEARCH_TYPE.ALBUM:
total_results.albums = (
total_results.albums + result.albums
)
else:
break
continue
else:
break
return total_results
ИС
ИС
ИС
b
ИС