jaseg / python-mpv

Python interface to the awesome mpv media player
https://git.jaseg.de/python-mpv.git
Other
531 stars 67 forks source link

Loadfile command broken by API change in mpv v0.38.0 #273

Closed monkeylugs closed 2 months ago

monkeylugs commented 2 months ago

Hi , i'm a python novice so please accept my apologies if this is wasting your time.

several scripts which have previously been working have started to show similar errors when playing or appending a url to a playlist.

Here is a minimal example that is enough to cause an error -

import mpv

mpv_playlist_list = ["https://youtu.be/E6iQPkjh1F4", "https://youtu.be/PPvo41LkJjo", "https://youtu.be/B3aZtjTC_-Q" ]

print("create player")
player = mpv.MPV(
                    ytdl=True,
                    input_default_bindings=True,
                    input_vo_keyboard=True,
                    osc=True,
                    prefetch_playlist=True,
                    autofit="60%"
                    )
for i in mpv_playlist_list:
    print(f"playlist append = {i}")
    player.playlist_append(i)

print("playlist_pos = 0")
player.playlist_pos = 0
player.wait_for_playback()

The error -

create player playlist append = https://youtu.be/E6iQPkjh1F4 Traceback (most recent call last): File "/home/mark/python_stuff/lutv-dls/test_mk2/mpv/./mpv_test_basic.py", line 20, in player.playlist_append(i) File "/usr/lib/python3.11/site-packages/mpv.py", line 1890, in playlist_append self.loadfile(filename, 'append', **options) File "/usr/lib/python3.11/site-packages/mpv.py", line 1329, in loadfile self.command('loadfile', filename.encode(fs_enc), mode, MPV._encode_options(options)) File "/usr/lib/python3.11/site-packages/mpv.py", line 1227, in command _mpv_command_node(self.handle, ppointer, out) File "/usr/lib/python3.11/site-packages/mpv.py", line 142, in raise_for_ec raise ex ValueError: ('Invalid value for mpv parameter', -4, (<MpvHandle object at 0x726ebd35ca70>, <mpv.LP_MpvNode object at 0x726ebd011400>, <mpv.LP_MpvNode object at 0x726ebd011370>))

Playing the first URL with mpv from the command line works as expected -

mpv https://youtu.be/E6iQPkjh1F4

(+) Video --vid=1 () (vp9 1920x1080 25.000fps) (+) Audio --aid=1 --alang=eng () (opus 2ch 48000Hz) Subs --sid=1 --slang=en-GB 'English (United Kingdom)' (webvtt) (external) File tags: Uploader: BBC Earth Science Channel_URL: https://www.youtube.com/channel/UCdsOTr6SmDrxuWE7sJFrkhQ AO: [pipewire] 48000Hz stereo 2ch floatp VO: [gpu] 1920x1080 yuv420p Saving state. AV: 00:00:39 / 00:03:16 (20%) A-V: 0.000 ct: -0.079 Dropped: 12 Cache: 14s/3MB Exiting... (Quit)

just in-case any of this is relevant -

Operating System: Arch Linux KDE Plasma Version: 6.0.4 KDE Frameworks Version: 6.1.0 Qt Version: 6.7.0 Kernel Version: 6.8.7-arch1-1 (64-bit) Graphics Platform: Wayland Processors: 8 × Intel® Core™ i7-6700HQ CPU @ 2.60GHz Memory: 15.4 GiB of RAM Graphics Processor: Mesa Intel® HD Graphics 530 Manufacturer: Dell Inc. Product Name: XPS 15 9550

Name : python-mpv Version : 1.0.5-1

please advise if further information is required

monkeylugs commented 2 months ago

After some investigation the problem may stem from here -

Name : mpv Version : 1:0.38.0-2 Build Date : Thu 18 Apr 2024 07:31:17 BST Install Date : Thu 18 Apr 2024 12:19:30 BST

Rolling back to this version removes the error -

Name : mpv Version : 1:0.37.0-3 Build Date : Sun 31 Mar 2024 11:04:09 BST Install Date : Thu 18 Apr 2024 22:36:41 BST

liyaastrova commented 2 months ago

replace

self.command('loadfile', filename.encode(fs_enc), mode, MPV._encode_options(options))

to

self.command('loadfile', filename.encode(fs_enc), mode, -1, MPV._encode_options(options))

in mpv.py (should fix player.play, not sure about player.playlist_append)

context: https://github.com/mpv-player/mpv/blob/master/DOCS/interface-changes.rst, https://github.com/mpv-player/mpv/issues/13806 and https://github.com/mpv-player/mpv/pull/13406#issuecomment-1962259492

--- mpv 0.38.0 ---
   - add `index` argument to `loadfile` and `loadlist` commands
   - move the `options` argument of the `loadfile` command from the third
     parameter to the fourth (after `index`)
monkeylugs commented 2 months ago

can confirm the suggested change works for both player.play() and player.playlist_append()

I presume there must be other changes in the latest version of mpv as from a quick test - autofit="60%" appears to now be ignored, but that's a problem for another day....

edit - my mistake autofit now seems to be multiplied by the desktop scaling on hdpi screens, so in my case doubled. Probably a change in how kde plasma handles scaling in wayland or similar..

jaseg commented 2 months ago

Oof, that's a breaking change to a basic API that's completely unnecessary. Why can't it distinguish between a numeric parameter and a k/v options dict in the third argument?

Oh well, brace yourselves for a new release in a few minutes. I'll include a kludge to make it work with both newer and older versions.

Thank you for the bug report, and feel free to open more issues in case you hit any other incompatibilities.

jaseg commented 2 months ago

Closed in v1.0.6