Skip to content

Commit

Permalink
Error handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
coletdjnz committed Dec 23, 2024
1 parent ad29340 commit 2f0c677
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 15 additions & 8 deletions yt_dlp_plugins/extractor/_ytse/downloader/sabr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions yt_dlp_plugins/extractor/_ytse/protos/_sabr_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2f0c677

Please sign in to comment.