Skip to content

Instantly share code, notes, and snippets.

@nenodias
Created November 26, 2017 01:26
Show Gist options
  • Select an option

  • Save nenodias/82683be2a63bbafcbb266330de2e9a02 to your computer and use it in GitHub Desktop.

Select an option

Save nenodias/82683be2a63bbafcbb266330de2e9a02 to your computer and use it in GitHub Desktop.
YoutubePython
import sys
from pytube import YouTube
'''
yt = YouTube("https://www.youtube.com/watch?v=JGXi_9A__Vc")
'''
if __name__ == '__main__':
url = sys.argv[1]
yt = YouTube(url)
if yt:
print('Downloading {0}'.format(yt.title))
yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download()
lista_linguagens = ['pt-BR', 'pt-PT', 'en']
for linguagem in lista_linguagens:
caption = yt.captions.get_by_language_code(linguagem)
if caption:
with open(yt.title+'.srt', 'w') as f:
f.write(caption.generate_srt_captions())
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment