From 2f0c6777b0e9842b735593eae63ce9d62c83f397 Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Mon, 23 Dec 2024 17:03:45 +1300 Subject: [PATCH] Error handling improvements --- .../extractor/_ytse/downloader/sabr.py | 23 ++++++++++++------- .../extractor/_ytse/protos/_sabr_error.py | 6 ++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/yt_dlp_plugins/extractor/_ytse/downloader/sabr.py b/yt_dlp_plugins/extractor/_ytse/downloader/sabr.py index a69c6a6..3399b2e 100644 --- a/yt_dlp_plugins/extractor/_ytse/downloader/sabr.py +++ b/yt_dlp_plugins/extractor/_ytse/downloader/sabr.py @@ -11,6 +11,7 @@ from yt_dlp.downloader import FileDownloader from yt_dlp.extractor.youtube import INNERTUBE_CLIENTS from yt_dlp.networking import Request, Response +from yt_dlp.networking.exceptions import HTTPError from yt_dlp.utils import parse_qs, traverse_obj, int_or_none, DownloadError from yt_dlp.utils._utils import _YDLLogger from yt_dlp.utils.progress import ProgressCalculator @@ -168,15 +169,21 @@ def download(self): # todo: add retry logic for network errors # For livestreams, if exceed retries, assume end of stream - response = self._urlopen( - Request( - url=self.server_abr_streaming_url, - method='POST', - data=payload, - query={'rn': request_number}, - headers={'content-type': 'application/x-protobuf'} + + try: + response = self._urlopen( + Request( + url=self.server_abr_streaming_url, + method='POST', + data=payload, + query={'rn': request_number}, + headers={'content-type': 'application/x-protobuf'} + ) ) - ) + except HTTPError as e: + self._logger.warning(f'HTTP Error: {e.status} - {e.reason}') + self.parse_ump_response(e.response) + raise DownloadError(f'HTTP Error: {e.status} - {e.reason}') self.parse_ump_response(response) diff --git a/yt_dlp_plugins/extractor/_ytse/protos/_sabr_error.py b/yt_dlp_plugins/extractor/_ytse/protos/_sabr_error.py index f6ac984..4c933aa 100644 --- a/yt_dlp_plugins/extractor/_ytse/protos/_sabr_error.py +++ b/yt_dlp_plugins/extractor/_ytse/protos/_sabr_error.py @@ -3,12 +3,12 @@ @protobug.message -class UnknownMessage: - unknown_field: typing.Optional[protobug.Int32] = protobug.field(1, default=None) +class Error: + status_code: typing.Optional[protobug.Int32] = protobug.field(1, default=None) # e.g. 403 @protobug.message class SabrError: type: typing.Optional[protobug.String] = protobug.field(1, default=None) code: typing.Optional[protobug.Int32] = protobug.field(2, default=None) - unknown_message: typing.Optional[UnknownMessage] = protobug.field(3, default=None) + errors: typing.Optional[Error] = protobug.field(3, default=None)