|
require "mp" |
|
local msg = require "mp.msg" |
|
local utils = require "mp.utils" |
|
-- Currently, I use webp quality=90 |
|
-- In the future: Use jxl quality=80 |
|
-- It might be nice to adjust the quality on a show-by-show basis |
|
|
|
-- The format_json consults metatables to distinguish between empty arrays and lists |
|
local json_object_metatable = { type = "MAP" } |
|
function json_object(obj) |
|
setmetatable(obj, json_object_metatable) |
|
return obj |
|
end |
|
|
|
function subtitle_screenshot(arg_format) |
|
local format = arg_format or "webp" |
|
|
|
local path = "/Users/cassie/Pictures/VideoScreenshots/" |
|
local base_filename = os.date("Screen Shot %Y-%m-%d at %H.%M.%S") |
|
local image_filename = path .. base_filename .. "." .. format |
|
local meta_filename = path .. "Meta/" .. base_filename .. ".json" |
|
|
|
local text, err = utils.format_json(json_object { |
|
version = 2, |
|
screenshot = image_filename, |
|
working_dir = mp.get_property("working-directory"), |
|
path = mp.get_property("path"), |
|
filename = mp.get_property("filename"), |
|
title = mp.get_property("media-title"), |
|
time = mp.get_property("time-pos/full"), |
|
subtitle = mp.get_property("sub-text"), |
|
subtitle_ass = mp.get_property("sub-text-ass"), |
|
-- v2 fields start here: |
|
secondary_subtitle = mp.get_property("secondary-sub-text"), |
|
stream_filename = mp.get_property("stream-open-filename"), |
|
audio_info = json_object { |
|
id = mp.get_property("current-tracks/audio/id"), |
|
title = mp.get_property("current-tracks/audio/title"), |
|
lang = mp.get_property("current-tracks/audio/lang"), |
|
}, |
|
subtitle_info = json_object { |
|
id = mp.get_property("current-tracks/sub/id"), |
|
title = mp.get_property("current-tracks/sub/title"), |
|
lang = mp.get_property("current-tracks/sub/lang"), |
|
}, |
|
secondary_subtitle_info = json_object { |
|
id = mp.get_property("current-tracks/sub2/id"), |
|
title = mp.get_property("current-tracks/sub2/title"), |
|
lang = mp.get_property("current-tracks/sub2/lang"), |
|
}, |
|
}) |
|
if text then |
|
local file = io.open(meta_filename, "w") |
|
file:write(text) |
|
file:close() |
|
else |
|
msg.error(err) |
|
end |
|
|
|
mp.command_native({"screenshot-to-file", image_filename}) |
|
end |
|
|
|
mp.register_script_message("subtitle-screenshot", subtitle_screenshot) |
|
--- mp.add_key_binding("s", "subtitle-screenshot", subtitle_screenshot) |