def download_all(self, location=None): """Download all the videos in the the playlist. Initially, download resolution is 720p (or highest available), later more option should be added to download resolution of choice TODO(nficano): Add option to download resolution of user's choice """ self.populate_video_urls() logger.debug('total videos found: ', len(self.video_urls)) logger.debug('starting download') if self.on_start_callback is not None: self.on_start_callback(len(self.video_urls)) for link in self.video_urls: yt = YouTube(link) if self.on_progress_callback is not None: yt.register_on_progress_callback(self.on_progress_callback) if self.on_complete_callback is not None: yt.register_on_complete_callback(self.on_complete_callback) stream = yt.streams.filter( progressive=True, subtype='mp4', ).order_by('resolution').desc().first() if location is not None: stream.download(location) else: stream.download() logger.debug('download complete')
def startDownload(url): global file_size path_to_save = askdirectory() if path_to_save is None: return try: yt = YouTube(url) st = yt.streams.first() yt.register_on_complete_callback(completeDownload) yt.register_on_progress_callback(progressDownload) file_size = st.filesize st.download(output_path=path_to_save) except Exception as e: print(e) print("Something Went wrong...Try again")