Skip to content

Commit e8991dc

Browse files
authored
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.
1 parent b730693 commit e8991dc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: youtubedownloader.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ def download():
1414
url = YouTube(str(url_box.get()))
1515
video = url.streams.first()
1616
filename = filedialog.asksaveasfilename(defaultextension=".mp4", filetypes=[("MP4 files", "*.mp4")])
17-
video.download(filename=filename)
18-
messagebox.showinfo('', 'Download completed!')
17+
if filename: # Check if a filename is selected
18+
video.download(filename=filename)
19+
messagebox.showinfo('', 'Download completed!')
20+
else:
21+
messagebox.showwarning('', 'Download cancelled!')
1922
except Exception as e:
2023
messagebox.showerror("Error", "An error occurred while downloading the video.")
2124

2225

26+
2327
root = Tk()
2428
root.title('YouTube Downloader')
2529
root.geometry('780x500+200+200')

0 commit comments

Comments
 (0)