Last active
January 28, 2020 11:03
-
-
Save bowbowbow/ec9a0f9ef1bb3f136a05a21af4bb69a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup
Run