From d9ba25ce859877f6edd41a2750bfac19e2ee1c1c Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Thu, 10 Jul 2025 22:45:39 +0200 Subject: [PATCH] Update docs, add caching and removed unused code --- .../YoutubeStreamInfoItemLockupExtractor.java | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemLockupExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemLockupExtractor.java index 536965edd..ac8e77131 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemLockupExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemLockupExtractor.java @@ -2,6 +2,7 @@ package org.schabi.newpipe.extractor.services.youtube.extractors; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; +import com.grack.nanojson.JsonArray; import com.grack.nanojson.JsonObject; import org.schabi.newpipe.extractor.Image; @@ -23,6 +24,16 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.Nullable; +/** + * Note: + * This extractor is currently (2025-07) only used to extract related video streams.
+ * The following features are currently not implemented because they have never been observed: + * + */ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtractor { private static final String NO_VIEWS_LOWERCASE = "no views"; @@ -30,6 +41,11 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra private final JsonObject lockupViewModel; private final TimeAgoParser timeAgoParser; + private String cachedName; + private String cachedTextualUploadDate; + + private JsonArray cachedMetadataRows; + /** * Creates an extractor of StreamInfoItems from a YouTube page. * @@ -75,9 +91,6 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra @Override public boolean isAd() throws ParsingException { - if (isPremium()) { - return true; - } final String name = getName(); // only get it once return "[Private video]".equals(name) || "[Deleted video]".equals(name); @@ -99,9 +112,14 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra @Override public String getName() throws ParsingException { + if (cachedName != null) { + return cachedName; + } + final String name = JsonUtils.getString(lockupViewModel, "metadata.lockupMetadataViewModel.title.content"); if (!isNullOrEmpty(name)) { + this.cachedName = name; return name; } throw new ParsingException("Could not get name"); @@ -179,9 +197,14 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra @Nullable @Override public String getTextualUploadDate() throws ParsingException { - return metadataPart(1, 1) + if (cachedTextualUploadDate != null) { + return cachedTextualUploadDate; + } + + this.cachedTextualUploadDate = metadataPart(1, 1) .map(this::getTextContentFromMetadataPart) .orElse(null); + return cachedTextualUploadDate; } @Nullable @@ -196,11 +219,6 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra @Override public long getViewCount() throws ParsingException { - if (isPremium() || isPremiere()) { - return -1; - } - - // TODO Check if this is the same for shorts final Optional optTextContent = metadataPart(1, 0) .map(this::getTextContentFromMetadataPart); // We could do this inline if the ParsingException would be a RuntimeException -.- @@ -230,21 +248,14 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra "contentImage.thumbnailViewModel.image.sources")); } - private boolean isPremium() { - // TODO Detect with samples - return false; - } - - private boolean isPremiere() { - // TODO Detect with samples - return false; - } - private Optional metadataPart(final int rowIndex, final int partIndex) throws ParsingException { - return JsonUtils.getArray(lockupViewModel, + if (cachedMetadataRows == null) { + cachedMetadataRows = JsonUtils.getArray(lockupViewModel, "metadata.lockupMetadataViewModel.metadata" - + ".contentMetadataViewModel.metadataRows") + + ".contentMetadataViewModel.metadataRows"); + } + return cachedMetadataRows .streamAsJsonObjects() .skip(rowIndex) .limit(1) @@ -258,17 +269,4 @@ public class YoutubeStreamInfoItemLockupExtractor implements StreamInfoItemExtra private String getTextContentFromMetadataPart(final JsonObject metadataPart) { return metadataPart.getObject("text").getString("content"); } - - @Nullable - @Override - public String getShortDescription() { - // Not present - return null; - } - - @Override - public boolean isShortFormContent() throws ParsingException { - // TODO Detect with samples - return false; - } }