|
26 | 26 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.CONTENT_CHECK_OK; |
27 | 27 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.CPN; |
28 | 28 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.RACY_CHECK_OK; |
| 29 | +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.STRING_PREDICATE; |
29 | 30 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.VIDEO_ID; |
30 | 31 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl; |
31 | 32 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.generateContentPlaybackNonce; |
| 33 | +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getFirstCollaborator; |
32 | 34 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getImagesFromThumbnailsArray; |
33 | 35 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse; |
34 | 36 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject; |
| 37 | +import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.hasArtistOrVerifiedIconBadgeAttachment; |
35 | 38 | import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder; |
36 | 39 | import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; |
37 | 40 |
|
@@ -119,6 +122,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { |
119 | 122 | private static final String THUMBNAILS = "thumbnails"; |
120 | 123 | private static final String VIDEO_DETAILS = "videoDetails"; |
121 | 124 | private static final String TITLE = "title"; |
| 125 | + private static final String BADGES = "badges"; |
122 | 126 |
|
123 | 127 | @Nullable |
124 | 128 | private static PoTokenProvider poTokenProvider; |
@@ -488,17 +492,16 @@ public String getUploaderName() throws ParsingException { |
488 | 492 |
|
489 | 493 | @Override |
490 | 494 | public boolean isUploaderVerified() { |
491 | | - final var videoOwnerRenderer = getVideoSecondaryInfoRenderer().getObject("owner") |
| 495 | + final var videoOwnerRenderer = getVideoSecondaryInfoRenderer() |
| 496 | + .getObject("owner") |
492 | 497 | .getObject("videoOwnerRenderer"); |
493 | 498 |
|
494 | | - return Optional.ofNullable(videoOwnerRenderer.getArray("badges", null)) |
| 499 | + return Optional.ofNullable(videoOwnerRenderer.getArray(BADGES, null)) |
495 | 500 | .map(YoutubeParsingHelper::isVerified) |
496 | | - .or(() -> YoutubeParsingHelper.getFirstCollaborator(videoOwnerRenderer) |
| 501 | + .or(() -> getFirstCollaborator(videoOwnerRenderer.getObject("navigationEndpoint")) |
497 | 502 | .map(channel -> { |
498 | | - final var attachmentRuns = channel.getObject(TITLE) |
499 | | - .getArray("attachmentRuns"); |
500 | | - return YoutubeParsingHelper |
501 | | - .hasArtistOrVerifiedIconBadgeAttachment(attachmentRuns); |
| 503 | + final var runs = channel.getObject(TITLE).getArray("attachmentRuns"); |
| 504 | + return hasArtistOrVerifiedIconBadgeAttachment(runs); |
502 | 505 | })) |
503 | 506 | .orElse(false); |
504 | 507 | } |
@@ -534,26 +537,19 @@ public List<Image> getUploaderAvatars() throws ParsingException { |
534 | 537 |
|
535 | 538 | @Override |
536 | 539 | public long getUploaderSubscriberCount() throws ParsingException { |
537 | | - final JsonObject videoOwnerRenderer = JsonUtils.getObject(getVideoSecondaryInfoRenderer(), |
| 540 | + final var renderer = JsonUtils.getObject(getVideoSecondaryInfoRenderer(), |
538 | 541 | "owner.videoOwnerRenderer"); |
| 542 | + final var subscriberCountText = getTextFromObject(renderer.getObject("subscriberCountText")) |
| 543 | + .or(() -> getFirstCollaborator(renderer.getObject("navigationEndpoint")) |
| 544 | + .map(endpoint -> endpoint.getObject("subtitle").getString("content"))) |
| 545 | + .filter(STRING_PREDICATE); |
539 | 546 |
|
540 | | - final String subscriberCountText; |
541 | | - if (videoOwnerRenderer.has("subscriberCountText")) { |
542 | | - subscriberCountText = getTextFromObject(videoOwnerRenderer |
543 | | - .getObject("subscriberCountText")).orElse(null); |
544 | | - } else { |
545 | | - subscriberCountText = YoutubeParsingHelper |
546 | | - .getFirstCollaborator(videoOwnerRenderer.getObject("navigationEndpoint")) |
547 | | - .map(endpoint -> endpoint.getObject("subtitle").getString("content")) |
548 | | - .orElse(null); |
549 | | - } |
550 | | - |
551 | | - if (isNullOrEmpty(subscriberCountText)) { |
| 547 | + if (subscriberCountText.isEmpty()) { |
552 | 548 | return UNKNOWN_SUBSCRIBER_COUNT; |
553 | 549 | } |
554 | 550 |
|
555 | 551 | try { |
556 | | - return Utils.mixedNumberWordToLong(subscriberCountText); |
| 552 | + return Utils.mixedNumberWordToLong(subscriberCountText.get()); |
557 | 553 | } catch (final NumberFormatException e) { |
558 | 554 | throw new ParsingException("Could not get uploader subscriber count", e); |
559 | 555 | } |
@@ -1408,7 +1404,7 @@ public List<Frameset> getFrames() throws ExtractionException { |
1408 | 1404 | @Override |
1409 | 1405 | public Privacy getPrivacy() { |
1410 | 1406 | return playerMicroFormatRenderer.getBoolean("isUnlisted") |
1411 | | - || getVideoPrimaryInfoRenderer().getArray("badges") |
| 1407 | + || getVideoPrimaryInfoRenderer().getArray(BADGES) |
1412 | 1408 | .streamAsJsonObjects() |
1413 | 1409 | .anyMatch(badge -> |
1414 | 1410 | "PRIVACY_UNLISTED".equals(badge.getObject("metadataBadgeRenderer") |
|
0 commit comments