mpv
mpv copied to clipboard
lua script observe_property playlist returns reason
Expected behavior of the wanted feature
the playlist property is triggered for a bunch of reasons, listing some: Next file, previous file, add file, remove file, shuffle, and more. And I couldn't find a way to tell them apart.
It would help a lot to if there was a way, perhaps another parameter or field, specifying the reason why the playlist property changed, it could be a new event like end-file. My use case is basically, I want to keep a text file up to date with the playlist currently playing, some of the transformations are quite heavy, and I would like to only update this file when necessary, that is, when the playlist actually changes, basically the remove, add and shuffle events from before. If the reason field was present, I would be able to just filter those out with a simple if.
something like
function on_playlist_change(data)
if data.reason == "shuffle" or data.reason == "add_file" or data.reason == "remove_file" then
update();
end
end
mp.register_event('playlist-change', on_playlist_change)
Alternative behavior of the wanted feature
another solution would be a way to listen to all of those events separetly, like listening for add-file, remove-file, shuffle, etc.