Created
September 15, 2017 22:18
-
-
Save jordanemedlock/b68c0decdccad10007cbfc8b00b09d7e to your computer and use it in GitHub Desktop.
This file contains 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
from pytube import YouTube | |
from pprint import pprint | |
import sys | |
if len(sys.argv) > 1: | |
vid = sys.argv[1] | |
else: | |
print('Usage - python3 youtube_download.py VIDEO_ID') | |
sys.exit(1) | |
try: | |
yt = YouTube("http://www.youtube.com/watch?v={}".format(vid)) | |
except e: | |
print('Failed to get video with id', vid) | |
sys.exit(1) | |
yt.set_filename(yt.filename + '_' + vid) | |
if len(yt.filter('mp4')) > 0: | |
if len(yt.filter('mp4', '720p')) > 0: | |
video = yt.get('mp4', '720p') | |
else: | |
video = yt.filter('mp4')[-1] | |
else: | |
print('No mp4 formatted videos') | |
sys.exit(1) | |
def on_progress(so_far, total, start): | |
pass | |
def on_finish(filename): | |
print('on_finish({})'.format(filename)) | |
video.download('.', on_progress=on_progress, on_finish=on_finish) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment