Last active
June 9, 2025 07:55
-
-
Save s-zeid/7ad39697af06220ccec2868a340fd162 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- <https://gist.github.com/7ad39697af06220ccec2868a340fd162> | |
| -- input.conf usage: <key> show-text "${user-data/bitrates}" | |
| -- <key> show-text "${user-data/bitrate/<subkey>}" | |
| -- <key> script-binding bitrate/show [subkey (default: all)] | |
| -- <key> script-binding bitrate/osd-toggle [subkey (default: all)] | |
| -- subkeys: all, va, v, a, s | |
| -- example: k show-text "${user-data/bitrates}" | |
| -- K script-binding bitrate/osd-toggle va | |
| local function update() | |
| local function reformat_size(s) | |
| return s:gsub(" (.)bps$", "%1") .. "" | |
| end | |
| local all, vb_ab, vb, ab, sb = {}, {}, {}, {}, {} | |
| for _, track in ipairs(mp.get_property_native("track-list")) do | |
| if #vb == 0 and track.type == "video" and not track.image then | |
| table.insert(vb, reformat_size(mp.get_property_osd("video-bitrate", "?"))) | |
| elseif #ab == 0 and track.type == "audio" then | |
| table.insert(ab, reformat_size(mp.get_property_osd("audio-bitrate", "?"))) | |
| elseif #sb == 0 and track.type == "sub" then | |
| table.insert(sb, reformat_size(mp.get_property_osd("sub-bitrate", "?"))) | |
| end | |
| end | |
| for _, part in ipairs({{"VB", vb}, {"AB", ab}, {"SB", sb}}) do | |
| local label, value = part[1], part[2] | |
| if #value ~= 0 then | |
| table.insert(all, label .. ": " .. table.concat(value, ", ")) | |
| if label == "VB" or label == "AB" then | |
| table.insert(vb_ab, label .. ": " .. table.concat(value, ", ")) | |
| end | |
| end | |
| end | |
| for _, part in ipairs({ | |
| {"bitrates", all}, {"bitrate/all", all}, | |
| {"bitrate/va", vb_ab}, {"bitrate/av", vb_ab}, | |
| {"bitrate/v", vb, ", "}, {"bitrate/a", ab, ", "}, {"bitrate/s", sb, ", "}, | |
| }) do | |
| local key, value, sep = part[1], part[2], (part[3] or " / ") | |
| if #value ~= 0 then | |
| mp.set_property("user-data/" .. key, table.concat(value, sep)) | |
| else | |
| mp.del_property("user-data/" .. key) | |
| end | |
| end | |
| end | |
| mp.observe_property("vo-configured", "bool", update) | |
| mp.observe_property("playback-time", "number", update) | |
| mp.add_key_binding(nil, "show", function(state) | |
| if state.event ~= "up" then | |
| mp.osd_message(state.event) | |
| subkey = state.arg | |
| if subkey == nil or subkey == "" then | |
| subkey = "all" | |
| end | |
| subkey = subkey:gsub("[^a-zA-Z0-9_-]", "") .. "" | |
| mp.osd_message(mp.command_native({"expand-text", | |
| "${?user-data/bitrate/" .. subkey .. | |
| ":${user-data/bitrate/" .. subkey .. | |
| "}}" | |
| })) | |
| end | |
| end, {complex = true}) | |
| mp.add_key_binding(nil, "osd-toggle", function(state) | |
| if state.event == "up" or state.event == "press" then | |
| local subkey = state.arg | |
| if subkey == nil or subkey == "" then | |
| subkey = "all" | |
| end | |
| subkey = subkey:gsub("[^a-zA-Z0-9_-]", "") .. "" | |
| local osd_msg = mp.get_property("osd-msg1", "") | |
| local prefix = "${?user-data/bitrate/" .. subkey | |
| prefix = prefix .. ":${user-data/bitrate/" .. subkey .. "}\n}" | |
| local pos, pos_end = osd_msg:find(prefix, 1, true) | |
| if pos then | |
| mp.set_property("osd-msg1", osd_msg:sub(1, pos - 1) .. osd_msg:sub(pos_end + 1)) | |
| else | |
| mp.set_property("osd-msg1", prefix .. osd_msg) | |
| end | |
| end | |
| end, {complex = true}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment