From 6f3f608ab651574999a169cd506428ded9eac491 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 11 Feb 2022 04:08:22 +0000 Subject: [PATCH 1/7] Add support for extracting channel subscriber count in StreamInfo. --- .../extractors/YoutubeStreamExtractor.java | 15 +++++++++++++++ .../newpipe/extractor/stream/StreamExtractor.java | 11 +++++++++++ .../newpipe/extractor/stream/StreamInfo.java | 14 ++++++++++++++ .../services/BaseStreamExtractorTest.java | 1 + .../services/DefaultStreamExtractorTest.java | 7 +++++++ .../stream/YoutubeStreamExtractorDefaultTest.java | 5 +++++ 6 files changed, 53 insertions(+) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 6c7ac66b..10a20393 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -45,6 +45,7 @@ import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.*; +import static org.schabi.newpipe.extractor.ListExtractor.ITEM_COUNT_UNKNOWN; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; @@ -437,6 +438,20 @@ public class YoutubeStreamExtractor extends StreamExtractor { return fixThumbnailUrl(url); } + @Override + public long getUploaderSubscriberCount() throws ParsingException { + final JsonObject videoOwnerRenderer = JsonUtils.getObject(videoSecondaryInfoRenderer, "owner.videoOwnerRenderer"); + if (videoOwnerRenderer.has("subscriberCountText")) { + try { + return Utils.mixedNumberWordToLong(getTextFromObject(videoOwnerRenderer.getObject("subscriberCountText"))); + } catch (final NumberFormatException e) { + throw new ParsingException("Could not get subscriber count", e); + } + } else { + return ITEM_COUNT_UNKNOWN; + } + } + @Nonnull @Override public String getDashMpdUrl() throws ParsingException { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index b78f8664..f7bac660 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -202,6 +202,17 @@ public abstract class StreamExtractor extends Extractor { return false; } + /** + * The subscriber count of the uploader. + * If the subscriber count is not implemented, or is unavailable, return -1. + * + * @return the subscriber count of the uploader or -1 if not available + * @throws ParsingException + */ + public long getUploaderSubscriberCount() throws ParsingException { + return -1; + } + /** * The url to the image file/profile picture/avatar of the creator/uploader of the stream. * If the url is not available you can return an empty String. diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java index 455f0dc4..42ca495c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java @@ -235,6 +235,11 @@ public class StreamInfo extends Info { } catch (Exception e) { streamInfo.addError(e); } + try { + streamInfo.setUploaderSubscriberCount(extractor.getUploaderSubscriberCount()); + } catch (Exception e) { + streamInfo.addError(e); + } try { streamInfo.setSubChannelName(extractor.getSubChannelName()); @@ -367,6 +372,7 @@ public class StreamInfo extends Info { private String uploaderUrl = ""; private String uploaderAvatarUrl = ""; private boolean uploaderVerified = false; + private long uploaderSubscriberCount = -1; private String subChannelName = ""; private String subChannelUrl = ""; @@ -540,6 +546,14 @@ public class StreamInfo extends Info { this.uploaderVerified = uploaderVerified; } + public long getUploaderSubscriberCount() { + return uploaderSubscriberCount; + } + + public void setUploaderSubscriberCount(long uploaderSubscriberCount) { + this.uploaderSubscriberCount = uploaderSubscriberCount; + } + public String getSubChannelName() { return subChannelName; } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java index f32a6090..da418660 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/BaseStreamExtractorTest.java @@ -5,6 +5,7 @@ public interface BaseStreamExtractorTest extends BaseExtractorTest { void testUploaderName() throws Exception; void testUploaderUrl() throws Exception; void testUploaderAvatarUrl() throws Exception; + void testSubscriberCount() throws Exception; void testSubChannelName() throws Exception; void testSubChannelUrl() throws Exception; void testSubChannelAvatarUrl() throws Exception; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java index 1563abac..5f02d55a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java @@ -45,6 +45,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest expectedDescriptionContains() { return Arrays.asList("https://www.youtube.com/channel/UC7l23W7gFi4Uho6WSzckZRA", "https://www.handcraftpictures.com/"); @@ -182,6 +183,7 @@ public class YoutubeStreamExtractorDefaultTest { @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @Override public String expectedUploaderName() { return "Unbox Therapy"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCsTcErHg8oDvUnTzoqsYeNw"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 18_000_000; } @Override public List expectedDescriptionContains() { return Arrays.asList("https://www.youtube.com/watch?v=X7FLCHVXpsA&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34", "https://www.youtube.com/watch?v=Lqv6G0pDNnw&list=PL7u4lWXQ3wfI_7PgX0C-VTiwLeu0S4v34", @@ -274,6 +276,7 @@ public class YoutubeStreamExtractorDefaultTest { @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @Override public String expectedUploaderName() { return "tagesschau"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UC5NOEUbkLheQcaaRldYW5GA"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 1_000_000; } @Override public boolean expectedUploaderVerified() { return true; } @Override public List expectedDescriptionContains() { return Arrays.asList("Themen der Sendung", "07:15", "Wetter", "Sendung nachträglich bearbeitet"); @@ -336,6 +339,7 @@ public class YoutubeStreamExtractorDefaultTest { @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @Override public String expectedUploaderName() { return "maiLab"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCyHDQ5C6z1NDmJ4g6SerW8g"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 1_400_000; } @Override public List expectedDescriptionContains() {return Arrays.asList("Vitamin", "2:44", "Was ist Vitamin D?");} @Override public boolean expectedUploaderVerified() { return true; } @Override public long expectedLength() { return 1010; } @@ -405,6 +409,7 @@ public class YoutubeStreamExtractorDefaultTest { @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @Override public String expectedUploaderName() { return "Dinge Erklärt – Kurzgesagt"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCwRH985XgMYXQ6NxXDo8npw"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 1_500_000; } @Override public List expectedDescriptionContains() { return Arrays.asList("Lasst uns abtauchen!", "Angebot von funk", "Dinge"); } @Override public long expectedLength() { return 631; } @Override public long expectedTimestamp() { return TIMESTAMP; } From 4bd59f65f43b41e86fee3c12aac9f76e7e5256c5 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 12 Feb 2022 00:31:55 +0000 Subject: [PATCH 2/7] Update exception message. Co-authored-by: Tobi --- .../services/youtube/extractors/YoutubeStreamExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 10a20393..3e377b55 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -445,7 +445,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { try { return Utils.mixedNumberWordToLong(getTextFromObject(videoOwnerRenderer.getObject("subscriberCountText"))); } catch (final NumberFormatException e) { - throw new ParsingException("Could not get subscriber count", e); + throw new ParsingException("Could not get uploader subscriber count", e); } } else { return ITEM_COUNT_UNKNOWN; From ab49cb6e18cfb50d07e450281ab5d1f04e0f2a7c Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 12 Feb 2022 18:00:54 +0000 Subject: [PATCH 3/7] Add requested changes. --- .../services/youtube/extractors/YoutubeChannelExtractor.java | 4 +++- .../services/youtube/extractors/YoutubeStreamExtractor.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java index d7ba0712..6b19d606 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java @@ -61,6 +61,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor { private JsonObject initialData; private JsonObject videoTab; + private static final long UNKNOWN_SUBSCRIBER_COUNT = -1; + /** * Some channels have response redirects and the only way to reliably get the id is by saving it. *

@@ -281,7 +283,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor { throw new ParsingException("Could not get subscriber count", e); } } else { - return ITEM_COUNT_UNKNOWN; + return UNKNOWN_SUBSCRIBER_COUNT; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 3e377b55..3799dec7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -45,7 +45,6 @@ import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.*; -import static org.schabi.newpipe.extractor.ListExtractor.ITEM_COUNT_UNKNOWN; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.*; import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; @@ -104,6 +103,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { @Nullable private List subtitles = null; + private static final long UNKNOWN_SUBSCRIBER_COUNT = -1; + public YoutubeStreamExtractor(final StreamingService service, final LinkHandler linkHandler) { super(service, linkHandler); } @@ -448,7 +449,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { throw new ParsingException("Could not get uploader subscriber count", e); } } else { - return ITEM_COUNT_UNKNOWN; + return UNKNOWN_SUBSCRIBER_COUNT; } } From d290d2e39396a4a5856ebfa2d5cd59e438f0f69a Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sun, 13 Feb 2022 19:43:17 +0000 Subject: [PATCH 4/7] Move variable to super Extractor classes. --- .../org/schabi/newpipe/extractor/channel/ChannelExtractor.java | 2 ++ .../services/youtube/extractors/YoutubeChannelExtractor.java | 2 -- .../services/youtube/extractors/YoutubeStreamExtractor.java | 2 -- .../org/schabi/newpipe/extractor/stream/StreamExtractor.java | 1 + 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java index 8f2fe79a..1ec47498 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/channel/ChannelExtractor.java @@ -28,6 +28,8 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem; public abstract class ChannelExtractor extends ListExtractor { + public static final long UNKNOWN_SUBSCRIBER_COUNT = -1; + public ChannelExtractor(StreamingService service, ListLinkHandler linkHandler) { super(service, linkHandler); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java index 6b19d606..b01767e3 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java @@ -61,8 +61,6 @@ public class YoutubeChannelExtractor extends ChannelExtractor { private JsonObject initialData; private JsonObject videoTab; - private static final long UNKNOWN_SUBSCRIBER_COUNT = -1; - /** * Some channels have response redirects and the only way to reliably get the id is by saving it. *

diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 3799dec7..34e414a7 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -103,8 +103,6 @@ public class YoutubeStreamExtractor extends StreamExtractor { @Nullable private List subtitles = null; - private static final long UNKNOWN_SUBSCRIBER_COUNT = -1; - public YoutubeStreamExtractor(final StreamingService service, final LinkHandler linkHandler) { super(service, linkHandler); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index f7bac660..c84a7a8f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -47,6 +47,7 @@ import java.util.Locale; public abstract class StreamExtractor extends Extractor { public static final int NO_AGE_LIMIT = 0; + public static final long UNKNOWN_SUBSCRIBER_COUNT = -1; public StreamExtractor(StreamingService service, LinkHandler linkHandler) { super(service, linkHandler); From 5b0ec694a638cdbca038a76ad4bcae6daf6b37d6 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Tue, 22 Feb 2022 07:15:25 +0000 Subject: [PATCH 5/7] Add requested changes. --- .../schabi/newpipe/extractor/stream/StreamExtractor.java | 4 ++-- .../extractor/services/DefaultStreamExtractorTest.java | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index c84a7a8f..939b4f5a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -207,11 +207,11 @@ public abstract class StreamExtractor extends Extractor { * The subscriber count of the uploader. * If the subscriber count is not implemented, or is unavailable, return -1. * - * @return the subscriber count of the uploader or -1 if not available + * @return the subscriber count of the uploader or {@value UNKNOWN_SUBSCRIBER_COUNT} if not available * @throws ParsingException */ public long getUploaderSubscriberCount() throws ParsingException { - return -1; + return UNKNOWN_SUBSCRIBER_COUNT; } /** diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java index 5f02d55a..f8fb6e93 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/DefaultStreamExtractorTest.java @@ -34,6 +34,7 @@ import static org.schabi.newpipe.extractor.ExtractorAsserts.assertEqualsOrderInd import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsValidUrl; import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestListOfItems; +import static org.schabi.newpipe.extractor.stream.StreamExtractor.UNKNOWN_SUBSCRIBER_COUNT; /** * Test for {@link StreamExtractor} @@ -45,7 +46,7 @@ public abstract class DefaultStreamExtractorTest extends DefaultExtractorTest Date: Thu, 24 Feb 2022 12:50:41 +0000 Subject: [PATCH 6/7] Add test values for failing tests. --- .../youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java | 1 + .../youtube/stream/YoutubeStreamExtractorControversialTest.java | 1 + .../youtube/stream/YoutubeStreamExtractorLivestreamTest.java | 1 + .../youtube/stream/YoutubeStreamExtractorUnlistedTest.java | 1 + 4 files changed, 4 insertions(+) diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java index 189109b8..1ac7b5c1 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java @@ -45,6 +45,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtrac @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @Override public String expectedUploaderName() { return "DAN TV"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCcQHIVL83g5BEQe2IJFb-6w"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 50; } @Override public boolean expectedUploaderVerified() { return false; } @Override public boolean expectedDescriptionIsEmpty() { return true; } @Override public List expectedDescriptionContains() { return Collections.emptyList(); } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java index b7994036..73d7648a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java @@ -49,6 +49,7 @@ public class YoutubeStreamExtractorControversialTest extends DefaultStreamExtrac @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @Override public String expectedUploaderName() { return "Amazing Atheist"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCjNxszyFPasDdRoD9J6X-sw"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 977_000; } @Override public List expectedDescriptionContains() { return Arrays.asList("http://www.huffingtonpost.com/2010/09/09/obama-gma-interview-quran_n_710282.html", "freedom"); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java index e21bb446..3a3e7f0b 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java @@ -52,6 +52,7 @@ public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractor @Override public StreamType expectedStreamType() { return StreamType.LIVE_STREAM; } @Override public String expectedUploaderName() { return "Lofi Girl"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 9_800_000; } @Override public List expectedDescriptionContains() { return Arrays.asList("Lofi Girl merch", "Thank you for listening, I hope you will have a good time here"); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java index 5db8958c..a3f2b0b2 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java @@ -45,6 +45,7 @@ public class YoutubeStreamExtractorUnlistedTest extends DefaultStreamExtractorTe @Override public StreamType expectedStreamType() { return StreamType.VIDEO_STREAM; } @Override public String expectedUploaderName() { return "Hooked"; } @Override public String expectedUploaderUrl() { return "https://www.youtube.com/channel/UCPysfiuOv4VKBeXFFPhKXyw"; } + @Override public long expectedUploaderSubscriberCountAtLeast() { return 24_300; } @Override public List expectedDescriptionContains() { return Arrays.asList("https://www.youtube.com/user/Roccowschiptune", "https://www.facebook.com/HookedMagazinDE"); From e6d334765d8d7b66d718615678462b37a8f31cd0 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Sat, 26 Feb 2022 17:12:51 +0000 Subject: [PATCH 7/7] Apply requested codestyle improvements. --- .../extractors/YoutubeChannelExtractor.java | 39 +++++++++---------- .../extractors/YoutubeStreamExtractor.java | 31 +++++++-------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java index b01767e3..acc1fa11 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java @@ -89,9 +89,9 @@ public class YoutubeChannelExtractor extends ChannelExtractor { // we couldn't get information about the channel associated with this URL, if there is one. if (!channelId[0].equals("channel")) { final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder( - getExtractorLocalization(), getExtractorContentCountry()) - .value("url", "https://www.youtube.com/" + channelPath) - .done()) + getExtractorLocalization(), getExtractorContentCountry()) + .value("url", "https://www.youtube.com/" + channelPath) + .done()) .getBytes(UTF_8); final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url", @@ -104,8 +104,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor { throw new ContentNotAvailableException("This channel doesn't exist."); } else { throw new ContentNotAvailableException("Got error:\"" - + errorJsonObject.getString("status") + "\": " - + errorJsonObject.getString("message")); + + errorJsonObject.getString("status") + "\": " + + errorJsonObject.getString("message")); } } @@ -136,10 +136,10 @@ public class YoutubeChannelExtractor extends ChannelExtractor { int level = 0; while (level < 3) { final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder( - getExtractorLocalization(), getExtractorContentCountry()) - .value("browseId", id) - .value("params", "EgZ2aWRlb3M%3D") // Equal to videos - .done()) + getExtractorLocalization(), getExtractorContentCountry()) + .value("browseId", id) + .value("params", "EgZ2aWRlb3M%3D") // Equal to videos + .done()) .getBytes(UTF_8); final JsonObject jsonResponse = getJsonPostResponse("browse", body, @@ -273,16 +273,15 @@ public class YoutubeChannelExtractor extends ChannelExtractor { public long getSubscriberCount() throws ParsingException { final JsonObject c4TabbedHeaderRenderer = initialData.getObject("header") .getObject("c4TabbedHeaderRenderer"); - if (c4TabbedHeaderRenderer.has("subscriberCountText")) { - try { - return Utils.mixedNumberWordToLong(getTextFromObject(c4TabbedHeaderRenderer - .getObject("subscriberCountText"))); - } catch (final NumberFormatException e) { - throw new ParsingException("Could not get subscriber count", e); - } - } else { + if (!c4TabbedHeaderRenderer.has("subscriberCountText")) { return UNKNOWN_SUBSCRIBER_COUNT; } + try { + return Utils.mixedNumberWordToLong(getTextFromObject(c4TabbedHeaderRenderer + .getObject("subscriberCountText"))); + } catch (final NumberFormatException e) { + throw new ParsingException("Could not get subscriber count", e); + } } @Override @@ -385,9 +384,9 @@ public class YoutubeChannelExtractor extends ChannelExtractor { .getString("token"); final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(getExtractorLocalization(), - getExtractorContentCountry()) - .value("continuation", continuation) - .done()) + getExtractorContentCountry()) + .value("continuation", continuation) + .done()) .getBytes(UTF_8); return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey(), null, channelIds, null, body); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 34e414a7..7c728af6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -180,7 +180,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { // TODO: this parses English formatted dates only, we need a better approach to parse // the textual date final LocalDate localDate = LocalDate.parse(getTextFromObject( - getVideoPrimaryInfoRenderer().getObject("dateText")), + getVideoPrimaryInfoRenderer().getObject("dateText")), DateTimeFormatter.ofPattern("dd MMM yyyy", Locale.ENGLISH)); return DateTimeFormatter.ISO_LOCAL_DATE.format(localDate); } catch (final Exception ignored) { @@ -440,15 +440,14 @@ public class YoutubeStreamExtractor extends StreamExtractor { @Override public long getUploaderSubscriberCount() throws ParsingException { final JsonObject videoOwnerRenderer = JsonUtils.getObject(videoSecondaryInfoRenderer, "owner.videoOwnerRenderer"); - if (videoOwnerRenderer.has("subscriberCountText")) { - try { - return Utils.mixedNumberWordToLong(getTextFromObject(videoOwnerRenderer.getObject("subscriberCountText"))); - } catch (final NumberFormatException e) { - throw new ParsingException("Could not get uploader subscriber count", e); - } - } else { + if (!videoOwnerRenderer.has("subscriberCountText")) { return UNKNOWN_SUBSCRIBER_COUNT; } + try { + return Utils.mixedNumberWordToLong(getTextFromObject(videoOwnerRenderer.getObject("subscriberCountText"))); + } catch (final NumberFormatException e) { + throw new ParsingException("Could not get uploader subscriber count", e); + } } @Nonnull @@ -680,9 +679,9 @@ public class YoutubeStreamExtractor extends StreamExtractor { final Localization localization = getExtractorLocalization(); final ContentCountry contentCountry = getExtractorContentCountry(); final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder( - localization, contentCountry) - .value("videoId", videoId) - .done()) + localization, contentCountry) + .value("videoId", videoId) + .done()) .getBytes(UTF_8); // Put the sts string if we already know it so we don't have to fetch again the player @@ -731,8 +730,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { if (ageRestricted) { final byte[] ageRestrictedBody = JsonWriter.string(prepareDesktopEmbedVideoJsonBuilder( - localization, contentCountry, videoId) - .done()) + localization, contentCountry, videoId) + .done()) .getBytes(UTF_8); nextResponse = getJsonPostResponse("next", ageRestrictedBody, localization); } else { @@ -814,7 +813,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { final String videoId) throws IOException, ExtractionException { final byte[] mobileBody = JsonWriter.string(prepareAndroidMobileJsonBuilder( - localization, contentCountry) + localization, contentCountry) .value("videoId", videoId) .done()) .getBytes(UTF_8); @@ -887,8 +886,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { final String videoId) throws IOException, ExtractionException { final byte[] androidMobileEmbedBody = JsonWriter.string( - prepareAndroidMobileEmbedVideoJsonBuilder(localization, contentCountry, videoId) - .done()) + prepareAndroidMobileEmbedVideoJsonBuilder(localization, contentCountry, videoId) + .done()) .getBytes(UTF_8); final JsonObject androidMobileEmbedPlayerResponse = getJsonMobilePostResponse("player", androidMobileEmbedBody, contentCountry, localization);