diff --git a/sponsorblock_lm.lua b/sponsorblock_lm.lua index 64787f3..0f35666 100644 --- a/sponsorblock_lm.lua +++ b/sponsorblock_lm.lua @@ -1,5 +1,6 @@ local utils = require "mp.utils" local opts = require "mp.options" +local bit = require "bit" -- https://wiki.sponsor.ajay.app/w/Types#Category -- See README to configure options @@ -195,8 +196,8 @@ function getSegments(video_id) end local url = options.api_url .. "/skipSegments/" .. hashed_id .. "?actionTypes=" - .. "[\"skip\",\"mute\",\"full\"]&categories=" - .. utils.format_json(split(options.categories)) + .. percentEncodeComponent("[\"skip\",\"mute\",\"full\"]") .. "&categories=" + .. percentEncodeComponent(utils.format_json(split(options.categories))) proc = mp.command_native({ name = "subprocess", args = {"curl", "--silent", "--show-error", "--globoff", url}, @@ -279,6 +280,14 @@ function getIDs() 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) local arr = {} for i in string.gmatch(s, "%S+") do