diff --git a/src/delarte/__main__.py b/src/delarte/__main__.py index 350c5cb..4065fff 100644 --- a/src/delarte/__main__.py +++ b/src/delarte/__main__.py @@ -14,14 +14,14 @@ import time import requests -from . import api, cli, common, hls, muxing, naming, www +from . import api, cli, error, hls, muxing, naming, www -class Abort(common.Error): +class Abort(error.ModuleError): """Aborted.""" -class Fail(common.UnexpectedError): +class Fail(error.UnexpectedError): """Unexpected error.""" @@ -181,29 +181,31 @@ def main(): with hls.download_source(http_session, source, progress) as local_source: muxing.mux_source(local_source, file_name, progress) - except common.UnexpectedError as e: + except error.UnexpectedError as e: print(str(e)) + print() print( - "This program is the result of browser/server traffic analysis and involves " - "some level of trying and guessing. This error might mean that we did not try " - "enough of that we guessed poorly." + "This program is the result of browser/server traffic analysis and involves\n" + "some level of trying and guessing. This error might mean that we did not try\n" + "enough or that we guessed poorly." ) + print("") print("Please consider submitting the issue to us so we may fix it.") print("") print("Issue tracker: https://git.afpy.org/fcode/delarte/issues") - print(f"Title: {e.args(0)}") + print(f"Title: {e.args[0]}") print("Body:") print(f" {repr(e)}") return 1 - except common.Error as e: + except error.ModuleError as e: print(str(e)) - print(repr(e)) + # print(repr(e)) return 1 except requests.HTTPError as e: print("Network error.") - print(str(e)) + # print(str(e)) return 1 diff --git a/src/delarte/api.py b/src/delarte/api.py index ea32171..88b1bbe 100644 --- a/src/delarte/api.py +++ b/src/delarte/api.py @@ -3,20 +3,20 @@ """Provide ArteTV JSON API utilities.""" -from . import common, model +from . import error, model MIME_TYPE = "application/vnd.api+json; charset=utf-8" -class UnexpectedResponse(common.UnexpectedError): +class UnexpectedResponse(error.UnexpectedError): """Unexpected response from ArteTV.""" -class NotFound(common.Error): +class NotFound(error.ModuleError): """Program not found on ArteTV.""" -class UnsupportedProtocol(common.Error): +class UnsupportedProtocol(error.ModuleError): """Program type not supported.""" diff --git a/src/delarte/common.py b/src/delarte/error.py similarity index 84% rename from src/delarte/common.py rename to src/delarte/error.py index 9849fa5..93d70f4 100644 --- a/src/delarte/common.py +++ b/src/delarte/error.py @@ -4,8 +4,8 @@ """Provide common utilities.""" -class Error(Exception): - """General error.""" +class ModuleError(Exception): + """Module error.""" def __str__(self): """Use the class definition docstring as a string representation.""" @@ -16,5 +16,5 @@ class Error(Exception): return f"{self.__class__.__qualname__}{self.args!r}" -class UnexpectedError(Error): +class UnexpectedError(ModuleError): """An error to report to developers.""" diff --git a/src/delarte/hls.py b/src/delarte/hls.py index c66d7a7..3429183 100644 --- a/src/delarte/hls.py +++ b/src/delarte/hls.py @@ -66,7 +66,7 @@ from tempfile import NamedTemporaryFile import m3u8 import webvtt -from . import common, model +from . import error, model # # WARNING ! @@ -84,7 +84,7 @@ from . import common, model # - Subtitles media playlists have only one segment -class UnexpectedResponse(common.UnexpectedError): +class UnexpectedResponse(error.UnexpectedError): """Unexpected response from ArteTV.""" diff --git a/src/delarte/www.py b/src/delarte/www.py index 4c52418..a85f7e9 100644 --- a/src/delarte/www.py +++ b/src/delarte/www.py @@ -3,13 +3,13 @@ """Provide ArteTV website utilities.""" -from . import common +from . import error BASE = "https://www.arte.tv/" LANGUAGES = ["fr", "de", "en", "es", "pl", "it"] -class InvalidUrl(common.Error): +class InvalidUrl(error.ModuleError): """Invalid ArteTV URL."""