make the message less useless
This commit is contained in:
		| @@ -20,27 +20,30 @@ 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 | ||||
|     	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 | ||||
| 	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 to "..tostring(v)) | ||||
| 			mp.set_property("time-pos",tonumber(v)) | ||||
|         			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() | ||||
| 	local video_path = mp.get_property("path") | ||||
| @@ -53,12 +56,13 @@ function file_loaded() | ||||
| 	youtube_id = string.sub(youtube_id, 1, 11) | ||||
|  | ||||
| 	getranges() | ||||
| 	if not ranges then return end | ||||
|  | ||||
| 	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() | ||||
| 	if ON then | ||||
|   | ||||
		Reference in New Issue
	
	Block a user