diff options
author | jaseg <code@jaseg.net> | 2016-02-10 17:38:38 +0100 |
---|---|---|
committer | jaseg <code@jaseg.net> | 2016-02-12 14:07:12 +0100 |
commit | 5605380fcbb724b180ed61d9ce7811018eb2e909 (patch) | |
tree | 544b6dc1f6f3d39000e2f4c73acf4793a13853e3 | |
parent | ec91bf3e57c19913cc93ac25587e4c44a74b588e (diff) | |
download | python-mpv-5605380fcbb724b180ed61d9ce7811018eb2e909.tar.gz python-mpv-5605380fcbb724b180ed61d9ce7811018eb2e909.tar.bz2 python-mpv-5605380fcbb724b180ed61d9ce7811018eb2e909.zip |
Improved log handling
-rw-r--r-- | mpv.py | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -148,7 +148,9 @@ class MpvEventLogMessage(Structure): ('text', c_char_p)] def as_dict(self): - return { name: getattr(self, name) for name, _t in self._fields_ } + return { 'prefix': self.prefix.decode(), + 'level': self.level.decode(), + 'text': self.text.decode().rstrip() } class MpvEventEndFile(c_int): EOF_OR_INIT_FAILURE = 0 @@ -272,7 +274,7 @@ def load_lua(): class MPV: """ See man mpv(1) for the details of the implemented commands. """ - def __init__(self, **kwargs): + def __init__(self, log_handler=None, **kwargs): """ Create an MPV instance. Any kwargs given will be passed to mpv as options. """ @@ -290,11 +292,17 @@ class MPV: self._playback_cond.notify_all() if devent['event_id'] == MpvEventID.PROPERTY_CHANGE: self._property_handlers[devent['reply_userdata']](devent['event']) + if devent['event_id'] == MpvEventID.LOG_MESSAGE and log_handler is not None: + ev = devent['event'] + log_handler('{}: {}: {}'.format(ev['level'], ev['prefix'], ev['text'])) for callback in self.event_callbacks: callback.call() self._event_thread = threading.Thread(target=event_loop, daemon=True) self._event_thread.start() + if log_handler is not None: + self.set_loglevel('terminal-default') + _mpv_set_option_string(self.handle, b'audio-display', b'no') istr = lambda o: ('yes' if o else 'no') if type(o) is bool else str(o) for k,v in kwargs.items(): @@ -309,6 +317,9 @@ class MPV: # def __del__(self): # _mpv_terminate_destroy(self.handle) + def set_loglevel(self, level): + _mpv_request_log_messages(self.handle, level.encode()) + def command(self, name, *args): """ Execute a raw command """ args = [name.encode()] + [ str(arg).encode() for arg in args if arg is not None ] + [None] |