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:
parent
00eb865b3c
commit
0621db19e4
@ -214,19 +214,21 @@ 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):
|
||||||
|
|
||||||
|
def _get_captions_for_language(language):
|
||||||
captions = None
|
captions = None
|
||||||
if clip_id:
|
if clip_id:
|
||||||
captions = self._download_json(
|
captions = self._download_json(
|
||||||
'%s/transcript/api/v1/caption/json/%s/%s'
|
'%s/transcript/api/v1/caption/json/%s/%s'
|
||||||
% (self._API_BASE, clip_id, lang), video_id,
|
% (self._API_BASE, clip_id, language), video_id,
|
||||||
'Downloading captions JSON', 'Unable to download captions JSON',
|
'Downloading captions JSON', 'Unable to download captions JSON',
|
||||||
fatal=False)
|
fatal=False)
|
||||||
if not captions:
|
if not captions:
|
||||||
captions_post = {
|
captions_post = {
|
||||||
'a': author,
|
'a': author,
|
||||||
'cn': int(clip_idx),
|
'cn': int(clip_idx),
|
||||||
'lc': lang,
|
'lc': language,
|
||||||
'm': name,
|
'm': name,
|
||||||
}
|
}
|
||||||
captions = self._download_json(
|
captions = self._download_json(
|
||||||
@ -234,16 +236,12 @@ query viewClip {
|
|||||||
'Downloading captions JSON', 'Unable to download captions JSON',
|
'Downloading captions JSON', 'Unable to download captions JSON',
|
||||||
fatal=False, data=json.dumps(captions_post).encode('utf-8'),
|
fatal=False, data=json.dumps(captions_post).encode('utf-8'),
|
||||||
headers={'Content-Type': 'application/json;charset=utf-8'})
|
headers={'Content-Type': 'application/json;charset=utf-8'})
|
||||||
|
|
||||||
if captions:
|
if captions:
|
||||||
return {
|
return [{'ext': 'json', 'data': json.dumps(captions), },
|
||||||
lang: [{
|
{'ext': 'srt', 'data': self._convert_subtitles(duration, captions), }]
|
||||||
'ext': 'json',
|
|
||||||
'data': json.dumps(captions),
|
return {language: _get_captions_for_language(language) for language in languages}
|
||||||
}, {
|
|
||||||
'ext': 'srt',
|
|
||||||
'data': self._convert_subtitles(duration, captions),
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
|
|
||||||
@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,
|
||||||
|
Loading…
Reference in New Issue
Block a user