Skip to content

Commit

Permalink
Improve error handling and default file extension
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Naman794 authored Apr 3, 2024
1 parent b730693 commit e8991dc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions youtubedownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit e8991dc

Please sign in to comment.