From 8efcc2e26d61f481fa5288de042b2e73224cbf60 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Mon, 12 May 2014 00:08:27 +0300 Subject: [PATCH] Add downloading videos counter --- youtube_dl_gui/DownloadThread.py | 20 ++++++++++++-------- youtube_dl_gui/YoutubeDLGUI.py | 4 ++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/youtube_dl_gui/DownloadThread.py b/youtube_dl_gui/DownloadThread.py index 960b005..a228782 100644 --- a/youtube_dl_gui/DownloadThread.py +++ b/youtube_dl_gui/DownloadThread.py @@ -38,12 +38,15 @@ class DownloadManager(Thread): while self._running: # If download list is not empty if self.download_list: - url, index = self._extract_data() + dl_item = self.download_list[0] + index = dl_item['index'] + url = dl_item['url'] self._check_download_queue() if self._running: self._download(url, index) + self.download_list.pop(0) else: if not self.downloading(): self._running = False @@ -69,6 +72,14 @@ class DownloadManager(Thread): ''' Add download item on download list ''' self.download_list.append(item) + def get_items_counter(self): + ''' Return download videos counter ''' + counter = 0 + for thread in self._threads_lst: + if thread.is_alive(): + counter += 1 + return len(self.download_list) + counter + def close(self, kill=False): self._callafter('closing') self._running = False @@ -80,13 +91,6 @@ class DownloadManager(Thread): dl_thread = DownloadThread(url, index, self.opt_manager, self.log_manager) self._threads_lst.append(dl_thread) - def _extract_data(self): - ''' Extract url, index from download list ''' - data = self.download_list.pop(0) - url = data['url'] - index = data['index'] - return url, index - def _terminate_all(self): ''' Close down all download threads ''' for thread in self._threads_lst: diff --git a/youtube_dl_gui/YoutubeDLGUI.py b/youtube_dl_gui/YoutubeDLGUI.py index f1f8473..9306967 100644 --- a/youtube_dl_gui/YoutubeDLGUI.py +++ b/youtube_dl_gui/YoutubeDLGUI.py @@ -190,6 +190,10 @@ class MainFrame(wx.Frame): topic = msg.topic[0] data = msg.data + # Report downloading videos number + videos_no = self.download_thread.get_items_counter() + self.status_bar_write('Downloading %s videos' % videos_no) + if topic == 'download_thread': self.status_list.write(data)