MPV constructor: Add loglevel argument

This commit is contained in:
jaseg 2017-08-02 10:46:13 +02:00
parent 1fa874db37
commit 7dc375f85c

7
mpv.py
View file

@ -469,7 +469,7 @@ class MPV(object):
""" See man mpv(1) for the details of the implemented commands. All mpv """ See man mpv(1) for the details of the implemented commands. All mpv
properties can be accessed as ```my_mpv.some_property``` and all mpv properties can be accessed as ```my_mpv.some_property``` and all mpv
options can be accessed as ```my_mpv['some-option']```. """ options can be accessed as ```my_mpv['some-option']```. """
def __init__(self, *extra_mpv_flags, log_handler=None, start_event_thread=True, **extra_mpv_opts): def __init__(self, *extra_mpv_flags, log_handler=None, start_event_thread=True, loglevel=None, **extra_mpv_opts):
""" Create an MPV instance. """ Create an MPV instance.
Extra arguments and extra keyword arguments will be passed to mpv as options. """ Extra arguments and extra keyword arguments will be passed to mpv as options. """
@ -496,6 +496,8 @@ class MPV(object):
self._event_handle = _mpv_create_client(self.handle, b'py_event_handler') self._event_handle = _mpv_create_client(self.handle, b'py_event_handler')
self._loop = partial(_event_loop, self._event_handle, self._playback_cond, self._event_callbacks, self._loop = partial(_event_loop, self._event_handle, self._playback_cond, self._event_callbacks,
self._message_handlers, self._property_handlers, log_handler) self._message_handlers, self._property_handlers, log_handler)
if loglevel is not None or log_handler is not None:
self.set_loglevel(loglevel or 'terminal-default')
if start_event_thread: if start_event_thread:
self._event_thread = threading.Thread(target=self._loop, name='MPVEventHandlerThread') self._event_thread = threading.Thread(target=self._loop, name='MPVEventHandlerThread')
self._event_thread.setDaemon(True) self._event_thread.setDaemon(True)
@ -503,9 +505,6 @@ class MPV(object):
else: else:
self._event_thread = None self._event_thread = None
if log_handler is not None:
self.set_loglevel('terminal-default')
def wait_for_playback(self): def wait_for_playback(self):
""" Waits until playback of the current title is paused or done """ """ Waits until playback of the current title is paused or done """
with self._playback_cond: with self._playback_cond: