diff --git a/ChangeLog b/ChangeLog index 98ca8b39..19bacbc1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,7 +18,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) - Imports for Internationalization with gettext - Fix bug set wx.Locale for Python 3.8 - Fix bug subprocess for Windows ([WinError 6] Handler no valid) - Set stderr to PIPE + - Set stderr to PIPE +- Do not interpret output [debug] as an error in the Logs +- Get all Logs except "ffmpeg version" +- Do not send messages to the GUI if the app does not exist (Destroy) ### Changed - Migration to Python 3.* diff --git a/youtube_dl_gui/downloaders.py b/youtube_dl_gui/downloaders.py index cac9b96b..710cb6ed 100644 --- a/youtube_dl_gui/downloaders.py +++ b/youtube_dl_gui/downloaders.py @@ -46,7 +46,6 @@ def __init__(self, queue): self._filedescriptor = None self._running = True self._queue = queue - self.start() def run(self): @@ -59,15 +58,11 @@ def run(self): pipedata = bytes(pipedata).decode(encoding=get_encoding(), errors='ignore') for line in pipedata.splitlines(): # Ignore ffmpeg stderr - if str('ffmpeg version') in line: + if 'ffmpeg version' in line: ignore_line = True - if not ignore_line and line != "": self._queue.put_nowait(line) - - self._filedescriptor = None ignore_line = False - sleep(self.WAIT_TIME) def attach_filedescriptor(self, filedesc): @@ -181,8 +176,6 @@ def download(self, url, options): if self._is_warning(stderr): self._set_returncode(self.WARNING) - else: - self._set_returncode(self.ERROR) # Set return code to ERROR if we could not start the download process # or the childs return code is greater than zero @@ -232,7 +225,8 @@ def _set_returncode(self, code): @staticmethod def _is_warning(stderr): - return str(stderr).split(':')[0] == 'WARNING' + warning_error = str(stderr).split(':')[0] + return warning_error == 'WARNING' or warning_error == 'ERROR' def _last_data_hook(self): """Set the last data information based on the return code. """ @@ -295,7 +289,6 @@ def _proc_is_alive(self): """Returns True if self._proc is alive else False. """ if self._proc is None: return False - return self._proc.poll() is None def _get_cmd(self, url, options): @@ -322,24 +315,23 @@ def _create_process(self, cmd): """ info = None + kwargs = dict(stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + if os.name == 'nt': # Hide subprocess window info = subprocess.STARTUPINFO() info.dwFlags |= subprocess.STARTF_USESHOWWINDOW info.wShowWindow = subprocess.SW_HIDE - # Encode command for subprocess - # Refer to http://stackoverflow.com/a/9951851/35070 - # if sys.version_info < (3, 0): - # cmd = convert_item(cmd, to_unicode=False) + kwargs['startupinfo'] = info + kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP + else: + kwargs['start_new_session'] = True try: - self._proc = subprocess.Popen(cmd, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - startupinfo=info, - start_new_session=True) + self._proc = subprocess.Popen(cmd, **kwargs) except (ValueError, OSError, FileNotFoundError) as error: self._log('Failed to start process: {}'.format(str(cmd))) self._log(str(error)) diff --git a/youtube_dl_gui/downloadmanager.py b/youtube_dl_gui/downloadmanager.py index d040916e..09c578cd 100644 --- a/youtube_dl_gui/downloadmanager.py +++ b/youtube_dl_gui/downloadmanager.py @@ -27,6 +27,7 @@ RLock ) +import wx from wx import CallAfter # noinspection PyPep8Naming from pubsub import pub as Publisher @@ -501,7 +502,10 @@ def _talk_to_gui(signal, data=None): downloads using the active() method. """ - CallAfter(Publisher.sendMessage, MANAGER_PUB_TOPIC, signal=signal, data=data) + app = wx.GetApp() + + if app is not None: + CallAfter(Publisher.sendMessage, MANAGER_PUB_TOPIC, signal=signal, data=data) def _check_youtubedl(self): """Check if youtube-dl binary exists. If not try to download it. """ @@ -559,17 +563,19 @@ class Worker(Thread): """ WAIT_TIME = 0.1 + worker_count = 0 def __init__(self, opt_manager, youtubedl, log_manager=None, worker=None): super(Worker, self).__init__() # Use Daemon ? # self.setDaemon(True) + Worker.worker_count += 1 self.opt_manager = opt_manager self.log_manager = log_manager if worker: self.worker = worker else: - self.worker = 1 + self.worker = Worker.worker_count self.setName("Worker_" + str(worker)) @@ -638,8 +644,8 @@ def stop_download(self): def close(self): """Kill the worker after stopping the download process. """ + self.stop_download() self._running = False - self._downloader.stop() def available(self): """Return True if the worker has no job else False. """ @@ -752,5 +758,8 @@ def _talk_to_gui(self, signal, data): if signal == 'receive': self._wait_for_reply = True + + app = wx.GetApp() - CallAfter(Publisher.sendMessage, WORKER_PUB_TOPIC, signal=signal, data=data) + if app is not None: + CallAfter(Publisher.sendMessage, WORKER_PUB_TOPIC, signal=signal, data=data) diff --git a/youtube_dl_gui/version.py b/youtube_dl_gui/version.py index 45da0750..5220f471 100644 --- a/youtube_dl_gui/version.py +++ b/youtube_dl_gui/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- -__version__ = '1.1.2' +__version__ = '1.1.3'