Skip to content

Commit 2e7c420

Browse files
Merge pull request #2148 from Naman794/patch-1
Improve error handling and default file extension
2 parents b730693 + e8991dc commit 2e7c420

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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)