feat(sponsorblock): support actionTypes (#766)

* feat(sponsorblock): support actionTypes

* feat(sponsorblock): handle nullable actionType

* style: correctly format assignment

Co-authored-by: Bnyro <82752168+Bnyro@users.noreply.github.com>

---------

Co-authored-by: Bnyro <82752168+Bnyro@users.noreply.github.com>
This commit is contained in:
FineFindus 2024-03-13 21:41:46 +01:00 committed by GitHub
parent e68e3f9356
commit cd4bc36f4f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -99,7 +99,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
try {
return getJsonResponse(
SponsorBlockUtils.getSponsors(request.getPathParameter("videoId"),
request.getQueryParameter("category")).getBytes(UTF_8),
request.getQueryParameter("category"), request.getQueryParameter("actionType")).getBytes(UTF_8),
"public, max-age=3600");
} catch (Exception e) {
return getErrorResponse(e, request.getPath());

View File

@ -22,7 +22,7 @@ import static me.kavin.piped.consts.Constants.mapper;
public class SponsorBlockUtils {
public static String getSponsors(String id, String categories)
public static String getSponsors(String id, String categories, String actionType)
throws IOException {
if (StringUtils.isEmpty(categories))
@ -30,11 +30,15 @@ public class SponsorBlockUtils {
String hash = DigestUtils.sha256Hex(id);
for (String url : Constants.SPONSORBLOCK_SERVERS) {
for (String apiUrl : Constants.SPONSORBLOCK_SERVERS) {
try {
String url = apiUrl + "/api/skipSegments/" + URLUtils.silentEncode(hash.substring(0, 4))
var resp = RequestUtils.sendGetRaw(url + "/api/skipSegments/" + URLUtils.silentEncode(hash.substring(0, 4))
+ "?categories=" + URLUtils.silentEncode(categories)).get();
+ "?categories=" + URLUtils.silentEncode(categories);
if (actionType != null && !actionType.isBlank())
url += "&actionTypes=" + URLUtils.silentEncode(actionType);
var resp = RequestUtils.sendGetRaw(url).get();
if (resp.status() == 200) {
var any = mapper.readTree(resp.body());