|
1 | 1 | package org.schabi.newpipe.extractor.services.youtube.extractors; |
2 | 2 |
|
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 | | - |
8 | 3 | import com.grack.nanojson.JsonArray; |
9 | 4 | import com.grack.nanojson.JsonObject; |
10 | | - |
11 | 5 | import org.schabi.newpipe.extractor.exceptions.ParsingException; |
12 | 6 | import org.schabi.newpipe.extractor.localization.DateWrapper; |
13 | 7 | import org.schabi.newpipe.extractor.localization.TimeAgoParser; |
|
18 | 12 | import org.schabi.newpipe.extractor.utils.JsonUtils; |
19 | 13 | import org.schabi.newpipe.extractor.utils.Utils; |
20 | 14 |
|
| 15 | +import javax.annotation.Nullable; |
21 | 16 | import java.time.Instant; |
22 | 17 | import java.time.OffsetDateTime; |
23 | 18 | import java.time.ZoneOffset; |
24 | 19 | import java.time.format.DateTimeFormatter; |
25 | 20 |
|
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; |
27 | 25 |
|
28 | 26 | /* |
29 | 27 | * Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org> |
@@ -331,7 +329,37 @@ public boolean isShortFormContent() throws ParsingException { |
331 | 329 | final String webPageType = videoInfo.getObject("navigationEndpoint") |
332 | 330 | .getObject("commandMetadata").getObject("webCommandMetadata") |
333 | 331 | .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; |
335 | 363 | } catch (final Exception e) { |
336 | 364 | throw new ParsingException("Could not determine if this is short-form content", e); |
337 | 365 | } |
|
0 commit comments