From e8991dc9cc7539185d293f0186f89e37a31d3100 Mon Sep 17 00:00:00 2001 From: Naman Sinha <65483393+Naman794@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:43:02 +0530 Subject: [PATCH] Improve error handling and default file extension This update improves the YouTube downloader application by adding error handling for cases where the user cancels the download without selecting a filename. Additionally, it sets the default file extension to ".mp4" for easier file saving. These changes enhance the robustness and user-friendliness of the application, ensuring a smoother experience for users during video downloads. --- youtubedownloader.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/youtubedownloader.py b/youtubedownloader.py index 8343098aa0b..55b5bc85990 100644 --- a/youtubedownloader.py +++ b/youtubedownloader.py @@ -14,12 +14,16 @@ def download(): url = YouTube(str(url_box.get())) video = url.streams.first() filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")]) - video.download(filename=filename) - messagebox.showinfo('', 'Download completed!') + if filename: # Check if a filename is selected + video.download(filename=filename) + messagebox.showinfo('', 'Download completed!') + else: + messagebox.showwarning('', 'Download cancelled!') except Exception as e: messagebox.showerror("Error", "An error occurred while downloading the video.") + root = Tk() root.title('YouTube Downloader') root.geometry('780x500+200+200')