From 563499ce3d39be5e906a62260e3098c14994f698 Mon Sep 17 00:00:00 2001 From: nathansmithsmith Date: Sun, 14 Jan 2024 15:32:48 -0700 Subject: Numbers added --- src/model/youload_playlist.py | 16 +++++++++++----- src/view/app.py | 15 ++++++++++++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/model/youload_playlist.py b/src/model/youload_playlist.py index f23533f..a021b83 100644 --- a/src/model/youload_playlist.py +++ b/src/model/youload_playlist.py @@ -31,20 +31,26 @@ class YouLoadPlayList: """Gets the playlist ready for download. Creates the output folder and that stuff.""" os.mkdir(self.folder_name) - def download_video(self, video_num: int) -> str: + def download_video(self, video_num: int, use_prefix: bool) -> str: """Download video at 'video_num'""" video = self.yt_playlist.videos[video_num] video_size = video.streams.get_highest_resolution().filesize + # Create prefix. + filename_prefix = "" + + if use_prefix: + filename_prefix = str(video_num + 1) + " " + # Download this fucker. if self.download_type == "highest": - video.streams.get_highest_resolution().download(output_path=self.folder_name) + video.streams.get_highest_resolution().download(output_path=self.folder_name, filename_prefix=filename_prefix) elif self.download_type == "lowest": - video.streams.get_lowest_resolution().download(output_path=self.folder_name) + video.streams.get_lowest_resolution().download(output_path=self.folder_name, filename_prefix=filename_prefix) elif self.download_type == "audio": - video.streams.get_audio_only().download(output_path=self.folder_name) + video.streams.get_audio_only().download(output_path=self.folder_name, filename_prefix=filename_prefix) else: - video.streams.get_by_resolution(self.download_type).download(output_path=self.folder_name) + video.streams.get_by_resolution(self.download_type).download(output_path=self.folder_name, filename_prefix=filename_prefix) return f"Title: {video.title}, Size: {video_size // (1024 ** 2)} MB" diff --git a/src/view/app.py b/src/view/app.py index 0fe3fa6..3639de3 100644 --- a/src/view/app.py +++ b/src/view/app.py @@ -52,7 +52,12 @@ class YouloadApp(App): self.download_type_button.bind(on_press=self.download_type_chooser.open) # Folder display. - self.folder_display = Label(text=util.get_default_download_dir(), size_hint=(0.75, 1.0)) + self.folder_display = Label(text=util.get_default_download_dir(), size_hint=(0.5, 1.0)) + + # Add numbers. + self.do_add_numbers: bool = False + self.add_numbers_button = Button(text="No numbers", size_hint=(0.25, 1.0)) + self.add_numbers_button.bind(on_press=self.toggle_add_numbers_cb) # choose folder button. self.choose_folder_button = Button(text="Folder", size_hint=(0.25, 1.0)) @@ -65,9 +70,9 @@ class YouloadApp(App): info_line2 = BoxLayout(size_hint=(1.0, 0.1)) info_line2.add_widget(self.folder_display) + info_line2.add_widget(self.add_numbers_button) info_line2.add_widget(self.choose_folder_button) - # Info display. self.downloads_display = Label(text="", size_hint=(1.0, 0.7)) @@ -88,6 +93,10 @@ class YouloadApp(App): def uid_url_input(self, instance, value): self.url = value + def toggle_add_numbers_cb(self, instance): + self.do_add_numbers = not self.do_add_numbers + self.add_numbers_button.text = "Numbers" if self.do_add_numbers else "No numbers" + # Download the videos in a different thread so the ui still works. def download_playlist_thread(self): try: @@ -111,7 +120,7 @@ class YouloadApp(App): break self.download_status.text = f"Downloading {i+1}/{playlist.video_count}" - self.downloads_display.text += playlist.download_video(i) + "\n" + self.downloads_display.text += playlist.download_video(i, self.do_add_numbers) + "\n" # Complete download. self.download_status.text = "Download complete" -- cgit v1.2.3