关于在yazi里面调用mpv时读取当前排序下的文件列表

这个是我目前使用的mpv配置(关于image和music的两个部分,我用mpv同时作为音频、视频以及图片查看器)

[image]
osc=no
hr-seek=yes
load-scripts=no # avoid autoload mpv-mpris to serve as an image viewer
force-window=yes
background=color
background-color=0/0.75
input-conf=~/.config/mpv/image-input.conf
#script=~/.config/mpv/scripts/autoload.lua
reset-on-next-file=mute,video-pan-x,video-pan-y,video-zoom
title='${filename} - mpv-image'
loop-playlist=inf
loop-file=inf
mute=yes

[music]
osc=no
hr-seek=yes
force-window=yes # avoid no window showing when album cover is missing
gapless-audio=weak
#loop-playlist=inf
no-resume-playback
#background=color
#background-color=0/0.75
script-opts=autoload-disabled=yes
title='${filename} - mpv-music'
#geometry=800x800
loop-playlist=no
loop-file=no

然后这个是在ai的帮助下写的一个yazi的插件(路径~/.config/yazi/plugins/mpv-sort.yazi/main.lua

--- @sync entry

local function detect_mode(path)
	local ext = path:match("%.([^%.]+)$")
	if not ext then
		return "unknown"
	end

	ext = ext:lower()

	local audio = {
		mp3 = true,
		flac = true,
		wav = true,
		m4a = true,
		ogg = true,
		opus = true,
	}

	local image = {
		jpg = true,
		jpeg = true,
		png = true,
		webp = true,
		bmp = true,
	}

	if audio[ext] then
		return "audio"
	end
	if image[ext] then
		return "image"
	end

	return "unknown"
end

local function entry()
	local hovered = cx.active.current.hovered
	if not hovered then
		return
	end

	local current = tostring(hovered.url)
	local files = cx.active.current.files

	local mode = detect_mode(current)

	local list = {}
	local start = 0
	local i = 0

	for _, f in ipairs(files) do
		local path = tostring(f.url)
		local ext = path:match("%.([^%.]+)$")
		ext = ext and ext:lower()

		if mode == "audio" then
			if
				ext
				and (ext == "mp3" or ext == "flac" or ext == "wav" or ext == "m4a" or ext == "ogg" or ext == "opus")
			then
				table.insert(list, path)
				if path == current then
					start = i
				end
				i = i + 1
			end
		elseif mode == "image" then
			if ext and (ext == "jpg" or ext == "jpeg" or ext == "png" or ext == "webp" or ext == "bmp") then
				table.insert(list, path)
				if path == current then
					start = i
				end
				i = i + 1
			end
		end
	end

	local playlist = "/tmp/yazi-mpv.m3u"
	local fp = io.open(playlist, "w")
	for _, p in ipairs(list) do
		fp:write(p .. "\n")
	end
	fp:close()

	local cmd = Command("mpv")

	-- 🔥 关键:profile 分流
	if mode == "audio" then
		cmd:arg("--profile=music")
	elseif mode == "image" then
		cmd:arg("--profile=image")
	end

	cmd:arg("--playlist=" .. playlist)
	cmd:arg("--playlist-start=" .. tostring(start))

	cmd:spawn()
end

return { entry = entry }

现在能够做到的事情是根据我在yazi里面应用的排序方式从当前hover的文件开始生成播放列表,然后使用我在yazi的keymap.toml里面配置的快捷键调用mpv

[[mgr.prepend_keymap]]
on  = [ "g", "m" ]
run = "plugin mpv-sort"
desc = "Play sorted media"

不过我不知道要怎么在yazi的opener部分实现这个功能,如果能在yazi的yazi.toml的opener部分实现这个功能那应该在使用上还会更无感一些,不需要另外设置单独的快捷键。。