question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Download auto-generated translations

See original GitHub issue

This is a feature request.

YouTube also offers auto (google) translated versions of the subtitles. I would like to be able to download those. Is there a reason why the auto-generated original language is listed when I run yt.captions.all(), but the auto-translated versions aren’t?

Is it possible to also get those from the API? If so I’d be happy to make a PR with the necessary changes.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Tiriarcommented, Jul 14, 2020

Note that the caption URL also has a parameter asr_langs, which includes a list of languages that the caption can be translated to.

For the time being, I am using this code as a workaround to get translation from any captions that support it:

from urllib.parse import parse_qs, urlparse

from pytube import YouTube
from pytube.captions import Caption

def get_srt(url, lang='en'):
    video = YouTube(url)
    captions = video.captions.get(lang)

    if not captions:
        for c in video.captions:
            params = parse_qs(urlparse(c.url).query)
            asr_lang = params.get('asr_langs')
            if asr_lang and lang in asr_lang[0].split(','):
                captions = Caption({
                    'baseUrl': f'{c.url}&tlang={lang}',
                    'languageCode': lang,
                    'name': {'simpleText': 'ASR'}
                })
                break

    if not captions:
        raise KeyError

    return captions.generate_srt_captions()
0reactions
github-actions[bot]commented, Sep 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I download auto generated subtitles in YouTube?
Under subtitles, click ADD. They appear automatically in the language of the video but you can get any language you want by publishing...
Read more >
Download auto-generated translations · Issue #461
I would like to be able to download those. Is there a reason why the auto-generated original language is listed when I run...
Read more >
How To Download Automatically Generated Subtitles?
But do you know how to download automatically generated subtitles? Here are 5 online subtitle download tools for video makers. 1. EasySub. EasySub...
Read more >
5 Proven Ways to Download YouTube Subtitles as SRT ...
5 best desktop & online YouTube subtitle download tools to save auto-generated & translated closed caption from YouTube video/playlist as SRT format or ......
Read more >
Is it possible to download the automatic captions from a ...
You can download automatic captions for virtually any "public" or "unlisted" ... This will download the video along with the auto-generated ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found