mirror of
https://github.com/glomatico/votify.git
synced 2026-09-30 04:52:30 +02:00
Standardize media exceptions and update handlers
This commit is contained in:
@@ -31,7 +31,6 @@ class SpotifyAudioInterface(SpotifyBaseInterface):
|
||||
):
|
||||
raise VotifyMediaAudioQualityNotAvailableException(
|
||||
media_id=playback_info["metadata"]["uri"].split(":")[-1],
|
||||
playback_info=playback_info,
|
||||
)
|
||||
|
||||
file_id = None
|
||||
|
||||
@@ -3,7 +3,8 @@ import logging
|
||||
from .audio import SpotifyAudioInterface
|
||||
from .constants import COVER_SIZE_ID_MAP_EPISODE, DEFAULT_EPISODE_DECRYPTION_KEY
|
||||
from .enums import MediaType
|
||||
from .types import MediaTags, SpotifyMedia, DecryptionKey, DecryptionKeyAv
|
||||
from .exceptions import VotifyMediaAudioQualityNotAvailableException
|
||||
from .types import DecryptionKey, DecryptionKeyAv, MediaTags, SpotifyMedia
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -47,7 +48,12 @@ class SpotifyEpisodeInterface(SpotifyAudioInterface):
|
||||
episode_data["coverArt"]["sources"][0]["url"]
|
||||
)
|
||||
|
||||
media.stream_info = await self.get_stream_info(playback_info, True)
|
||||
try:
|
||||
media.stream_info = await self.get_stream_info(playback_info, True)
|
||||
except VotifyMediaAudioQualityNotAvailableException as e:
|
||||
e.media_metadata = episode_data
|
||||
raise
|
||||
|
||||
media.decryption_key = DecryptionKeyAv(
|
||||
DecryptionKey(
|
||||
decryption_key=DEFAULT_EPISODE_DECRYPTION_KEY,
|
||||
|
||||
@@ -15,33 +15,49 @@ class VotifyUnsupportedMediaTypeException(VotiyException):
|
||||
self.media_type = media_type
|
||||
|
||||
|
||||
class VotifyDrmDisabledException(VotiyException):
|
||||
def __init__(self, media_id: str, media_metadata: dict | None = None):
|
||||
super().__init__(f"DRM is disabled, cannot process media: {media_id}")
|
||||
class VotifyMediaException(VotiyException):
|
||||
def __init__(self, message: str, media_id: str, media_metadata: dict | None = None):
|
||||
super().__init__(f"{message}: {media_id}")
|
||||
|
||||
self.media_id = media_id
|
||||
self.media_metadata = media_metadata
|
||||
|
||||
|
||||
class VotifyMediaNotFoundException(VotiyException):
|
||||
class VotifyDrmDisabledException(VotifyMediaException):
|
||||
def __init__(self, media_id: str, media_metadata: dict | None = None):
|
||||
super().__init__(f"Media not found: {media_id}")
|
||||
|
||||
self.media_id = media_id
|
||||
self.media_metadata = media_metadata
|
||||
super().__init__(
|
||||
"DRM is disabled, cannot process media",
|
||||
media_id=media_id,
|
||||
media_metadata=media_metadata,
|
||||
)
|
||||
|
||||
|
||||
class VotifyMediaUnstreamableException(VotiyException):
|
||||
class VotifyMediaNotFoundException(VotifyMediaException):
|
||||
def __init__(self, media_id: str, media_metadata: dict | None = None):
|
||||
super().__init__(f"Media is not streamable: {media_id}")
|
||||
|
||||
self.media_id = media_id
|
||||
self.media_metadata = media_metadata
|
||||
super().__init__(
|
||||
"Media not found",
|
||||
media_id=media_id,
|
||||
media_metadata=media_metadata,
|
||||
)
|
||||
|
||||
|
||||
class VotifyMediaAudioQualityNotAvailableException(VotiyException):
|
||||
def __init__(self, media_id: str, playback_info: dict | None = None):
|
||||
super().__init__(f"Selected audio quality is not available: {media_id}")
|
||||
class VotifyMediaUnstreamableException(VotifyMediaException):
|
||||
def __init__(self, media_id: str, media_metadata: dict | None = None):
|
||||
super().__init__(
|
||||
"Media is not streamable",
|
||||
media_id=media_id,
|
||||
media_metadata=media_metadata,
|
||||
)
|
||||
|
||||
self.media_id = media_id
|
||||
self.playback_info = playback_info
|
||||
|
||||
class VotifyMediaAudioQualityNotAvailableException(VotifyMediaException):
|
||||
def __init__(
|
||||
self,
|
||||
media_id: str,
|
||||
media_metadata: dict | None = None,
|
||||
):
|
||||
super().__init__(
|
||||
"Selected audio quality is not available",
|
||||
media_id=media_id,
|
||||
media_metadata=media_metadata,
|
||||
)
|
||||
|
||||
@@ -6,6 +6,9 @@ from ..api import VotifyRequestException
|
||||
from .audio import SpotifyAudioInterface
|
||||
from .constants import COVER_SIZE_ID_MAP_SONG
|
||||
from .enums import MediaType
|
||||
from .exceptions import (
|
||||
VotifyMediaAudioQualityNotAvailableException,
|
||||
)
|
||||
from .types import MediaLyrics, MediaTags, SpotifyMedia
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -57,11 +60,15 @@ class SpotifySongInterface(SpotifyAudioInterface):
|
||||
media.album_metadata["coverArt"]["sources"][0]["url"]
|
||||
)
|
||||
|
||||
media.stream_info = await self.get_stream_info(playback_info, False)
|
||||
if media.stream_info is not None:
|
||||
media.decryption_key = await self.get_widevine_decryption_key(
|
||||
media.stream_info.audio_track.widevine_pssh
|
||||
)
|
||||
try:
|
||||
media.stream_info = await self.get_stream_info(playback_info, False)
|
||||
except VotifyMediaAudioQualityNotAvailableException as e:
|
||||
e.media_metadata = track_data
|
||||
raise
|
||||
|
||||
media.decryption_key = await self.get_widevine_decryption_key(
|
||||
media.stream_info.audio_track.widevine_pssh
|
||||
)
|
||||
|
||||
logger.debug(f"Processed song media: {media}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user