1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2025-07-05 21:08:33 +00:00

[Substack] allow multiple embeds regardless of post type

This commit is contained in:
jhwgh1968 2025-04-24 17:58:03 -05:00
parent d49565da20
commit e89132c678

View File

@ -133,7 +133,9 @@ def _real_extract(self, url):
canonical_url = urllib.parse.urlparse(url)._replace(netloc=domain).geturl()
post_type = webpage_info['post']['type']
post_title = traverse_obj(webpage_info, ('post', 'title'))
formats, subtitles = [], {}
all_results = []
result_info = {
'id': str(webpage_info['post']['id']),
'subtitles': subtitles,
@ -144,7 +146,9 @@ def _real_extract(self, url):
'uploader_id': str_or_none(traverse_obj(webpage_info, ('post', 'publication_id'))),
'webpage_url': canonical_url,
}
# handle specific post types which are based on media
if post_type == 'podcast':
podcast_result = dict(result_info)
fmt = {'url': webpage_info['post']['podcast_url']}
if not determine_ext(fmt['url'], default_ext=None):
# The redirected format URL expires but the original URL doesn't,
@ -153,21 +157,21 @@ def _real_extract(self, url):
HEADRequest(fmt['url']), display_id,
'Resolving podcast file extension',
'Podcast URL is invalid').url)
result_info['formats'] = [fmt]
return result_info
elif post_type == 'video':
podcast_result['formats'] = [fmt]
all_results.append(podcast_result)
if post_type == 'video':
video_result = dict(result_info)
formats, subtitles = self._extract_video_formats(
webpage_info['post']['videoUpload']['id'], canonical_url)
result_info.update({
video_result.update({
'formats': formats,
'subtitles': subtitles,
})
return result_info
elif post_type == 'newsletter':
results = []
all_results.append(video_result)
# search for embedded players on the page
found_items = []
post_id = str(webpage_info['post']['id'])
post_title = traverse_obj(webpage_info, ('post', 'title'))
assert result_info['uploader_id'] is not None, 'newsletter posted without user_id'
video_players = re.finditer(
@ -230,12 +234,10 @@ def _real_extract(self, url):
'uploader_id': str_or_none(json_vid_data.get('user_id', None)),
'uploader': None, # video uploader username is not included
})
results.append(new_result)
all_results.append(new_result)
if len(results) > 0:
if len(all_results) > 0:
playlist_title = f'Videos for {post_title}'
return self.playlist_result(results, post_id, playlist_title)
return self.playlist_result(all_results, post_id, playlist_title)
else:
self.raise_no_formats(f'Page type "{post_type}" contains no supported embeds')
self.raise_no_formats(f'Page type "{post_type}" is not supported')