Browse Source

Add _get_worker method and refactor run method

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
a10a08a949
1 changed files with 15 additions and 9 deletions
  1. 24
      youtube_dl_gui/downloadmanager.py

24
youtube_dl_gui/downloadmanager.py

@ -355,15 +355,14 @@ class DownloadManager(Thread):
item = self.download_list.fetch_next() item = self.download_list.fetch_next()
if item is not None: if item is not None:
# TODO create a get_worker method?
for worker in self._workers:
if worker.available():
worker.download(item.url, item.options, item.object_id)
self.download_list.change_stage(item.object_id, "Active")
break
else:
if self._jobs_done():
break
worker = self._get_worker()
if worker is not None:
worker.download(item.url, item.options, item.object_id)
self.download_list.change_stage(item.object_id, "Active")
if item is None and self._jobs_done():
break
time.sleep(self.WAIT_TIME) time.sleep(self.WAIT_TIME)
@ -463,6 +462,13 @@ class DownloadManager(Thread):
if not os_path_exists(self._youtubedl_path()): if not os_path_exists(self._youtubedl_path()):
UpdateThread(self.opt_manager.options['youtubedl_path'], True).join() UpdateThread(self.opt_manager.options['youtubedl_path'], True).join()
def _get_worker(self):
for worker in self._workers:
if worker.available():
return worker
return None
def _jobs_done(self): def _jobs_done(self):
"""Returns True if the workers have finished their jobs else False. """ """Returns True if the workers have finished their jobs else False. """
for worker in self._workers: for worker in self._workers:

Loading…
Cancel
Save