Skip to content

Commit

Permalink
Handle NonStreamableError for metadata parsing (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathom committed Jan 24, 2024
1 parent 1c2bd25 commit 24d23ad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
10 changes: 9 additions & 1 deletion streamrip/media/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..client import Client
from ..config import Config
from ..db import Database
from ..exceptions import NonStreamableError
from ..filepath_utils import clean_filepath
from ..metadata import AlbumMetadata
from ..metadata.util import get_album_track_ids
Expand Down Expand Up @@ -50,7 +51,14 @@ class PendingAlbum(Pending):
db: Database

async def resolve(self) -> Album | None:
resp = await self.client.get_metadata(self.id, "album")
try:
resp = await self.client.get_metadata(self.id, "album")
except NonStreamableError as e:
logger.error(
f"Album {self.id} not available to stream on {self.client.source} ({e})",
)
return None

meta = AlbumMetadata.from_album_resp(resp, self.client.source)
if meta is None:
logger.error(
Expand Down
12 changes: 10 additions & 2 deletions streamrip/media/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..config import Config, QobuzDiscographyFilterConfig
from ..console import console
from ..db import Database
from ..exceptions import NonStreamableError
from ..metadata import ArtistMetadata
from .album import Album, PendingAlbum
from .media import Media, Pending
Expand Down Expand Up @@ -180,8 +181,15 @@ class PendingArtist(Pending):
config: Config
db: Database

async def resolve(self) -> Artist:
resp = await self.client.get_metadata(self.id, "artist")
async def resolve(self) -> Artist | None:
try:
resp = await self.client.get_metadata(self.id, "artist")
except NonStreamableError as e:
logger.error(
f"Artist {self.id} not available to stream on {self.client.source} ({e})",
)
return None

meta = ArtistMetadata.from_resp(resp, self.client.source)
albums = [
PendingAlbum(album_id, self.client, self.config, self.db)
Expand Down
10 changes: 9 additions & 1 deletion streamrip/media/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ class PendingPlaylist(Pending):
db: Database

async def resolve(self) -> Playlist | None:
resp = await self.client.get_metadata(self.id, "playlist")
try:
resp = await self.client.get_metadata(self.id, "playlist")
except NonStreamableError as e:
logger.error(
f"Playlist {self.id} not available to stream on {self.client.source} ({e})",
)
return None

meta = PlaylistMetadata.from_resp(resp, self.client.source)
name = meta.name
parent = self.config.session.downloads.folder
Expand Down Expand Up @@ -261,6 +268,7 @@ async def _make_query(
if that fails.
Args:
----
query (str): Query to search
s (Status):
callback: function to call after each query completes
Expand Down

0 comments on commit 24d23ad

Please sign in to comment.