kljohann / mpv.el

control mpv for easy note taking
GNU General Public License v3.0
142 stars 14 forks source link

Add a backward compatible function of mpv playlist-play-index #10

Open firmart opened 3 years ago

firmart commented 3 years ago

The mpv command playlist-play-index was only introduced recently in version 0.33. It would be useful to have a backward compatible wrapper for people haven't upgraded their mpv build.

P.S. Maybe we can make it interactive.

kljohann commented 3 years ago

Thanks, I'll have a look. In general I'd like to keep this library slim, so I wouldn't want to add too many extra functions. But if playlist-play-index is important for your workflow (or some other package) we can add it (also considering that 0.33 is not available yet for several widely used distributions).

firmart commented 3 years ago

Thank you. Yes, it would be useful/fundamental for some package like vuiet to be able to jump around in a playlist. This PR comes from a misunderstanding that any command in the mpv documentation would work with mpv-run-command. However, (mpv-run-command "playlist-play-index" 0) simply doesn't work for mpv version prior to 0.33.

firmart commented 3 years ago

I fixed the code to reflect your suggestions. I wasn't able to test the case whenever playlist-pos returns -1, because I don't know exactly how to remove the current flag. Maybe I simply can't with my mpv version v0.32. I tried both (mpv-set-property "playlist-pos" -1) and (mpv-set-property "playlist-current-pos" -1). The former raised the error unsupported format for accessing format and the latter raised property not found.

As you said, (mpv-set-property "playlist-pos" pos) does work, though the documentation says

Writing the current value back to the property is subject to change. 
Currently, it will restart playback of the playlist entry. 
But in the future, writing the current value will be ignored. 
Use the playlist-play-index command to get guaranteed behavior.

we are fine as mpv version 0.33 won't go through this path. So I replaced the cl-loop.

kljohann commented 3 years ago

Looks good! On 0.33 I can get playlist-pos = -1 by starting mpv with --idle=yes or --idle=once. It will be -1 initially if no filename has been provided, and, in the case of --idle=yes, also after playback has finished:

(mpv-start "--idle=once")
(mpv-get-property "playlist-pos") ;; returns `-1` on 0.33

(mpv-start "--idle=yes" "https://www.youtube.com/watch?v=ylXk1LBvIqU")
;; ... wait until playlist has finished playing ...
(mpv-get-property "playlist-pos") ;; returns `-1` on 0.33

Can you give this a try on 0.32?