From c01b36209a12fe7b19ee4ba8a3a467697d9bbf5f Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Thu, 9 Nov 2023 11:40:27 -0700 Subject: Folder already exists error handled --- src/model/youload_app.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/model/youload_app.py b/src/model/youload_app.py index b75aee6..6d20b22 100644 --- a/src/model/youload_app.py +++ b/src/model/youload_app.py @@ -45,7 +45,7 @@ class YouloadApp(App): self.folder_display = Label(text=str(Path.home()), size_hint=(0.4, 1.0)) # choose folder button. - self.choose_folder_button = Button(text="Choose folder", size_hint=(0.2, 1.0)) + self.choose_folder_button = Button(text="Folder", size_hint=(0.2, 1.0)) self.choose_folder_button.bind(on_press=self.choose_folder_cb) # Info line. @@ -77,32 +77,36 @@ class YouloadApp(App): # Download the videos in a different thread so the ui still works. def download_playlist_thread(self): - self.download_status.text = "Fetching playlist" - self.submit.text = "Stop" - self.is_downloading = True - - # Get playlist. try: + self.download_status.text = "Fetching playlist" + self.submit.text = "Stop" + self.is_downloading = True + + # Get playlist. playlist = YouLoadPlayList(self.url) - except KeyError: - self.download_status.text = "Error getting playlist" - return - playlist.set_download_directory(self.folder_display.text) - playlist.prepare_for_download() - self.downloads_display.text = f"Downloading to {playlist.folder_name}\n" + # Set directory and other stuff. + playlist.set_download_directory(self.folder_display.text) + playlist.prepare_for_download() + self.downloads_display.text = f"Downloading to {playlist.folder_name}\n" + + # Download each video + for i in range(playlist.video_count): + # Stop this mother fucker + if self.should_stop_download: + break - # Download each video - for i in range(playlist.video_count): - # Stop this mother fucker - if self.should_stop_download: - break + self.download_status.text = f"Downloading {i+1}/{playlist.video_count}" + self.downloads_display.text += playlist.download_video(i) + "\n" - self.download_status.text = f"Downloading {i+1}/{playlist.video_count}" - self.downloads_display.text += playlist.download_video(i) + "\n" + # Complete download. + self.download_status.text = "Download complete" + except FileExistsError: + self.download_status.text = "Folder already exists" + except KeyError: + self.download_status.text = "Error getting playlist" self.submit.text = "Download" - self.download_status.text = "Download complete" self.is_downloading = False def stop_download(self): -- cgit v1.2.3