Files
youtubedownloader/main.py

31 lines
747 B
Python

from pytube import YouTube
# Asks the User for a youtube video URL.
def get_video_url():
try:
video_url = input('YouTube video URL: ')
return video_url
except Exception as e:
print(f"An error has occured: {e}")
# Download the video.
def video_download(video_url):
try:
youtube = YouTube(video_url)
video = youtube.streams.get_highest_resolution()
video.download()
except Exception as e:
print(f"An error has occured: {e}")
def main():
try:
video_url = get_video_url()
video_download(video_url)
except KeyboardInterrupt:
print("Session ended by user.")
except Exception as e:
print(f"{e}")
if __name__ == "__main__":
main()