From cd4bc36f4f52487a7424b0c53d0ad1e59920def3 Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Wed, 13 Mar 2024 21:41:46 +0100 Subject: [PATCH] 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> --- .../java/me/kavin/piped/server/ServerLauncher.java | 2 +- .../java/me/kavin/piped/utils/SponsorBlockUtils.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/kavin/piped/server/ServerLauncher.java b/src/main/java/me/kavin/piped/server/ServerLauncher.java index 21b2e2b..8af9028 100644 --- a/src/main/java/me/kavin/piped/server/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/server/ServerLauncher.java @@ -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()); diff --git a/src/main/java/me/kavin/piped/utils/SponsorBlockUtils.java b/src/main/java/me/kavin/piped/utils/SponsorBlockUtils.java index 4151575..799d1a7 100644 --- a/src/main/java/me/kavin/piped/utils/SponsorBlockUtils.java +++ b/src/main/java/me/kavin/piped/utils/SponsorBlockUtils.java @@ -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());