Using this function I am able to get the file-size of the current playing file in the playlist of MPV media player. But I also want to be able to get file_size of all files in the playlist and get the total sum of that and write it to the screen once I press a hot-key. I would appreciate any help as I think I am almost there but I am a bit stuck on what to do from here on
local assdraw = require "mp.assdraw"
local options = require "mp.options"
local mp = require 'mp'
local utils = require "mp.utils"
package.path = mp.command_native({"expand-path", "~~/script-modules/?.lua;"})..package.path
local filesize = require "filesize"
local function readable_bytes(size)
if not size then return nil end
return filesize(size)
end
local info_active = true
local o = {
font_size = 9.25,
font_color = "FFFFFF",
border_size = 0.8,
border_color = "000000",
font_name = "Source Sans Pro"
}
options.read_options(o)
function get_formatting()
return string.format(
"{\\fs%d}{\\1c&H%s&}{\\bord%f}{\\3c&H%s&}{\\fn%s}",
o.font_size, o.font_color, o.border_size, o.border_color, o.font_name
)
end
function get_info()
return string.format(
"Dotta: %s %s",
get_formatting(),
display_total_playlist_filesize())
end
function render_info()
ass = assdraw.ass_new()
ass:pos(10, 10)
ass:append(get_info())
mp.set_osd_ass(0, 0, ass.text)
end
function clear_info()
mp.set_osd_ass(0, 0, "")
end
function toggle_info()
if info_active then
mp.register_event("tick", render_info)
render_info()
else
-- TODO: Rewrite to timer + pause/unpause handlers.
mp.unregister_event(render_info)
clear_info()
end
info_active = not info_active
end
function display_total_playlist_filesize()
file_size = mp.get_property_native('file-size')
if not file_size then return nil end
return string.format("%s", readable_bytes(file_size)
)
end
mp.add_key_binding("TAB", "toggle_info", toggle_info)