Skip to content

Commit f9bd08c

Browse files
FireMasterKchowder
authored andcommitted
Address reviews.
1 parent 9282c3c commit f9bd08c

3 files changed

Lines changed: 42 additions & 12 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package org.schabi.newpipe.extractor.services.youtube.extractors;
22

3-
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
4-
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getThumbnailUrlFromInfoItem;
5-
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
6-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
7-
83
import com.grack.nanojson.JsonArray;
94
import com.grack.nanojson.JsonObject;
10-
115
import org.schabi.newpipe.extractor.exceptions.ParsingException;
126
import org.schabi.newpipe.extractor.localization.DateWrapper;
137
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
@@ -18,12 +12,16 @@
1812
import org.schabi.newpipe.extractor.utils.JsonUtils;
1913
import org.schabi.newpipe.extractor.utils.Utils;
2014

15+
import javax.annotation.Nullable;
2116
import java.time.Instant;
2217
import java.time.OffsetDateTime;
2318
import java.time.ZoneOffset;
2419
import java.time.format.DateTimeFormatter;
2520

26-
import javax.annotation.Nullable;
21+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
22+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getThumbnailUrlFromInfoItem;
23+
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
24+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2725

2826
/*
2927
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
@@ -331,7 +329,37 @@ public boolean isShortFormContent() throws ParsingException {
331329
final String webPageType = videoInfo.getObject("navigationEndpoint")
332330
.getObject("commandMetadata").getObject("webCommandMetadata")
333331
.getString("webPageType");
334-
return !isNullOrEmpty(webPageType) && webPageType.equals("WEB_PAGE_TYPE_SHORTS");
332+
333+
boolean isShort = !isNullOrEmpty(webPageType)
334+
&& webPageType.equals("WEB_PAGE_TYPE_SHORTS");
335+
336+
if (!isShort) {
337+
isShort = videoInfo.getObject("navigationEndpoint").has("reelWatchEndpoint");
338+
}
339+
340+
if (!isShort) {
341+
final JsonObject thumbnailTimeOverlay = videoInfo.getArray("thumbnailOverlays")
342+
.stream()
343+
.filter(JsonObject.class::isInstance)
344+
.map(JsonObject.class::cast)
345+
.filter(thumbnailOverlay -> thumbnailOverlay.has(
346+
"thumbnailOverlayTimeStatusRenderer"))
347+
.map(thumbnailOverlay -> thumbnailOverlay.getObject(
348+
"thumbnailOverlayTimeStatusRenderer"))
349+
.findFirst()
350+
.orElse(null);
351+
352+
if (!isNullOrEmpty(thumbnailTimeOverlay)) {
353+
isShort = thumbnailTimeOverlay.getString("style")
354+
.equalsIgnoreCase("SHORTS")
355+
|| thumbnailTimeOverlay.getObject("icon")
356+
.getString("iconType")
357+
.toLowerCase()
358+
.contains("shorts");
359+
}
360+
}
361+
362+
return isShort;
335363
} catch (final Exception e) {
336364
throw new ParsingException("Could not determine if this is short-form content", e);
337365
}

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public void setShortFormContent(final boolean shortFormContent) {
139139
this.shortFormContent = shortFormContent;
140140
}
141141

142-
143142
@Override
144143
public String toString() {
145144
return "StreamInfoItem{"

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfoItemExtractor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,13 @@ default String getShortDescription() throws ParsingException {
129129
}
130130

131131
/**
132-
* Check if the stream is a short-form content
132+
* Whether the stream is a short-form content.
133133
*
134-
* @return {@code true} if the stream is a short-form content
135-
* @throws ParsingException thrown if there is an error in the extraction
134+
* <p>
135+
* Short-form contents are contents in the style of TikTok, YouTube Shorts, or Instagram Reels videos.
136+
* </p>
137+
*
138+
* @return whether the stream is a short-form content
136139
*/
137140
default boolean isShortFormContent() throws ParsingException {
138141
return false;

0 commit comments

Comments
 (0)