Skip to content

Instantly share code, notes, and snippets.

@smellslikeml
Created December 7, 2019 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smellslikeml/604f8dd6ee0b568034867df53dcbcb7c to your computer and use it in GitHub Desktop.
Save smellslikeml/604f8dd6ee0b568034867df53dcbcb7c to your computer and use it in GitHub Desktop.
Download a specific video from YouTube
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