diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-11-09 14:50:05 +0000 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-11-09 14:50:05 +0000 |
commit | 9ce37c420eab96910379fddb280a4d5b25cd0e67 (patch) | |
tree | 7281a4b03a220abfe86e6cea7019d6ba3e6af230 | |
parent | d204b513c10e2c0dba13fc050cde8c7e4da03990 (diff) | |
download | youload-9ce37c420eab96910379fddb280a4d5b25cd0e67.tar.gz youload-9ce37c420eab96910379fddb280a4d5b25cd0e67.tar.bz2 youload-9ce37c420eab96910379fddb280a4d5b25cd0e67.zip |
Added cli interface
-rw-r--r-- | src/youload_app.py | 12 | ||||
-rw-r--r-- | src/youload_cli.py | 27 | ||||
-rw-r--r-- | src/youload_playlist.py | 2 |
3 files changed, 37 insertions, 4 deletions
diff --git a/src/youload_app.py b/src/youload_app.py index 037ac30..53e4bce 100644 --- a/src/youload_app.py +++ b/src/youload_app.py @@ -10,16 +10,20 @@ from kivy.uix.label import Label import threading +import pytube + from youload_playlist import YouLoadPlayList class YouloadApp(App): def build(self): layout = BoxLayout(orientation='vertical') + pytube.helpers.setup_logger(0, None) + # Data members self.url = "https://youtube.com/playlist?list=PLuZUmvZz4WI78uqT5S71yBHNBMJ97HzhY&si=SI2qN9MgxmmK2rbf" self.is_downloading = False - self.stop_download = False + self.should_stop_download = False # Url input. url_input = TextInput(text=self.url, multiline=False, size_hint=(0.75, 1.0)) @@ -74,7 +78,7 @@ class YouloadApp(App): self.downloads_display.text += playlist.download_video(i) + "\n" # Stop this mother fucker - if self.stop_download: + if self.should_stop_download: break self.submit.text = "Download" @@ -82,7 +86,7 @@ class YouloadApp(App): self.is_downloading = False def stop_download(self): - self.stop_download = True + self.should_stop_download = True def submit_cb(self, instance): # Is already downloading something. @@ -93,7 +97,7 @@ class YouloadApp(App): # Start download thread. download_thread = threading.Thread(target=self.download_playlist_thread) - self.stop_download = False + self.should_stop_download = False download_thread.start() def on_stop(self): diff --git a/src/youload_cli.py b/src/youload_cli.py new file mode 100644 index 0000000..7429b48 --- /dev/null +++ b/src/youload_cli.py @@ -0,0 +1,27 @@ +from youload_playlist import YouLoadPlayList +import sys + +def main() -> None: + if len(sys.argv) <= 1: + print("Needs the url") + return + + # Get playlist + try: + playlist = YouLoadPlayList(sys.argv[1]) + except KeyError: + print("Error getting playlist") + return + + playlist.prepare_for_download() + + # Download each video. + for i in range(playlist.video_count): + print(f"Downloading {i+1}/{playlist.video_count}") + print(playlist.download_video(i) + "\n") + + print("Download complete") + + +if __name__ == "__main__": + main() diff --git a/src/youload_playlist.py b/src/youload_playlist.py index 4121d85..1d62ee5 100644 --- a/src/youload_playlist.py +++ b/src/youload_playlist.py @@ -20,9 +20,11 @@ class YouLoadPlayList: return f"Title: {video.title}, Size: {video_size} MB" def prepare_for_download(self) -> None: + """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: + """Download video at 'video_num'""" video = self.yt_playlist.videos[video_num] video_size = video.streams.get_highest_resolution().filesize video.streams.get_highest_resolution().download(output_path=self.folder_name) |