require 'mp.options' function handle_file_load () if mp.get_property("metadata/by-key/artist") == nil and mp.get_property("metadata/by-key/title") == nil then -- media-title is filename if no title is set if mp.get_property("media-title") ~= mp.get_property("filename") then info = mp.get_property("media-title") else info = mp.get_property("filename/no-ext") end else info = mp.get_property("metadata/by-key/artist") .. " – " .. mp.get_property("metadata/by-key/title") end -- check for youtube-dl if mp.get_property("stream-open-filename") ~= mp.get_property("path") then info = info .. "\n(" .. mp.get_property("path") .. ")" end file = io.open(options.write, "w") io.output(file) io.write(info .. "\n") io.close(file) end options = { write = "", } read_options(options) if options.write ~= "" then mp.register_event("file-loaded", handle_file_load) end