Skip to content

Instantly share code, notes, and snippets.

@akarsh1995
Created September 4, 2020 15:23
Show Gist options
  • Select an option

  • Save akarsh1995/389dda206d3b8a463a471b421b2b7042 to your computer and use it in GitHub Desktop.

Select an option

Save akarsh1995/389dda206d3b8a463a471b421b2b7042 to your computer and use it in GitHub Desktop.
Download youtube videos like a pro 😎.
youtube-dl==2020.7.28
import youtube_dl
def download_video(video_url):
try:
video_url = video_url.strip()
with youtube_dl.YoutubeDL({}) as ydl:
ydl.download([video_url])
print('We have finished downloading your video!, Enjoy ;)')
except Exception:
print('Either link is incorrect or an error has occured.')
if __name__ == '__main__':
import sys
url_arg = sys.argv[-1] # grep an argument
url = url_arg if url_arg.startswith('https://www.youtube.com') else None
video_url = url or 'https://www.youtube.com/watch?v=60ItHLz5WEA'
download_video(video_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment