No title
August 03, 2023
# Import the necessary libraries
import pytube
# Function to download a YouTube video
def download_video(url, save_path):
try:
# Create a YouTube object
youtube = pytube.YouTube(url)
# Get the highest resolution stream available
video_stream = youtube.streams.get_highest_resolution()
# Download the video to the specified path
video_stream.download(output_path=save_path)
return True, "Download successful!"
except Exception as e:
return False, str(e)
# Input YouTube video URL
video_url = input("Enter the YouTube video URL: ")
# Provide a save path for the downloaded video
save_path = input("Enter the save path: ")
# Call the download_video function
success, message = download_video(video_url, save_path)
# Display download status
if success:
print(message)
else:
print("Download failed:", message)