Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[extractor/TwitCasting] fix: Use UserNotLive #7975

Merged
merged 6 commits into from Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/test_download.py
Expand Up @@ -31,6 +31,7 @@
DownloadError,
ExtractorError,
UnavailableVideoError,
YoutubeDLError,
format_bytes,
join_nonempty,
)
Expand Down Expand Up @@ -100,6 +101,8 @@ def print_skipping(reason):
print_skipping('IE marked as not _WORKING')

for tc in test_cases:
if tc.get('expected_exception'):
continue
info_dict = tc.get('info_dict', {})
params = tc.get('params', {})
if not info_dict.get('id'):
Expand Down Expand Up @@ -139,6 +142,17 @@ def get_tc_filename(tc):

res_dict = None

def match_exception(err):
expected_exception = test_case.get('expected_exception', None)
bashonly marked this conversation as resolved.
Show resolved Hide resolved
if not expected_exception:
return False
if err.__class__.__name__ == expected_exception:
return True
for exc in err.exc_info:
if exc.__class__.__name__ == expected_exception:
return True
return False

def try_rm_tcs_files(tcs=None):
if tcs is None:
tcs = test_cases
Expand All @@ -161,6 +175,8 @@ def try_rm_tcs_files(tcs=None):
except (DownloadError, ExtractorError) as err:
# Check if the exception is not a network related one
if not isinstance(err.exc_info[1], (TransportError, UnavailableVideoError)) or (isinstance(err.exc_info[1], HTTPError) and err.exc_info[1].status == 503):
if match_exception(err):
return
err.msg = f'{getattr(err, "msg", err)} ({tname})'
raise

Expand All @@ -171,6 +187,10 @@ def try_rm_tcs_files(tcs=None):
print(f'Retrying: {try_num} failed tries\n\n##########\n\n')

try_num += 1
except YoutubeDLError as err:
if match_exception(err):
return
raise
else:
break

Expand Down
6 changes: 5 additions & 1 deletion yt_dlp/extractor/twitcasting.py
Expand Up @@ -7,6 +7,7 @@
from ..utils import (
clean_html,
ExtractorError,
UserNotLive,
bashonly marked this conversation as resolved.
Show resolved Hide resolved
float_or_none,
get_element_by_class,
get_element_by_id,
Expand Down Expand Up @@ -235,6 +236,9 @@ class TwitCastingLiveIE(InfoExtractor):
_TESTS = [{
'url': 'https://twitcasting.tv/ivetesangalo',
'only_matching': True,
}, {
'url': 'https://twitcasting.tv/c:unusedlive',
'expected_exception': 'UserNotLive',
}]

def _real_extract(self, url):
Expand All @@ -260,7 +264,7 @@ def _real_extract(self, url):
r'(?s)<a\s+class="tw-movie-thumbnail"\s*href="/[^/]+/movie/(?P<video_id>\d+)"\s*>.+?</a>',
webpage, 'current live ID 2', default=None, group='video_id')
if not current_live:
raise ExtractorError('The user is not currently live')
raise UserNotLive(video_id=uploader_id)
return self.url_result('https://twitcasting.tv/%s/movie/%s' % (uploader_id, current_live))


Expand Down