Skip to content

Instantly share code, notes, and snippets.

@mateusjunges
Last active December 19, 2022 03:15
Show Gist options
  • Save mateusjunges/eb91b7f18e42fd7474504934520fb3c6 to your computer and use it in GitHub Desktop.
Save mateusjunges/eb91b7f18e42fd7474504934520fb3c6 to your computer and use it in GitHub Desktop.
from pytube import YouTube
import os
def Download(link, output):
print("Downloading...\n\n")
youtubeObject = YouTube(link)
video = youtubeObject.streams.get_highest_resolution()
try:
video.download(output)
except Exception as e:
print("There was an error while downloading your YT video\n")
print(str(e))
exit()
print("Download completed!")
video_url = input("Please, paste the URL to the video you want to download:\n")
current_user = os.getlogin()
defaultPath = "/home/" + current_user + "/Videos/"
outputPath = str(input("Where do you want to save this video? (" + defaultPath + ")\n") or defaultPath)
if len(video_url) > 0:
Download(video_url, outputPath)
else:
print("No URL provided.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment