Created
December 7, 2019 00:22
-
-
Save smellslikeml/604f8dd6ee0b568034867df53dcbcb7c to your computer and use it in GitHub Desktop.
Download a specific video from YouTube
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
import pytube | |
def yt_download(video_id, video_path): | |
video_url = 'https://youtu.be/{}'.format(video_id) | |
youtube = pytube.YouTube(video_url) | |
video = youtube.streams.first() | |
video.download(video_path) | |
print('youtube video {} saved as: \n\n {}{}.mp4'.format(video_id, video_path, video.title)) | |
if __name__ == '__main__': | |
import os | |
import argparse | |
ap = argparse.ArgumentParser() | |
ap.add_argument("-v", "--video", type=str, required=True, | |
help="youtube video id") | |
ap.add_argument("-p", "--path", type=str, default=os.environ['HOME'] | |
+ '/Downloads/', help="video download path") | |
args = vars(ap.parse_args()) | |
yt_download(args['video'], args['path']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment