From 2775d83c94eceedfa8c7623c7387bb33b903d5e3 Mon Sep 17 00:00:00 2001 From: Jouni Date: Tue, 27 Oct 2020 02:56:23 +0200 Subject: [PATCH] make the message less useless --- sponsorblock_minimal.lua | 42 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/sponsorblock_minimal.lua b/sponsorblock_minimal.lua index 6cf98ba..05e89af 100644 --- a/sponsorblock_minimal.lua +++ b/sponsorblock_minimal.lua @@ -20,26 +20,29 @@ function getranges() "categories=["..options.categories.."]", "-G", options.API} - local sponsors - sponsors = mp.command_native({name = "subprocess", capture_stdout = true, playback_only = false, args = args}) - if not string.match(sponsors.stdout,"%[(.-)%]") then return end - ranges = {} - for i in string.gmatch(string.sub(sponsors.stdout,2,-2),"%[(.-)%]") do - k,v = string.match(i,"(%d+.?%d*),(%d+.?%d*)") - ranges[k] = v + local sponsors = mp.command_native({name = "subprocess", capture_stdout = true, playback_only = false, args = args}) + + if string.match(sponsors.stdout,"%[(.-)%]") then + ranges = {} + for i in string.gmatch(string.sub(sponsors.stdout,2,-2),"%[(.-)%]") do + k,v = string.match(i,"(%d+.?%d*),(%d+.?%d*)") + ranges[k] = v + end end return end function skip_ads(name,pos) - if pos == nil then return end - for k,v in pairs(ranges) do - if tonumber(k) <= pos and tonumber(v) > pos then - mp.osd_message("[sponsorblock] skipping to "..tostring(v)) - mp.set_property("time-pos",tonumber(v)) - return - end + if pos ~= nil then + for k,v in pairs(ranges) do + if tonumber(k) <= pos and tonumber(v) > pos then + mp.osd_message("[sponsorblock] skipping forward "..math.floor(tonumber(v)-mp.get_property("time-pos")).."s") + mp.set_property("time-pos",tonumber(v)+0.01) + return + end + end end + return end function file_loaded() @@ -53,11 +56,12 @@ function file_loaded() youtube_id = string.sub(youtube_id, 1, 11) getranges() - if not ranges then return end - - ON = true - mp.add_key_binding("b","sponsorblock",toggle) - mp.observe_property("time-pos", "native", skip_ads) + if ranges then + ON = true + mp.add_key_binding("b","sponsorblock",toggle) + mp.observe_property("time-pos", "native", skip_ads) + end + return end function toggle()