mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-30 12:01:28 +00:00
[youtube] Add support for automatically translated subtitles (fixes #4555)
They have a manually uploaded subtitles track and YouTube can transtale it.
This commit is contained in:
parent
1931a73f39
commit
7d900ef1bf
|
@ -88,6 +88,14 @@ def test_youtube_automatic_captions(self):
|
||||||
subtitles = self.getSubtitles()
|
subtitles = self.getSubtitles()
|
||||||
self.assertTrue(subtitles['it'] is not None)
|
self.assertTrue(subtitles['it'] is not None)
|
||||||
|
|
||||||
|
def test_youtube_translated_subtitles(self):
|
||||||
|
# This video has a subtitles track, which can be translated
|
||||||
|
self.url = 'Ky9eprVWzlI'
|
||||||
|
self.DL.params['writeautomaticsub'] = True
|
||||||
|
self.DL.params['subtitleslangs'] = ['it']
|
||||||
|
subtitles = self.getSubtitles()
|
||||||
|
self.assertTrue(subtitles['it'] is not None)
|
||||||
|
|
||||||
def test_youtube_nosubtitles(self):
|
def test_youtube_nosubtitles(self):
|
||||||
self.DL.expect_warning('video doesn\'t have subtitles')
|
self.DL.expect_warning('video doesn\'t have subtitles')
|
||||||
self.url = 'n5BB19UTcdA'
|
self.url = 'n5BB19UTcdA'
|
||||||
|
|
|
@ -662,10 +662,11 @@ def _get_available_automatic_caption(self, video_id, webpage):
|
||||||
list_url = caption_url + '&' + list_params
|
list_url = caption_url + '&' + list_params
|
||||||
caption_list = self._download_xml(list_url, video_id)
|
caption_list = self._download_xml(list_url, video_id)
|
||||||
original_lang_node = caption_list.find('track')
|
original_lang_node = caption_list.find('track')
|
||||||
if original_lang_node is None or original_lang_node.attrib.get('kind') != 'asr':
|
if original_lang_node is None:
|
||||||
self._downloader.report_warning('Video doesn\'t have automatic captions')
|
self._downloader.report_warning('Video doesn\'t have automatic captions')
|
||||||
return {}
|
return {}
|
||||||
original_lang = original_lang_node.attrib['lang_code']
|
original_lang = original_lang_node.attrib['lang_code']
|
||||||
|
caption_kind = original_lang_node.attrib.get('kind', '')
|
||||||
|
|
||||||
sub_lang_list = {}
|
sub_lang_list = {}
|
||||||
for lang_node in caption_list.findall('target'):
|
for lang_node in caption_list.findall('target'):
|
||||||
|
@ -675,7 +676,7 @@ def _get_available_automatic_caption(self, video_id, webpage):
|
||||||
'tlang': sub_lang,
|
'tlang': sub_lang,
|
||||||
'fmt': sub_format,
|
'fmt': sub_format,
|
||||||
'ts': timestamp,
|
'ts': timestamp,
|
||||||
'kind': 'asr',
|
'kind': caption_kind,
|
||||||
})
|
})
|
||||||
sub_lang_list[sub_lang] = caption_url + '&' + params
|
sub_lang_list[sub_lang] = caption_url + '&' + params
|
||||||
return sub_lang_list
|
return sub_lang_list
|
||||||
|
|
Loading…
Reference in a new issue