Skip to content

Commit cd4bc36

Browse files
FineFindusBnyro
andauthored
feat(sponsorblock): support actionTypes (#766)
* feat(sponsorblock): support actionTypes * feat(sponsorblock): handle nullable actionType * style: correctly format assignment Co-authored-by: Bnyro <[email protected]> --------- Co-authored-by: Bnyro <[email protected]>
1 parent e68e3f9 commit cd4bc36

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/main/java/me/kavin/piped/server/ServerLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ AsyncServlet mainServlet(Executor executor) {
9999
try {
100100
return getJsonResponse(
101101
SponsorBlockUtils.getSponsors(request.getPathParameter("videoId"),
102-
request.getQueryParameter("category")).getBytes(UTF_8),
102+
request.getQueryParameter("category"), request.getQueryParameter("actionType")).getBytes(UTF_8),
103103
"public, max-age=3600");
104104
} catch (Exception e) {
105105
return getErrorResponse(e, request.getPath());

src/main/java/me/kavin/piped/utils/SponsorBlockUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@
2222

2323
public class SponsorBlockUtils {
2424

25-
public static String getSponsors(String id, String categories)
25+
public static String getSponsors(String id, String categories, String actionType)
2626
throws IOException {
2727

2828
if (StringUtils.isEmpty(categories))
2929
return mapper.writeValueAsString(new InvalidRequestResponse());
3030

3131
String hash = DigestUtils.sha256Hex(id);
3232

33-
for (String url : Constants.SPONSORBLOCK_SERVERS) {
33+
for (String apiUrl : Constants.SPONSORBLOCK_SERVERS) {
3434
try {
35+
String url = apiUrl + "/api/skipSegments/" + URLUtils.silentEncode(hash.substring(0, 4))
3536

36-
var resp = RequestUtils.sendGetRaw(url + "/api/skipSegments/" + URLUtils.silentEncode(hash.substring(0, 4))
37-
+ "?categories=" + URLUtils.silentEncode(categories)).get();
37+
+ "?categories=" + URLUtils.silentEncode(categories);
38+
if (actionType != null && !actionType.isBlank())
39+
url += "&actionTypes=" + URLUtils.silentEncode(actionType);
40+
41+
var resp = RequestUtils.sendGetRaw(url).get();
3842

3943
if (resp.status() == 200) {
4044
var any = mapper.readTree(resp.body());

0 commit comments

Comments
 (0)