summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2024-04-20 12:48:58 +0200
committerjaseg <git@jaseg.de>2024-04-20 12:48:58 +0200
commitd96eaf7e64f1063ae16f88abfaa14c2997b3291d (patch)
treeea0b912e9dc8461241269ce78a8652b483b5ff64
parentd26f801cecc7a87b88ab2687228ce3c540d8e998 (diff)
downloadpython-mpv-d96eaf7e64f1063ae16f88abfaa14c2997b3291d.tar.gz
python-mpv-d96eaf7e64f1063ae16f88abfaa14c2997b3291d.tar.bz2
python-mpv-d96eaf7e64f1063ae16f88abfaa14c2997b3291d.zip
Fix loadfile for mpv v0.38.0
mpv v0.38.0 added an argument to the loadfile command. Unfortunately the parsing logic isn't very smart, and now mis-interprets the old argument format, and breaks literally everything written against older versions that used the `options` kv dict. This commit adds a kludge that uses the right variant depending on the mpv version.
-rw-r--r--mpv.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/mpv.py b/mpv.py
index a4ea245..9297004 100644
--- a/mpv.py
+++ b/mpv.py
@@ -893,6 +893,8 @@ class MPV(object):
self._event_thread.start()
else:
self._event_thread = None
+ if (m := re.search(r'(\d+)\.(\d+)\.(\d+)', self.mpv_version)):
+ self.mpv_version_tuple = tuple(map(int, m.groups()))
@contextmanager
def _enqueue_exceptions(self):
@@ -1324,9 +1326,16 @@ class MPV(object):
def _encode_options(options):
return ','.join('{}={}'.format(_py_to_mpv(str(key)), str(val)) for key, val in options.items())
- def loadfile(self, filename, mode='replace', **options):
+ def loadfile(self, filename, mode='replace', index=None, **options):
"""Mapped mpv loadfile command, see man mpv(1)."""
- self.command('loadfile', filename.encode(fs_enc), mode, MPV._encode_options(options))
+ if self.mpv_version_tuple >= (0, 38, 0):
+ if index is None:
+ index = -1
+ self.command('loadfile', filename.encode(fs_enc), mode, index, MPV._encode_options(options))
+ else:
+ if index is not None:
+ warn(f'The index argument to the loadfile command is only supported on mpv >= 0.38.0')
+ self.command('loadfile', filename.encode(fs_enc), mode, MPV._encode_options(options))
def loadlist(self, playlist, mode='replace'):
"""Mapped mpv loadlist command, see man mpv(1)."""