Add null-check for SponsorBlock endpoint (#154)

This commit is contained in:
Kavin 2021-12-24 14:17:02 +00:00 committed by GitHub
parent 0c86edc1be
commit 49f439e761
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,8 @@ import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.lang3.StringUtils;
import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
@ -15,12 +17,16 @@ import com.grack.nanojson.JsonParserException;
import com.grack.nanojson.JsonWriter;
import me.kavin.piped.consts.Constants;
import me.kavin.piped.utils.resp.InvalidRequestResponse;
public class SponsorBlockUtils {
public static final String getSponsors(String id, String categories)
throws IOException, InterruptedException, NoSuchAlgorithmException, JsonParserException {
if (StringUtils.isEmpty(categories))
return Constants.mapper.writeValueAsString(new InvalidRequestResponse());
String hash = toSha256(id);
URI uri = URI.create("https://sponsor.ajay.app/api/skipSegments/" + URLUtils.silentEncode(hash.substring(0, 4))