Skip to content

Commit

Permalink
Fix some bugs: Logs, Close Frame
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksis committed Jan 21, 2021
1 parent 62cd2de commit 7dc4603
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down
32 changes: 12 additions & 20 deletions youtube_dl_gui/downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def __init__(self, queue):
self._filedescriptor = None
self._running = True
self._queue = queue

self.start()

def run(self):
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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):
Expand All @@ -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))
Expand Down
17 changes: 13 additions & 4 deletions youtube_dl_gui/downloadmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
RLock
)

import wx
from wx import CallAfter
# noinspection PyPep8Naming
from pubsub import pub as Publisher
Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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. """
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion youtube_dl_gui/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-


__version__ = '1.1.2'
__version__ = '1.1.3'

0 comments on commit 7dc4603

Please sign in to comment.