Update NPE and remove the caching of CommentsInfo instances. (#209)

This commit is contained in:
Kavin 2022-03-03 12:03:45 +00:00 committed by GitHub
parent 72666ecf83
commit cec135933e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 14 deletions

View File

@ -16,7 +16,7 @@ dependencies {
implementation 'it.unimi.dsi:fastutil-core:8.5.8'
implementation 'commons-codec:commons-codec:1.15'
implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:4963fdabd4842b2f1aeb12506e105798b30e0cfa'
implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:87df3331f419e1a93690d3f34eb50c7c14ff4aa1'
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.1'

View File

@ -1,9 +1,6 @@
package me.kavin.piped.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.benmanes.caffeine.cache.Scheduler;
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonWriter;
import com.rometools.rome.feed.synd.*;
@ -67,11 +64,6 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
public class ResponseHelper {
public static final LoadingCache<String, CommentsInfo> commentsCache = Caffeine.newBuilder()
.expireAfterWrite(1, TimeUnit.HOURS)
.scheduler(Scheduler.systemScheduler())
.maximumSize(1000).build(key -> CommentsInfo.getInfo("https://www.youtube.com/watch?v=" + key));
public static byte[] streamsResponse(String videoId) throws Exception {
CompletableFuture<StreamInfo> futureStream = CompletableFuture.supplyAsync(() -> {
@ -457,7 +449,7 @@ public class ResponseHelper {
public static byte[] commentsResponse(String videoId) throws Exception {
CommentsInfo info = commentsCache.get(videoId);
CommentsInfo info = CommentsInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
List<Comment> comments = new ObjectArrayList<>();
@ -492,9 +484,7 @@ public class ResponseHelper {
Page prevpage = Constants.mapper.readValue(prevpageStr, Page.class);
CommentsInfo init = commentsCache.get(videoId);
InfoItemsPage<CommentsInfoItem> info = CommentsInfo.getMoreItems(init, prevpage);
InfoItemsPage<CommentsInfoItem> info = CommentsInfo.getMoreItems(YOUTUBE_SERVICE, "https://www.youtube.com/watch?v=" + videoId, prevpage);
List<Comment> comments = new ObjectArrayList<>();
@ -519,7 +509,7 @@ public class ResponseHelper {
nextpage = Constants.mapper.writeValueAsString(page);
}
CommentsPage commentsItem = new CommentsPage(comments, nextpage, init.isCommentsDisabled());
CommentsPage commentsItem = new CommentsPage(comments, nextpage, false);
return Constants.mapper.writeValueAsBytes(commentsItem);