Skip to content

Instantly share code, notes, and snippets.

@bowbowbow
Last active January 28, 2020 11:03
Show Gist options
  • Save bowbowbow/ec9a0f9ef1bb3f136a05a21af4bb69a1 to your computer and use it in GitHub Desktop.
Save bowbowbow/ec9a0f9ef1bb3f136a05a21af4bb69a1 to your computer and use it in GitHub Desktop.
import os
import pysrt
def download_youtube_srt(link):
video_id = link[link.find('?v=') + 3:]
import subprocess
subprocess.call(['youtube-dl',
# for sub
'--sub-lang', 'en',
'--write-sub',
'--convert-subs', 'srt',
# for filename
'--output', './' + video_id + '.%(ext)s',
link,
])
srt_path = os.path.abspath(os.path.dirname(__file__) + '/{}.en.srt'.format(video_id))
subs = pysrt.open(srt_path)
for sub in subs:
print(sub.start)
print(sub.end)
print(sub.text)
if __name__ == '__main__':
download_youtube_srt('https://www.youtube.com/watch?v=ir5yzW0yIk0')
@bowbowbow
Copy link
Author

Setup

pip install youtube-dl
pip install pysrt

Run

python download_youtube_srt.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment