Fix 400s/empty server responses
https://github.com/ajayyy/SponsorBlock/issues/1819#issuecomment-1667166456
This commit is contained in:
parent
26fb582e7c
commit
8bcc5d180d
|
@ -1,5 +1,6 @@
|
||||||
local utils = require "mp.utils"
|
local utils = require "mp.utils"
|
||||||
local opts = require "mp.options"
|
local opts = require "mp.options"
|
||||||
|
local bit = require "bit"
|
||||||
|
|
||||||
-- https://wiki.sponsor.ajay.app/w/Types#Category
|
-- https://wiki.sponsor.ajay.app/w/Types#Category
|
||||||
-- See README to configure options
|
-- See README to configure options
|
||||||
|
@ -195,8 +196,8 @@ function getSegments(video_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
local url = options.api_url .. "/skipSegments/" .. hashed_id .. "?actionTypes="
|
local url = options.api_url .. "/skipSegments/" .. hashed_id .. "?actionTypes="
|
||||||
.. "[\"skip\",\"mute\",\"full\"]&categories="
|
.. percentEncodeComponent("[\"skip\",\"mute\",\"full\"]") .. "&categories="
|
||||||
.. utils.format_json(split(options.categories))
|
.. percentEncodeComponent(utils.format_json(split(options.categories)))
|
||||||
proc = mp.command_native({
|
proc = mp.command_native({
|
||||||
name = "subprocess",
|
name = "subprocess",
|
||||||
args = {"curl", "--silent", "--show-error", "--globoff", url},
|
args = {"curl", "--silent", "--show-error", "--globoff", url},
|
||||||
|
@ -279,6 +280,14 @@ function getIDs()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function percentEncodeComponent(s)
|
||||||
|
-- https://url.spec.whatwg.org/#component-percent-encode-set
|
||||||
|
return string.gsub(s, "[^!'()*-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz~]", function (char)
|
||||||
|
local byte = string.byte(char)
|
||||||
|
return "%" .. bit.tohex(byte, -2)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
function split(s)
|
function split(s)
|
||||||
local arr = {}
|
local arr = {}
|
||||||
for i in string.gmatch(s, "%S+") do
|
for i in string.gmatch(s, "%S+") do
|
||||||
|
|
Loading…
Reference in New Issue