summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mpv.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/mpv.py b/mpv.py
index df34563..a7a8565 100644
--- a/mpv.py
+++ b/mpv.py
@@ -163,6 +163,10 @@ class MpvEventID(c_int):
'TICK', 'SCRIPT_INPUT_DISPATCH', 'CLIENT_MESSAGE', 'VIDEO_RECONFIG', 'AUDIO_RECONFIG',
'METADATA_UPDATE', 'SEEK', 'PLAYBACK_RESTART', 'PROPERTY_CHANGE', 'CHAPTER_CHANGE'][self.value]
+ @classmethod
+ def from_str(kls, s):
+ return getattr(kls, s.upper().replace('-', '_'))
+
class MpvNodeList(Structure):
def array_value(self, decode_str=False):
@@ -637,9 +641,10 @@ class MPV(object):
def event_callback(self, *event_types):
def register(callback):
+ types = [MpvEventID.from_str(t) if isinstance(t, str) else t for t in event_types] or MpvEventID.ANY
@wraps(callback)
def wrapper(event, *args, **kwargs):
- if event['event_id'] in (event_types or MpvEventID.ANY):
+ if event['event_id'] in types:
callback(event, *args, **kwargs)
self._event_callbacks.append(wrapper)
wrapper.unregister_event_callback = partial(self.unregister_event_callback, wrapper)