Skip to content

Instantly share code, notes, and snippets.

@arundasan91
Created April 14, 2017 19:57
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 arundasan91/ec5176d0652ceb01d86acf7a34c273d9 to your computer and use it in GitHub Desktop.
Save arundasan91/ec5176d0652ceb01d86acf7a34c273d9 to your computer and use it in GitHub Desktop.
Function to download video's from YouTube to a specific location. Requires 'youtube-dl'.
def download_video(url, output_dir, filename, ext='mp4'):
"""Function to download video's from YouTube to a specific location.
Args:
url: YouTube URL.
output_dir: Output directory to save the video.
filename: Filename of the video.
ext: File type to save the video to. Default to mp4.
"""
import os
file_loc = output_dir + filename + "." + ext
# Download from Youtube URL
if (url):
print("Downloading Youtube Video")
os.system("youtube-dl -o " + file_loc + " -f " + ext + " " + url)
print("Done..")
else:
print("Please input a URL")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment