stats: make non-ASS styling configurable

Also add a few convenience functions and remove the unused italic and
underlined formatting functions.
This commit is contained in:
Julian 2015-04-28 02:13:27 +02:00 committed by wm4
parent 9e57927af1
commit 81efbc3921
1 changed files with 56 additions and 44 deletions

View File

@ -12,10 +12,12 @@
require 'mp.options' require 'mp.options'
-- options
local o = { local o = {
no_osd = 0, ass_formatting = true,
duration = 3, duration = 3,
-- text formatting
-- text style
font = "Source Sans Pro", font = "Source Sans Pro",
font_size = 11, font_size = 11,
font_color = "FFFFFF", font_color = "FFFFFF",
@ -25,22 +27,25 @@ local o = {
shadow_y_offset = 0.0, shadow_y_offset = 0.0,
shadow_color = "000000", shadow_color = "000000",
alpha = "11", alpha = "11",
-- indentation
-- Custom header for ASS tags to style the text output.
-- Specifying this will ignore the text style values above and just
-- use this string instead.
custom_header = "",
-- text formatting
-- with ASS
nl = "\\N", nl = "\\N",
prop_indent = "\\h\\h\\h\\h\\h", prop_indent = "\\h\\h\\h\\h\\h",
kv_sep = "\\h\\h", -- key<kv_sep>value kv_sep = "\\h\\h",
b1 = "{\\b1}", b1 = "{\\b1}",
b0 = "{\\b0}", b0 = "{\\b0}",
i1 = "{\\i1}", -- without ASS
i0 = "{\\i0}", no_ass_nl = "\n",
u1 = "{\\u1}", no_ass_prop_indent = "\t",
u0 = "{\\u0}", no_ass_kv_sep = " ",
no_ass_b1 = "",
-- Custom header for ASS tags to format the text output. no_ass_b0 = "",
-- Specifying this will ignore the text formatting values above and just
-- use this string instead.
custom_header = ""
} }
read_options(o) read_options(o)
@ -53,18 +58,13 @@ function main()
audio = "" audio = ""
} }
if mp.get_property("video-codec") == nil then o.ass_formatting = o.ass_formatting and has_vo_window()
o.nl = "\n" if not o.ass_formatting then
duration = mp.get_property("length") o.nl = o.no_ass_nl
o.prop_indent = "\t" o.prop_indent = o.no_ass_prop_indent
o.kv_sep = "" o.kv_sep = o.no_ass_kv_sep
o.b1 = "" o.b1 = o.no_ass_b1
o.b0 = "" o.b0 = o.no_ass_b0
o.i1 = ""
o.i0 = ""
o.u1 = ""
o.u0 = ""
o.no_osd = 1
end end
add_header(stats) add_header(stats)
@ -78,8 +78,8 @@ end
function add_file(s) function add_file(s)
s.file = "" s.file = ""
local fn = mp.get_property_osd("filename") local r = mp.get_property_osd("filename")
s.file = s.file .. b("File:") .. o.kv_sep .. no_ASS(fn) s.file = s.file .. b("File:") .. o.kv_sep .. no_ASS(r)
append_property(s, "file", "metadata/title", "Title:") append_property(s, "file", "metadata/title", "Title:")
append_property(s, "file", "chapter", "Chapter:") append_property(s, "file", "chapter", "Chapter:")
@ -93,12 +93,11 @@ end
function add_video(s) function add_video(s)
s.video = "" s.video = ""
local r = mp.get_property_osd("video") if not has_video() then
if not r or r == "no" or r == "" then
return return
end end
local fn = mp.get_property_osd("video-codec") local r = mp.get_property_osd("video-codec")
s.video = s.video .. b("Video:") .. o.kv_sep .. no_ASS(fn) s.video = s.video .. b("Video:") .. o.kv_sep .. no_ASS(r)
append_property(s, "video", "avsync", "A-V:") append_property(s, "video", "avsync", "A-V:")
if append_property(s, "video", "drop-frame-count", "Dropped:") then if append_property(s, "video", "drop-frame-count", "Dropped:") then
@ -124,10 +123,10 @@ end
function add_audio(s) function add_audio(s)
s.audio = "" s.audio = ""
local r = mp.get_property_osd("audio-codec") if not has_audio() then
if not r or r == "no" or r == "" then
return return
end end
local r = mp.get_property_osd("audio-codec")
s.audio = s.audio .. b("Audio:") .. o.kv_sep .. no_ASS(r) s.audio = s.audio .. b("Audio:") .. o.kv_sep .. no_ASS(r)
append_property(s, "audio", "audio-samplerate", "Sample Rate:") append_property(s, "audio", "audio-samplerate", "Sample Rate:")
@ -139,7 +138,8 @@ end
function add_header(s) function add_header(s)
if o.no_osd == 1 then if not o.ass_formatting then
s.header = ""
return return
end end
if o.custom_header and o.custom_header ~= "" then if o.custom_header and o.custom_header ~= "" then
@ -186,14 +186,14 @@ end
function no_ASS(t) function no_ASS(t)
if o.no_osd == 1 then
return t
end
return set_ASS(false) .. t .. set_ASS(true) return set_ASS(false) .. t .. set_ASS(true)
end end
function set_ASS(b) function set_ASS(b)
if not o.ass_formatting then
return ""
end
return mp.get_property_osd("osd-ass-cc/" .. (b and "0" or "1")) return mp.get_property_osd("osd-ass-cc/" .. (b and "0" or "1"))
end end
@ -203,15 +203,27 @@ function join_stats(s)
end end
function has_vo_window()
return mp.get_property("vo-configured") == "yes"
end
function has_video()
local r = mp.get_property("video")
return r ~= nil and r ~= "no" and r ~= ""
end
function has_audio()
local r = mp.get_property("audio")
return r ~= nil and r ~= "no" and r ~= ""
end
function b(t) function b(t)
return o.b1 .. t .. o.b0 return o.b1 .. t .. o.b0
end end
function i(t)
return o.i1 .. t .. o.i0
end
function u(t)
return o.u1 .. t .. o.u0
end
mp.add_key_binding("i", mp.get_script_name(), main, {repeatable=true}) mp.add_key_binding("i", mp.get_script_name(), main, {repeatable=true})