1
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp synced 2025-01-31 04:22:25 +01:00

Deprioritize TranscriptUrl

This commit is contained in:
kclauhk 2024-12-27 21:52:35 +08:00
parent 1508588107
commit 370347c3f8

View file

@ -7,6 +7,7 @@ from ..utils import (
ExtractorError, ExtractorError,
determine_ext, determine_ext,
float_or_none, float_or_none,
join_nonempty,
mimetype2ext, mimetype2ext,
smuggle_url, smuggle_url,
str_or_none, str_or_none,
@ -269,11 +270,11 @@ class MediasiteIE(InfoExtractor):
formats.extend(stream_formats) formats.extend(stream_formats)
# XXX: Presentation['Presenters'] # XXX: Presentation['Presenters']
transcripts = presentation.get('Transcripts', {}) transcripts = presentation.get('Transcripts', [])
captions, subtitles = {}, {} captions, subtitles = {}, {}
for transcript in transcripts: for transcript in transcripts:
lang_code = traverse_obj( lang_code = traverse_obj(
transcript, (('DetailedLanguageCode', 'LanguageCode'), {str}), get_all=False) transcript, (('DetailedLanguageCode', 'LanguageCode'), {str}), get_all=False) or 'und'
lang_name = transcript.get('Language') lang_name = transcript.get('Language')
t = { t = {
'url': transcript.get('CaptionsUrl'), 'url': transcript.get('CaptionsUrl'),
@ -283,15 +284,19 @@ class MediasiteIE(InfoExtractor):
captions.setdefault(lang_code, []).append(t) captions.setdefault(lang_code, []).append(t)
else: else:
subtitles.setdefault(lang_code, []).append(t) subtitles.setdefault(lang_code, []).append(t)
if transcript_url := presentation.get('TranscriptUrl'): if transcript_url := url_or_none(presentation.get('TranscriptUrl')):
if 'playbackTicket=' not in transcript_url:
transcript_url = join_nonempty(
transcript_url, traverse_obj(presentation, ('Streams', 0, 'SlidePlaybackTicketId', {str})),
delim='?playbackTicket=')
if determine_ext(transcript_url) != 'txt': if determine_ext(transcript_url) != 'txt':
if len(transcripts) == 1: if len(transcripts) == 1:
(captions or subtitles).setdefault(lang_code, []).append({ (captions or subtitles)[lang_code].insert(0, {
'url': transcript_url, 'url': transcript_url,
'name': lang_name, 'name': lang_name,
}) })
else: else:
subtitles.setdefault('und', []).append({'url': transcript_url}) subtitles.setdefault('und', []).insert(0, {'url': transcript_url})
return { return {
'id': resource_id, 'id': resource_id,