mirror of
				https://github.com/TeamPiped/Piped-Backend.git
				synced 2024-08-14 23:51:41 +00:00 
			
		
		
		
	Cleanup SponsorBlock utils to fix issues.
This commit is contained in:
		
							parent
							
								
									0c971e4d1c
								
							
						
					
					
						commit
						69814ddc30
					
				
					 1 changed files with 11 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -1,9 +1,5 @@
 | 
			
		|||
package me.kavin.piped.utils;
 | 
			
		||||
 | 
			
		||||
import com.grack.nanojson.JsonArray;
 | 
			
		||||
import com.grack.nanojson.JsonObject;
 | 
			
		||||
import com.grack.nanojson.JsonParser;
 | 
			
		||||
import com.grack.nanojson.JsonWriter;
 | 
			
		||||
import me.kavin.piped.consts.Constants;
 | 
			
		||||
import me.kavin.piped.utils.resp.InvalidRequestResponse;
 | 
			
		||||
import me.kavin.piped.utils.resp.SimpleErrorMessage;
 | 
			
		||||
| 
						 | 
				
			
			@ -11,15 +7,16 @@ import org.apache.commons.codec.digest.DigestUtils;
 | 
			
		|||
import org.apache.commons.lang3.StringUtils;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.security.NoSuchAlgorithmException;
 | 
			
		||||
 | 
			
		||||
import static me.kavin.piped.consts.Constants.mapper;
 | 
			
		||||
 | 
			
		||||
public class SponsorBlockUtils {
 | 
			
		||||
 | 
			
		||||
    public static String getSponsors(String id, String categories)
 | 
			
		||||
            throws IOException, NoSuchAlgorithmException {
 | 
			
		||||
            throws IOException {
 | 
			
		||||
 | 
			
		||||
        if (StringUtils.isEmpty(categories))
 | 
			
		||||
            return Constants.mapper.writeValueAsString(new InvalidRequestResponse());
 | 
			
		||||
            return mapper.writeValueAsString(new InvalidRequestResponse());
 | 
			
		||||
 | 
			
		||||
        String hash = DigestUtils.sha256Hex(id);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -30,11 +27,15 @@ public class SponsorBlockUtils {
 | 
			
		|||
                        + "?categories=" + URLUtils.silentEncode(categories));
 | 
			
		||||
 | 
			
		||||
                if (resp.status() == 200) {
 | 
			
		||||
                    JsonArray jArray = JsonParser.array().from(new String(resp.body()));
 | 
			
		||||
                    var any = mapper.readTree(resp.body());
 | 
			
		||||
 | 
			
		||||
                    jArray.removeIf(jObject -> !((JsonObject) jObject).getString("videoID").equalsIgnoreCase(id));
 | 
			
		||||
                    for (var element : any) {
 | 
			
		||||
                        if (element.get("videoID").asText().equalsIgnoreCase(id)) {
 | 
			
		||||
                            return mapper.writeValueAsString(element);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    return JsonWriter.string(jArray.getObject(0));
 | 
			
		||||
                    return "{}";
 | 
			
		||||
                }
 | 
			
		||||
            } catch (Exception ignored) {
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue