Merge pull request #591 from tcely/patch-5
Handle raise_no_formats exception
This commit is contained in:
2 files changed
+45
-2
No files matched your search
+10
-1
@@ -1499,7 +1499,16 @@ class Media(models.Model):
|
||||
if not callable(indexer):
|
||||
raise Exception(f'Media with source type f"{self.source.source_type}" '
|
||||
f'has no indexer')
|
||||
return indexer(self.url)
|
||||
response = indexer(self.url)
|
||||
no_formats_available = (
|
||||
not response or
|
||||
"formats" not in response.keys() or
|
||||
0 == len(response["formats"])
|
||||
)
|
||||
if no_formats_available:
|
||||
self.can_download = False
|
||||
self.skip = True
|
||||
return response
|
||||
|
||||
def calculate_episode_number(self):
|
||||
if self.source.source_type == Source.SOURCE_TYPE_YOUTUBE_PLAYLIST:
|
||||
|
||||
@@ -73,6 +73,26 @@ def get_channel_image_info(url):
|
||||
raise YouTubeError(f'Failed to extract channel info for "{url}": {e}') from e
|
||||
|
||||
|
||||
def _subscriber_only(msg='', response=None):
|
||||
if response is None:
|
||||
# process msg only
|
||||
msg = str(msg)
|
||||
if 'access to members-only content' in msg:
|
||||
return True
|
||||
if ': Join this channel' in msg:
|
||||
return True
|
||||
else:
|
||||
# ignore msg entirely
|
||||
if not isinstance(response, dict):
|
||||
raise TypeError(f'response must be a dict, got "{type(response)}" instead')
|
||||
|
||||
if 'availability' not in response.keys():
|
||||
return False
|
||||
|
||||
# check for the specific expected value
|
||||
return 'subscriber_only' == response.get('availability')
|
||||
return False
|
||||
|
||||
|
||||
def get_media_info(url):
|
||||
'''
|
||||
@@ -82,6 +102,8 @@ def get_media_info(url):
|
||||
'''
|
||||
opts = get_yt_opts()
|
||||
opts.update({
|
||||
'ignoreerrors': False, # explicitly set this to catch exceptions
|
||||
'ignore_no_formats_error': False, # we must fail first to try again with this enabled
|
||||
'skip_download': True,
|
||||
'simulate': True,
|
||||
'logger': log,
|
||||
@@ -92,7 +114,19 @@ def get_media_info(url):
|
||||
try:
|
||||
response = y.extract_info(url, download=False)
|
||||
except yt_dlp.utils.DownloadError as e:
|
||||
raise YouTubeError(f'Failed to extract_info for "{url}": {e}') from e
|
||||
if not _subscriber_only(msg=e.msg):
|
||||
raise YouTubeError(f'Failed to extract_info for "{url}": {e}') from e
|
||||
# adjust options and try again
|
||||
opts.update({'ignore_no_formats_error': True,})
|
||||
with yt_dlp.YoutubeDL(opts) as yy:
|
||||
try:
|
||||
response = yy.extract_info(url, download=False)
|
||||
except yt_dlp.utils.DownloadError as ee:
|
||||
raise YouTubeError(f'Failed (again) to extract_info for "{url}": {ee}') from ee
|
||||
# validate the response is what we expected
|
||||
if not _subscriber_only(response=response):
|
||||
response = {}
|
||||
|
||||
if not response:
|
||||
raise YouTubeError(f'Failed to extract_info for "{url}": No metadata was '
|
||||
f'returned by youtube-dl, check for error messages in the '
|
||||
|
||||
Reference in new issue
Block a user