Skip to content

Commit de84ffc

Browse files
author
dariusjonda
committed
Add option to hide OSD message
in order to hide the text that shows up whenever a sponsoblock action has been triggered, a function has been added, that returns an empty string whenever the option "osd_text_show" is set to false see issue po5#44
1 parent a4808e7 commit de84ffc

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

sponsorblock.lua

+51-19
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ local options = {
7777
local_pattern = "",
7878

7979
-- Legacy option, use skip_categories instead
80-
skip = true
80+
skip = true,
81+
82+
-- Decide whether or not to show text when sponsoblocks triggers an action
83+
osd_text_show = false
8184
}
8285

8386
mp.options = require "mp.options"
@@ -137,7 +140,8 @@ function parse_update_interval()
137140
local num, mod = s:match "^(%d+)([hdm])$"
138141

139142
if num == nil or mod == nil then
140-
mp.osd_message("[sponsorblock] auto_update_interval " .. s .. " is invalid", 5)
143+
local osd_text = osd_show("[sponsorblock] auto_update_interval " .. s .. " is invalid", 5)
144+
mp.osd_message()
141145
return nil
142146
end
143147

@@ -150,6 +154,13 @@ function parse_update_interval()
150154
return num * time_table[mod]
151155
end
152156

157+
function osd_show(text)
158+
local s = options.osd_text_show
159+
if s == false then return "" end
160+
161+
return text;
162+
end
163+
153164
function clean_chapters()
154165
local chapters = mp.get_property_native("chapter-list")
155166
local new_chapters = {}
@@ -282,10 +293,12 @@ function skip_ads(name, pos)
282293
if (options.fast_forward == uuid or not options.skip_once or not t.skipped) and t.start_time <= pos and t.end_time > pos then
283294
if options.fast_forward == uuid then return end
284295
if options.fast_forward == false then
285-
mp.osd_message("[sponsorblock] " .. t.category .. " skipped")
296+
local osd_text = osd_show("[sponsorblock] " .. t.category .. " skipped")
297+
mp.osd_message(osd_text)
286298
mp.set_property("time-pos", t.end_time)
287299
else
288-
mp.osd_message("[sponsorblock] skipping " .. t.category)
300+
local osd_text = osd_show("[sponsorblock] skipping " .. t.category)
301+
mp.osd_message(osd_text)
289302
end
290303
t.skipped = true
291304
last_skip = {uuid = uuid, dir = nil}
@@ -342,9 +355,15 @@ function skip_ads(name, pos)
342355
end
343356

344357
function vote(dir)
345-
if last_skip.uuid == "" then return mp.osd_message("[sponsorblock] no sponsors skipped, can't submit vote") end
358+
if last_skip.uuid == "" then
359+
local osd_text = osd_show("[sponsorblock] no sponsors skipped, can't submit vote")
360+
return mp.osd_message(osd_text)
361+
end
346362
local updown = dir == "1" and "up" or "down"
347-
if last_skip.dir == dir then return mp.osd_message("[sponsorblock] " .. updown .. "vote already submitted") end
363+
if last_skip.dir == dir then
364+
local osd_text = osd_show("[sponsorblock] " .. updown .. "vote already submitted")
365+
return mp.osd_message(osd_text)
366+
end
348367
last_skip.dir = dir
349368
local args = {
350369
options.python_path,
@@ -364,7 +383,8 @@ function vote(dir)
364383
else
365384
utils.subprocess({args = args})
366385
end
367-
mp.osd_message("[sponsorblock] " .. updown .. "vote submitted")
386+
local osd_text = osd_show("[sponsorblock] " .. updown .. "vote submitted")
387+
mp.osd_message(osd_text)
368388
end
369389

370390
function update()
@@ -463,11 +483,13 @@ function set_segment()
463483
if segment.progress == 1 then
464484
segment.progress = 0
465485
segment.b = pos
466-
mp.osd_message("[sponsorblock] segment boundary B set, press again for boundary A", 3)
486+
local osd_text = osd_show("[sponsorblock] segment boundary B set, press again for boundary A")
487+
mp.osd_message(osd_text, 3)
467488
else
468489
segment.progress = 1
469490
segment.a = pos
470-
mp.osd_message("[sponsorblock] segment boundary A set, press again for boundary B", 3)
491+
local osd_text = osd_show("[sponsorblock] segment boundary A set, press again for boundary B")
492+
mp.osd_message(osd_text, 3)
471493
end
472494
if options.make_chapters and not segment.first then
473495
local start_time = math.min(segment.a, segment.b)
@@ -494,7 +516,8 @@ function submit_segment(category)
494516
local start_time = math.min(segment.a, segment.b)
495517
local end_time = math.max(segment.a, segment.b)
496518
if end_time - start_time == 0 or end_time == 0 then
497-
mp.osd_message("[sponsorblock] empty segment, not submitting")
519+
local osd_text = osd_show("[sponsorblock] empty segment, not submitting")
520+
mp.osd_message(osd_text)
498521
elseif segment.progress <= 1 then
499522
segment.progress = segment.progress + 2
500523
local category_list = ""
@@ -504,9 +527,11 @@ function submit_segment(category)
504527
mp.add_forced_key_binding(tostring(category_id), "select_category_"..category, function() select_category(category) end)
505528
mp.add_forced_key_binding("KP"..tostring(category_id), "kp_select_category_"..category, function() select_category(category) end)
506529
end
507-
mp.osd_message(string.format("[sponsorblock] press a number to select category for segment: %.2d:%.2d:%.2d to %.2d:%.2d:%.2d\n\n" .. category_list .. "\nyou can press Shift+G again for default (Sponsor) or hide this message with g", math.floor(start_time/(60*60)), math.floor(start_time/60%60), math.floor(start_time%60), math.floor(end_time/(60*60)), math.floor(end_time/60%60), math.floor(end_time%60)), 30)
530+
local osd_text = osd_show(string.format("[sponsorblock] press a number to select category for segment: %.2d:%.2d:%.2d to %.2d:%.2d:%.2d\n\n" .. category_list .. "\nyou can press Shift+G again for default (Sponsor) or hide this message with g", math.floor(start_time/(60*60)), math.floor(start_time/60%60), math.floor(start_time%60), math.floor(end_time/(60*60)), math.floor(end_time/60%60), math.floor(end_time%60)))
531+
mp.osd_message(osd_text, 30)
508532
else
509-
mp.osd_message("[sponsorblock] submitting segment...", 30)
533+
local osd_text = osd_show("[sponsorblock] submitting segment...")
534+
mp.osd_message(osd_text, 30)
510535
local submit
511536
local args = {
512537
options.python_path,
@@ -528,26 +553,33 @@ function submit_segment(category)
528553
end
529554
if string.match(submit.stdout, "success") then
530555
segment = {a = 0, b = 0, progress = 0, first = true}
531-
mp.osd_message("[sponsorblock] segment submitted")
556+
local osd_text = osd_show("[sponsorblock] segment submitted")
557+
mp.osd_message(osd_text)
532558
if options.make_chapters then
533559
clean_chapters()
534560
create_chapter("Submitted segment start", start_time)
535561
create_chapter("Submitted segment end", end_time)
536562
end
537563
elseif string.match(submit.stdout, "error") then
538-
mp.osd_message("[sponsorblock] segment submission failed, server may be down. try again", 5)
564+
local osd_text = osd_show("[sponsorblock] segment submission failed, server may be down. try again", 5)
565+
mp.osd_message()
539566
elseif string.match(submit.stdout, "502") then
540-
mp.osd_message("[sponsorblock] segment submission failed, server is down. try again", 5)
567+
local osd_text = osd_show("[sponsorblock] segment submission failed, server is down. try again", 5)
568+
mp.osd_message()
541569
elseif string.match(submit.stdout, "400") then
542-
mp.osd_message("[sponsorblock] segment submission failed, impossible inputs", 5)
570+
local osd_text = osd_show("[sponsorblock] segment submission failed, impossible inputs", 5)
571+
mp.osd_message()
543572
segment = {a = 0, b = 0, progress = 0, first = true}
544573
elseif string.match(submit.stdout, "429") then
545-
mp.osd_message("[sponsorblock] segment submission failed, rate limited. try again", 5)
574+
local osd_text = osd_show("[sponsorblock] segment submission failed, rate limited. try again", 5)
575+
mp.osd_message()
546576
elseif string.match(submit.stdout, "409") then
547-
mp.osd_message("[sponsorblock] segment already submitted", 3)
577+
local osd_text = osd_show("[sponsorblock] segment already submitted", 3)
578+
mp.osd_message()
548579
segment = {a = 0, b = 0, progress = 0, first = true}
549580
else
550-
mp.osd_message("[sponsorblock] segment submission failed", 5)
581+
local osd_text = osd_show("[sponsorblock] segment submission failed", 5)
582+
mp.osd_message()
551583
end
552584
end
553585
end

0 commit comments

Comments
 (0)