From 0cd5e05b7b927a3d53048e5347a4f37fd8920efa Mon Sep 17 00:00:00 2001 From: bopol Date: Mon, 2 Mar 2020 22:38:44 +0100 Subject: [PATCH] MediaCCCLH: use substring instead of replace; improve a bit tests, return Collections.emptyList(); instead of null where it's annotated @NonNull --- .../extractors/MediaCCCStreamExtractor.java | 11 +++++++---- .../MediaCCCStreamLinkHandlerFactory.java | 2 +- .../media_ccc/MediaCCCStreamExtractorTest.java | 12 ++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java index 424e8fdd1..59bfe1f4f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java @@ -16,6 +16,7 @@ import org.schabi.newpipe.extractor.stream.*; import javax.annotation.Nonnull; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Locale; @@ -104,13 +105,13 @@ public class MediaCCCStreamExtractor extends StreamExtractor { @Nonnull @Override public String getDashMpdUrl() throws ParsingException { - return null; + return ""; } @Nonnull @Override public String getHlsUrl() throws ParsingException { - return null; + return ""; } @Override @@ -170,14 +171,16 @@ public class MediaCCCStreamExtractor extends StreamExtractor { return null; } + @Nonnull @Override public List getSubtitlesDefault() throws IOException, ExtractionException { - return null; + return Collections.emptyList(); } + @Nonnull @Override public List getSubtitles(final MediaFormat format) throws IOException, ExtractionException { - return null; + return Collections.emptyList(); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java index 76e5df895..2c91d0564 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCStreamLinkHandlerFactory.java @@ -14,7 +14,7 @@ public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory { public String getId(String urlString) throws ParsingException { if (urlString.startsWith("https://api.media.ccc.de/public/events/") && !urlString.contains("?q=")) { - return urlString.replace("https://api.media.ccc.de/public/events/", ""); + return urlString.substring(39); //remove apiā€¦/public/events part } URL url; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java index 9cb856625..c0f51437d 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCStreamExtractorTest.java @@ -7,6 +7,7 @@ import org.schabi.newpipe.DownloaderTestImpl; import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCStreamExtractor; +import org.schabi.newpipe.extractor.utils.UtilsTest; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -14,6 +15,7 @@ import java.util.Calendar; import static java.util.Objects.requireNonNull; import static junit.framework.TestCase.assertEquals; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.MediaCCC; /** @@ -49,16 +51,19 @@ public class MediaCCCStreamExtractorTest { @Test public void testUrl() throws Exception { + assertIsSecureUrl(extractor.getUrl()); assertEquals("https://api.media.ccc.de/public/events/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getUrl()); } @Test public void testOriginalUrl() throws Exception { + assertIsSecureUrl(extractor.getOriginalUrl()); assertEquals("https://media.ccc.de/v/gpn18-105-tmux-warum-ein-schwarzes-fenster-am-bildschirm-reicht", extractor.getOriginalUrl()); } @Test public void testThumbnail() throws Exception { + assertIsSecureUrl(extractor.getThumbnailUrl()); assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/105-hd.jpg", extractor.getThumbnailUrl()); } @@ -69,11 +74,13 @@ public class MediaCCCStreamExtractorTest { @Test public void testUploaderUrl() throws Exception { + assertIsSecureUrl(extractor.getUploaderUrl()); assertEquals("https://api.media.ccc.de/public/conferences/gpn18", extractor.getUploaderUrl()); } @Test public void testUploaderAvatarUrl() throws Exception { + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); assertEquals("https://static.media.ccc.de/media/events/gpn/gpn18/logo.png", extractor.getUploaderAvatarUrl()); } @@ -122,16 +129,19 @@ public class MediaCCCStreamExtractorTest { @Test public void testUrl() throws Exception { + assertIsSecureUrl(extractor.getUrl()); assertEquals("https://api.media.ccc.de/public/events/36c3-10565-what_s_left_for_private_messaging", extractor.getUrl()); } @Test public void testOriginalUrl() throws Exception { + assertIsSecureUrl(extractor.getOriginalUrl()); assertEquals("https://media.ccc.de/v/36c3-10565-what_s_left_for_private_messaging", extractor.getOriginalUrl()); } @Test public void testThumbnail() throws Exception { + assertIsSecureUrl(extractor.getThumbnailUrl()); assertEquals("https://static.media.ccc.de/media/congress/2019/10565-hd.jpg", extractor.getThumbnailUrl()); } @@ -142,11 +152,13 @@ public class MediaCCCStreamExtractorTest { @Test public void testUploaderUrl() throws Exception { + assertIsSecureUrl(extractor.getUploaderUrl()); assertEquals("https://api.media.ccc.de/public/conferences/36c3", extractor.getUploaderUrl()); } @Test public void testUploaderAvatarUrl() throws Exception { + assertIsSecureUrl(extractor.getUploaderAvatarUrl()); assertEquals("https://static.media.ccc.de/media/congress/2019/logo.png", extractor.getUploaderAvatarUrl()); }