From 6ad27aea2aa87662ba0758e6ef18da98c3addea9 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Tue, 15 Nov 2022 19:21:36 +0000 Subject: [PATCH] Update NPE. --- build.gradle | 2 +- config.properties | 2 +- .../java/me/kavin/piped/consts/Constants.java | 7 ++++-- .../server/handlers/ChannelHandlers.java | 8 +++---- .../java/me/kavin/piped/utils/PageMixin.java | 14 ++++++----- .../utils/YouTubeChannelTabHandlerMixin.java | 23 ------------------- .../utils/resp/ListLinkHandlerMixin.java | 18 +++++++++++++++ 7 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/me/kavin/piped/utils/YouTubeChannelTabHandlerMixin.java create mode 100644 src/main/java/me/kavin/piped/utils/resp/ListLinkHandlerMixin.java diff --git a/build.gradle b/build.gradle index c20c68e..9ec3e0f 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ dependencies { implementation 'it.unimi.dsi:fastutil-core:8.5.9' implementation 'commons-codec:commons-codec:1.15' implementation 'org.bouncycastle:bcprov-jdk15on:1.70' - implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:cd90b9f950480a1991ef1175b8d10392a6f49234' + implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:15f45245d38b21d794870bea93291296c6bb9935' implementation 'com.github.FireMasterK:nanojson:5df3e81e87b791d01f132f376e4b7d4a1780f346' implementation 'com.fasterxml.jackson.core:jackson-core:2.14.0' implementation 'com.fasterxml.jackson.core:jackson-annotations:2.14.0' diff --git a/config.properties b/config.properties index 1b79a6c..c7eb856 100644 --- a/config.properties +++ b/config.properties @@ -4,7 +4,7 @@ PORT:8080 HTTP_WORKERS:2 # Proxy -PROXY_PART:https://pipedproxy-ams.kavin.rocks +PROXY_PART:https://pipedproxy-cdg.kavin.rocks # Outgoing HTTP Proxy - eg: 127.0.0.1:8118 #HTTP_PROXY: 127.0.0.1:8118 diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index cfc5fc4..4ee6f68 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.kavin.piped.utils.PageMixin; +import me.kavin.piped.utils.resp.ListLinkHandlerMixin; import okhttp3.OkHttpClient; import okhttp3.brotli.BrotliInterceptor; import org.apache.commons.io.IOUtils; @@ -12,6 +13,7 @@ import org.apache.commons.lang3.StringUtils; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.Page; import org.schabi.newpipe.extractor.StreamingService; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import java.io.File; import java.io.FileReader; @@ -80,6 +82,7 @@ public class Constants { public static final ObjectMapper mapper = JsonMapper.builder() .addMixIn(Page.class, PageMixin.class) + .addMixIn(ListLinkHandler.class, ListLinkHandlerMixin.class) .build(); public static final Object2ObjectOpenHashMap hibernateProperties = new Object2ObjectOpenHashMap<>(); @@ -162,11 +165,11 @@ public class Constants { } } - private static final String getProperty(final Properties prop, String key) { + private static String getProperty(final Properties prop, String key) { return getProperty(prop, key, null); } - private static final String getProperty(final Properties prop, String key, String def) { + private static String getProperty(final Properties prop, String key, String def) { final String envVal = System.getenv(key); diff --git a/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java b/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java index 35efd71..efbfb3d 100644 --- a/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/ChannelHandlers.java @@ -17,7 +17,7 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo; import org.schabi.newpipe.extractor.channel.ChannelTabInfo; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; -import org.schabi.newpipe.extractor.services.youtube.linkHandler.YouTubeChannelTabHandler; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import java.io.IOException; @@ -140,7 +140,7 @@ public class ChannelHandlers { .stream() .map(tab -> { try { - return new ChannelTab(tab.getTab().name(), mapper.writeValueAsString(tab)); + return new ChannelTab(tab.getContentFilters().get(0), mapper.writeValueAsString(tab)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } @@ -190,7 +190,7 @@ public class ChannelHandlers { if (StringUtils.isEmpty(data)) ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("data is a required parameter")); - YouTubeChannelTabHandler tabHandler = mapper.readValue(data, YouTubeChannelTabHandlerMixin.class); + ListLinkHandler tabHandler = mapper.readValue(data, ListLinkHandler.class); var info = ChannelTabInfo.getInfo(YOUTUBE_SERVICE, tabHandler); @@ -210,7 +210,7 @@ public class ChannelHandlers { if (StringUtils.isEmpty(data)) ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("data is a required parameter")); - YouTubeChannelTabHandler tabHandler = mapper.readValue(data, YouTubeChannelTabHandlerMixin.class); + ListLinkHandler tabHandler = mapper.readValue(data, ListLinkHandler.class); Page prevPage = mapper.readValue(prevPageStr, Page.class); diff --git a/src/main/java/me/kavin/piped/utils/PageMixin.java b/src/main/java/me/kavin/piped/utils/PageMixin.java index 6bf48ac..426e114 100644 --- a/src/main/java/me/kavin/piped/utils/PageMixin.java +++ b/src/main/java/me/kavin/piped/utils/PageMixin.java @@ -1,16 +1,18 @@ package me.kavin.piped.utils; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.schabi.newpipe.extractor.Page; + import java.util.List; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -public abstract class PageMixin { +public abstract class PageMixin extends Page { @JsonCreator public PageMixin(@JsonProperty("url") String url, @JsonProperty("id") String id, - @JsonProperty("ids") List ids, @JsonProperty("cookies") Map cookies, - @JsonProperty("body") byte[] body) { + @JsonProperty("ids") List ids, @JsonProperty("cookies") Map cookies, + @JsonProperty("body") byte[] body) { + super(url, id, ids, cookies, body); } } diff --git a/src/main/java/me/kavin/piped/utils/YouTubeChannelTabHandlerMixin.java b/src/main/java/me/kavin/piped/utils/YouTubeChannelTabHandlerMixin.java deleted file mode 100644 index 0bb92db..0000000 --- a/src/main/java/me/kavin/piped/utils/YouTubeChannelTabHandlerMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package me.kavin.piped.utils; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.schabi.newpipe.extractor.linkhandler.ChannelTabHandler; -import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; -import org.schabi.newpipe.extractor.services.youtube.linkHandler.YouTubeChannelTabHandler; - -import java.util.List; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class YouTubeChannelTabHandlerMixin extends YouTubeChannelTabHandler { - - @JsonCreator - @JsonIgnoreProperties(ignoreUnknown = true) - public YouTubeChannelTabHandlerMixin(@JsonProperty("originalUrl") String originalUrl, @JsonProperty("url") String url, - @JsonProperty("id") String id, @JsonProperty("contentFilters") List contentFilters, - @JsonProperty("sortFilter") String sortFilter, @JsonProperty("tab") ChannelTabHandler.Tab tab, - @JsonProperty("visitorData") String visitorData) { - super(new ListLinkHandler(originalUrl, url, id, contentFilters, sortFilter), tab, visitorData); - } -} diff --git a/src/main/java/me/kavin/piped/utils/resp/ListLinkHandlerMixin.java b/src/main/java/me/kavin/piped/utils/resp/ListLinkHandlerMixin.java new file mode 100644 index 0000000..52540b6 --- /dev/null +++ b/src/main/java/me/kavin/piped/utils/resp/ListLinkHandlerMixin.java @@ -0,0 +1,18 @@ +package me.kavin.piped.utils.resp; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; + +import java.util.List; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ListLinkHandlerMixin extends ListLinkHandler { + + @JsonCreator + public ListLinkHandlerMixin(@JsonProperty("originalUrl") String originalUrl, @JsonProperty("url") String url, @JsonProperty("id") String id, + @JsonProperty("contentFilters") List contentFilters, @JsonProperty("sortFilter") String sortFilter) { + super(originalUrl, url, id, contentFilters, sortFilter); + } +}