From f09b4e68d00dfdffd8dfd2945457c1f7a428c524 Mon Sep 17 00:00:00 2001 From: tonakriz Date: Thu, 23 Nov 2017 11:47:08 +0100 Subject: [PATCH] Using Class instead of HashMap, removed downloadSubtitles method --- .../services/youtube/YoutubeStreamExtractor.java | 7 +++++-- .../SoundcloudStreamExtractorDefaultTest.java | 2 +- .../youtube/YoutubeStreamExtractorDefaultTest.java | 14 ++------------ .../YoutubeStreamExtractorRestrictedTest.java | 7 +------ 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java index b9345e2e..daf5b8ac 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java @@ -426,14 +426,17 @@ public class YoutubeStreamExtractor extends StreamExtractor { JsonObject playerConfig = getPlayerConfig(getPageHtml()); String playerResponse = playerConfig.getObject("args").getString("player_response"); + // Captions does not exist, return null if (!JsonParser.object().from(playerResponse).has("captions")) return null; JsonObject captions = JsonParser.object().from(playerResponse).getObject("captions"); JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks"); int captionsSize = captionsArray.size(); - Subtitles[] result = new Subtitles[captionsSize]; + // Should not happen, if there is the "captions" object, it should always has some captions in it + if(captionsSize == 0) return null; + Subtitles[] result = new Subtitles[captionsSize]; for (int x = 0; x < captionsSize; x++) { String baseUrl = captionsArray.getObject(x).getString("baseUrl"); @@ -447,7 +450,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { result[x] = new Subtitles(languageName, languageCode, URL, isAutoGenerated); } - + return result; } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java index 882e0da3..6df8d430 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java @@ -105,6 +105,6 @@ public class SoundcloudStreamExtractorDefaultTest { @Test public void testGetSubtitles() throws IOException, ExtractionException, JsonParserException { - assertTrue(extractor.getSubtitlesList() != null); + assertTrue(extractor.getSubtitles() != null); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java index 77d484a2..07cad201 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java @@ -153,17 +153,7 @@ public class YoutubeStreamExtractorDefaultTest { @Test public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException { - assertTrue(extractor.getSubtitlesList() != null); - } - - @Test - public void testDownloadSubtitles() throws Exception { - try { - extractor.downloadSubtitles(extractor.getSubtitlesList().get("en")[0]); - // Video has no subtitles! - assert false; - } catch (Exception e) { - assert true; - } + // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null + assertTrue(extractor.getSubtitles() != null); } } diff --git a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java index 7b604f43..9bc89eef 100644 --- a/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java +++ b/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java @@ -107,11 +107,6 @@ public class YoutubeStreamExtractorRestrictedTest { @Test public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException { - assertTrue(extractor.getSubtitlesList() != null); - } - - @Test - public void testDownloadSubtitles() throws Exception { - assertTrue(extractor.downloadSubtitles("https://youtu.be/FmG385_uUys?t=174") != null); + assertTrue(extractor.getSubtitles() != null); } }