from __future__ import annotations
import asyncio
+import time
from collections.abc import AsyncGenerator, Callable
from typing import TYPE_CHECKING
if MediaType.PLAYLIST in media_types:
searchtypes.append("playlist")
+ time_start = time.time()
+
searchresult = await self._soundcloud.search(search_query, limit)
+ self.logger.debug(
+ "Processing Soundcloud search took %s seconds",
+ round(time.time() - time_start, 2),
+ )
+
for item in searchresult["collection"]:
media_type = item["kind"]
if media_type == "user":
result.tracks.append(await self._parse_track(item))
elif media_type == "playlist":
result.playlists.append(await self._parse_playlist(item))
+
return result
async def get_library_artists(self) -> AsyncGenerator[Artist, None]:
"""Retrieve all library artists from Soundcloud."""
+ time_start = time.time()
+
following = await self._soundcloud.get_following(self._user_id)
+ self.logger.debug(
+ "Processing Soundcloud library artists took %s seconds",
+ round(time.time() - time_start, 2),
+ )
for artist in following["collection"]:
try:
yield await self._parse_artist(artist)
async def get_library_playlists(self) -> AsyncGenerator[Playlist, None]:
"""Retrieve all library playlists from Soundcloud."""
+ time_start = time.time()
playlists = await self._soundcloud.get_account_playlists()
+ self.logger.debug(
+ "Processing Soundcloud library playlists took %s seconds",
+ round(time.time() - time_start, 2),
+ )
for item in playlists["collection"]:
- playlist_id = item["playlist"]["id"]
- playlist_obj = await self._soundcloud.get_playlist_details(playlist_id=playlist_id)
try:
+ playlist_obj = await self._soundcloud.get_playlist_details(
+ playlist_id=item["playlist"]["id"]
+ )
yield await self._parse_playlist(playlist_obj)
except (KeyError, TypeError, InvalidDataError, IndexError) as error:
self.logger.debug("Parse playlist failed: %s", playlist_obj, exc_info=error)
async def get_library_tracks(self) -> AsyncGenerator[Track, None]:
"""Retrieve library tracks from Soundcloud."""
+ time_start = time.time()
tracks = await self._soundcloud.get_tracks_liked()
+ self.logger.debug(
+ "Processing Soundcloud library tracks took %s seconds",
+ round(time.time() - time_start, 2),
+ )
for item in tracks["collection"]:
track = await self._soundcloud.get_track_details(item)
try: