mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-04-28 16:00:29 +05:30
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:
parent
e68e3f9356
commit
cd4bc36f4f
@ -99,7 +99,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||||||
try {
|
try {
|
||||||
return getJsonResponse(
|
return getJsonResponse(
|
||||||
SponsorBlockUtils.getSponsors(request.getPathParameter("videoId"),
|
SponsorBlockUtils.getSponsors(request.getPathParameter("videoId"),
|
||||||
request.getQueryParameter("category")).getBytes(UTF_8),
|
request.getQueryParameter("category"), request.getQueryParameter("actionType")).getBytes(UTF_8),
|
||||||
"public, max-age=3600");
|
"public, max-age=3600");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return getErrorResponse(e, request.getPath());
|
return getErrorResponse(e, request.getPath());
|
||||||
|
@ -22,7 +22,7 @@ import static me.kavin.piped.consts.Constants.mapper;
|
|||||||
|
|
||||||
public class SponsorBlockUtils {
|
public class SponsorBlockUtils {
|
||||||
|
|
||||||
public static String getSponsors(String id, String categories)
|
public static String getSponsors(String id, String categories, String actionType)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
if (StringUtils.isEmpty(categories))
|
if (StringUtils.isEmpty(categories))
|
||||||
@ -30,11 +30,15 @@ public class SponsorBlockUtils {
|
|||||||
|
|
||||||
String hash = DigestUtils.sha256Hex(id);
|
String hash = DigestUtils.sha256Hex(id);
|
||||||
|
|
||||||
for (String url : Constants.SPONSORBLOCK_SERVERS) {
|
for (String apiUrl : Constants.SPONSORBLOCK_SERVERS) {
|
||||||
try {
|
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);
|
||||||
+ "?categories=" + URLUtils.silentEncode(categories)).get();
|
if (actionType != null && !actionType.isBlank())
|
||||||
|
url += "&actionTypes=" + URLUtils.silentEncode(actionType);
|
||||||
|
|
||||||
|
var resp = RequestUtils.sendGetRaw(url).get();
|
||||||
|
|
||||||
if (resp.status() == 200) {
|
if (resp.status() == 200) {
|
||||||
var any = mapper.readTree(resp.body());
|
var any = mapper.readTree(resp.body());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user