#! /usr/bin/python3 from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button from kivy.uix.textinput import TextInput from kivy.uix.label import Label import threading from youload_playlist import YouLoadPlayList class YouloadApp(App): def build(self): layout = BoxLayout(padding=10, orientation='vertical') # Data members self.url = "https://youtube.com/playlist?list=PLuZUmvZz4WI78uqT5S71yBHNBMJ97HzhY&si=SI2qN9MgxmmK2rbf" self.is_downloading = False self.download_thread = threading.Thread(target=self.download_playlist_thread) self.stop_download = False # Url input. url_input = TextInput(text=self.url, multiline=False) url_input.bind(text=self.uid_url_input) # Submit button. submit = Button(text="Download") submit.bind(on_press=self.submit_cb) # Info display. self.info_display = Label(text="") # Everything else (: layout.add_widget(url_input) layout.add_widget(self.info_display) layout.add_widget(submit) return layout def uid_url_input(self, instance, value): self.url = value # Download the videos in a different thread so the ui still works. def download_playlist_thread(self): playlist = YouLoadPlayList(self.url) playlist.prepare_for_download() self.info_display.text = f"Downloading {self.url}\n" self.is_downloading = True # Download each video for i in range(playlist.video_count): self.info_display.text += playlist.download_video(i) + "\n" # Stop this mother fucker if self.stop_download: return self.is_downloading = False def submit_cb(self, instance): self.stop_download = False self.download_thread.start() def on_stop(self): self.stop_download = True