Skip to content

Commit

Permalink
Fix loadfile for mpv v0.38.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jaseg committed Apr 20, 2024
1 parent d26f801 commit d96eaf7
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ def __init__(self, *extra_mpv_flags, log_handler=None, start_event_thread=True,
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):
Expand Down Expand Up @@ -1324,9 +1326,16 @@ def playlist_play_index(self, idx):
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)."""
Expand Down

0 comments on commit d96eaf7

Please sign in to comment.