1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-11-29 19:47:54 +01:00

[pluralsight] multiple subtitles download

This commit is contained in:
Jaime Bergas Laborda 2020-04-17 10:44:31 +01:00
parent 00eb865b3c
commit 0621db19e4

View File

@ -214,36 +214,34 @@ query viewClip {
raise ExtractorError('Unable to log in') raise ExtractorError('Unable to log in')
def _get_subtitles(self, author, clip_idx, clip_id, lang, name, duration, video_id): def _get_subtitles(self, author, clip_idx, clip_id, languages, name, duration, video_id):
captions = None
if clip_id: def _get_captions_for_language(language):
captions = self._download_json( captions = None
'%s/transcript/api/v1/caption/json/%s/%s' if clip_id:
% (self._API_BASE, clip_id, lang), video_id, captions = self._download_json(
'Downloading captions JSON', 'Unable to download captions JSON', '%s/transcript/api/v1/caption/json/%s/%s'
fatal=False) % (self._API_BASE, clip_id, language), video_id,
if not captions: 'Downloading captions JSON', 'Unable to download captions JSON',
captions_post = { fatal=False)
'a': author, if not captions:
'cn': int(clip_idx), captions_post = {
'lc': lang, 'a': author,
'm': name, 'cn': int(clip_idx),
} 'lc': language,
captions = self._download_json( 'm': name,
'%s/player/retrieve-captions' % self._API_BASE, video_id, }
'Downloading captions JSON', 'Unable to download captions JSON', captions = self._download_json(
fatal=False, data=json.dumps(captions_post).encode('utf-8'), '%s/player/retrieve-captions' % self._API_BASE, video_id,
headers={'Content-Type': 'application/json;charset=utf-8'}) 'Downloading captions JSON', 'Unable to download captions JSON',
if captions: fatal=False, data=json.dumps(captions_post).encode('utf-8'),
return { headers={'Content-Type': 'application/json;charset=utf-8'})
lang: [{
'ext': 'json', if captions:
'data': json.dumps(captions), return [{'ext': 'json', 'data': json.dumps(captions), },
}, { {'ext': 'srt', 'data': self._convert_subtitles(duration, captions), }]
'ext': 'srt',
'data': self._convert_subtitles(duration, captions), return {language: _get_captions_for_language(language) for language in languages}
}]
}
@staticmethod @staticmethod
def _convert_subtitles(duration, subs): def _convert_subtitles(duration, subs):
@ -423,9 +421,13 @@ query viewClip {
duration = int_or_none( duration = int_or_none(
clip.get('duration')) or parse_duration(clip.get('formattedDuration')) clip.get('duration')) or parse_duration(clip.get('formattedDuration'))
# TODO: other languages? available_languages = [language['code'] for language in course['translationLanguages']]
requested_languages = self._downloader.params['subtitleslangs']
languages_to_retrieve = set(available_languages).intersection(requested_languages)
subtitles = self.extract_subtitles( subtitles = self.extract_subtitles(
author, clip_idx, clip.get('clipId'), 'en', name, duration, display_id) author, clip_idx, clip.get('clipId'), languages_to_retrieve, name, duration, display_id)
return { return {
'id': clip_id, 'id': clip_id,