2021-07-29 20:20:49 +02:00
|
|
|
"""Streamrip specific exceptions."""
|
2021-07-29 07:29:30 +02:00
|
|
|
|
2021-07-30 20:39:51 +02:00
|
|
|
from click import echo, style
|
2021-07-06 23:02:22 +02:00
|
|
|
|
|
|
|
|
2021-03-22 17:21:27 +01:00
|
|
|
class AuthenticationError(Exception):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""AuthenticationError."""
|
2021-03-22 17:21:27 +01:00
|
|
|
|
|
|
|
|
2023-12-22 05:48:02 +01:00
|
|
|
class MissingCredentialsError(Exception):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""MissingCredentials."""
|
2021-06-20 03:58:31 +02:00
|
|
|
|
|
|
|
|
2021-03-22 17:21:27 +01:00
|
|
|
class IneligibleError(Exception):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""IneligibleError.
|
|
|
|
|
|
|
|
Raised when the account is not eligible to stream a track.
|
|
|
|
"""
|
2021-03-22 17:21:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
class InvalidAppIdError(Exception):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""InvalidAppIdError."""
|
2021-03-22 17:21:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
class InvalidAppSecretError(Exception):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""InvalidAppSecretError."""
|
2021-03-22 17:21:27 +01:00
|
|
|
|
|
|
|
|
2023-12-22 05:48:02 +01:00
|
|
|
class NonStreamableError(Exception):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""Item is not streamable.
|
|
|
|
|
|
|
|
A versatile error that can have many causes.
|
|
|
|
"""
|
|
|
|
|
2021-07-06 23:02:22 +02:00
|
|
|
def __init__(self, message=None):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""Create a NonStreamable exception.
|
|
|
|
|
|
|
|
:param message:
|
|
|
|
"""
|
2021-07-06 23:02:22 +02:00
|
|
|
self.message = message
|
|
|
|
super().__init__(self.message)
|
|
|
|
|
|
|
|
def print(self, item):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""Print a readable version of the exception.
|
|
|
|
|
|
|
|
:param item:
|
|
|
|
"""
|
2021-07-30 20:24:09 +02:00
|
|
|
echo(self.print_msg(item))
|
2021-07-07 00:01:28 +02:00
|
|
|
|
|
|
|
def print_msg(self, item) -> str:
|
2021-07-29 20:20:49 +02:00
|
|
|
"""Return a generic readable message.
|
|
|
|
|
|
|
|
:param item:
|
|
|
|
:type item: Media
|
|
|
|
:rtype: str
|
|
|
|
"""
|
2021-07-30 20:24:09 +02:00
|
|
|
base_msg = [style(f"Unable to stream {item!s}.", fg="yellow")]
|
2021-07-06 23:02:22 +02:00
|
|
|
if self.message:
|
2021-07-15 22:37:20 +02:00
|
|
|
base_msg.extend(
|
|
|
|
(
|
2021-07-30 20:24:09 +02:00
|
|
|
style("Message:", fg="yellow"),
|
|
|
|
style(self.message, fg="red"),
|
2023-12-21 01:55:34 +01:00
|
|
|
),
|
2021-07-07 00:01:28 +02:00
|
|
|
)
|
|
|
|
|
2021-07-15 22:37:20 +02:00
|
|
|
return " ".join(base_msg)
|
2021-03-22 17:21:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ConversionError(Exception):
|
2021-07-29 20:20:49 +02:00
|
|
|
"""ConversionError."""
|