From 81efbc3921b411065774efa7c56f24046e598531 Mon Sep 17 00:00:00 2001 From: Julian Date: Tue, 28 Apr 2015 02:13:27 +0200 Subject: stats: make non-ASS styling configurable Also add a few convenience functions and remove the unused italic and underlined formatting functions. --- player/lua/stats.lua | 100 ++++++++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 44 deletions(-) (limited to 'player') diff --git a/player/lua/stats.lua b/player/lua/stats.lua index 748fa15f7c..e7e119a4f1 100644 --- a/player/lua/stats.lua +++ b/player/lua/stats.lua @@ -12,10 +12,12 @@ require 'mp.options' +-- options local o = { - no_osd = 0, + ass_formatting = true, duration = 3, - -- text formatting + + -- text style font = "Source Sans Pro", font_size = 11, font_color = "FFFFFF", @@ -25,22 +27,25 @@ local o = { shadow_y_offset = 0.0, shadow_color = "000000", 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", prop_indent = "\\h\\h\\h\\h\\h", - kv_sep = "\\h\\h", -- keyvalue - + kv_sep = "\\h\\h", b1 = "{\\b1}", b0 = "{\\b0}", - i1 = "{\\i1}", - i0 = "{\\i0}", - u1 = "{\\u1}", - u0 = "{\\u0}", - - -- Custom header for ASS tags to format the text output. - -- Specifying this will ignore the text formatting values above and just - -- use this string instead. - custom_header = "" + -- without ASS + no_ass_nl = "\n", + no_ass_prop_indent = "\t", + no_ass_kv_sep = " ", + no_ass_b1 = "", + no_ass_b0 = "", } read_options(o) @@ -53,18 +58,13 @@ function main() audio = "" } - if mp.get_property("video-codec") == nil then - o.nl = "\n" - duration = mp.get_property("length") - o.prop_indent = "\t" - o.kv_sep = "" - o.b1 = "" - o.b0 = "" - o.i1 = "" - o.i0 = "" - o.u1 = "" - o.u0 = "" - o.no_osd = 1 + o.ass_formatting = o.ass_formatting and has_vo_window() + if not o.ass_formatting then + o.nl = o.no_ass_nl + o.prop_indent = o.no_ass_prop_indent + o.kv_sep = o.no_ass_kv_sep + o.b1 = o.no_ass_b1 + o.b0 = o.no_ass_b0 end add_header(stats) @@ -78,8 +78,8 @@ end function add_file(s) s.file = "" - local fn = mp.get_property_osd("filename") - s.file = s.file .. b("File:") .. o.kv_sep .. no_ASS(fn) + local r = mp.get_property_osd("filename") + s.file = s.file .. b("File:") .. o.kv_sep .. no_ASS(r) append_property(s, "file", "metadata/title", "Title:") append_property(s, "file", "chapter", "Chapter:") @@ -93,12 +93,11 @@ end function add_video(s) s.video = "" - local r = mp.get_property_osd("video") - if not r or r == "no" or r == "" then + if not has_video() then return end - local fn = mp.get_property_osd("video-codec") - s.video = s.video .. b("Video:") .. o.kv_sep .. no_ASS(fn) + local r = mp.get_property_osd("video-codec") + s.video = s.video .. b("Video:") .. o.kv_sep .. no_ASS(r) append_property(s, "video", "avsync", "A-V:") if append_property(s, "video", "drop-frame-count", "Dropped:") then @@ -124,10 +123,10 @@ end function add_audio(s) s.audio = "" - local r = mp.get_property_osd("audio-codec") - if not r or r == "no" or r == "" then + if not has_audio() then return end + local r = mp.get_property_osd("audio-codec") s.audio = s.audio .. b("Audio:") .. o.kv_sep .. no_ASS(r) append_property(s, "audio", "audio-samplerate", "Sample Rate:") @@ -139,7 +138,8 @@ end function add_header(s) - if o.no_osd == 1 then + if not o.ass_formatting then + s.header = "" return end if o.custom_header and o.custom_header ~= "" then @@ -186,14 +186,14 @@ end function no_ASS(t) - if o.no_osd == 1 then - return t - end return set_ASS(false) .. t .. set_ASS(true) end 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")) end @@ -203,15 +203,27 @@ function join_stats(s) end -function b(t) - return o.b1 .. t .. o.b0 +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 i(t) - return o.i1 .. t .. o.i0 + + +function has_audio() + local r = mp.get_property("audio") + return r ~= nil and r ~= "no" and r ~= "" end -function u(t) - return o.u1 .. t .. o.u0 + + +function b(t) + return o.b1 .. t .. o.b0 end + mp.add_key_binding("i", mp.get_script_name(), main, {repeatable=true}) -- cgit v1.2.3