|
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; |
@@ -493,7 +495,7 @@ public boolean isUploaderVerified() { |
493 | 495 |
|
494 | 496 | return Optional.ofNullable(videoOwnerRenderer.getArray("badges", null)) |
495 | 497 | .map(YoutubeParsingHelper::isVerified) |
496 | | - .or(() -> YoutubeParsingHelper.getFirstCollaborator(videoOwnerRenderer) |
| 498 | + .or(() -> getFirstCollaborator(videoOwnerRenderer) |
497 | 499 | .map(channel -> { |
498 | 500 | final var attachmentRuns = channel.getObject(TITLE) |
499 | 501 | .getArray("attachmentRuns"); |
@@ -534,26 +536,19 @@ public List<Image> getUploaderAvatars() throws ParsingException { |
534 | 536 |
|
535 | 537 | @Override |
536 | 538 | public long getUploaderSubscriberCount() throws ParsingException { |
537 | | - final JsonObject videoOwnerRenderer = JsonUtils.getObject(getVideoSecondaryInfoRenderer(), |
| 539 | + final var renderer = JsonUtils.getObject(getVideoSecondaryInfoRenderer(), |
538 | 540 | "owner.videoOwnerRenderer"); |
| 541 | + final var subscriberCountText = getTextFromObject(renderer.getObject("subscriberCountText")) |
| 542 | + .or(() -> getFirstCollaborator(renderer.getObject("navigationEndpoint")) |
| 543 | + .map(endpoint -> endpoint.getObject("subtitle").getString("content"))) |
| 544 | + .filter(STRING_PREDICATE); |
539 | 545 |
|
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)) { |
| 546 | + if (subscriberCountText.isEmpty()) { |
552 | 547 | return UNKNOWN_SUBSCRIBER_COUNT; |
553 | 548 | } |
554 | 549 |
|
555 | 550 | try { |
556 | | - return Utils.mixedNumberWordToLong(subscriberCountText); |
| 551 | + return Utils.mixedNumberWordToLong(subscriberCountText.get()); |
557 | 552 | } catch (final NumberFormatException e) { |
558 | 553 | throw new ParsingException("Could not get uploader subscriber count", e); |
559 | 554 | } |
|
0 commit comments