Created
September 4, 2020 15:23
-
-
Save akarsh1995/389dda206d3b8a463a471b421b2b7042 to your computer and use it in GitHub Desktop.
Download youtube videos like a pro π.
This file contains hidden or 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
| youtube-dl==2020.7.28 |
This file contains hidden or 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 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