Skip to content

Commit

Permalink
feat(sponsorblock): support actionTypes (#766)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
FineFindus and Bnyro committed Mar 13, 2024
1 parent e68e3f9 commit cd4bc36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/me/kavin/piped/server/ServerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ AsyncServlet mainServlet(Executor executor) {
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());
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/me/kavin/piped/utils/SponsorBlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@

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))
return mapper.writeValueAsString(new InvalidRequestResponse());

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());
Expand Down

0 comments on commit cd4bc36

Please sign in to comment.