diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java index b4702c64d..90404282e 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java @@ -148,12 +148,12 @@ public class SoundcloudStreamExtractor extends StreamExtractor { } @Override - public List getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException { + public List getSubtitlesDefault() throws IOException, ExtractionException { return null; } @Override - public List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException { + public List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException { return null; } 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 00ee2433d..40e102264 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 @@ -380,19 +380,25 @@ public class YoutubeStreamExtractor extends StreamExtractor { } @Override - public List getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException { + public List getSubtitlesDefault() throws IOException, ExtractionException { return getSubtitles(SubtitlesFormat.TTML); } @Override - public List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException { + public List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException { 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; + try { + // Captions does not exist, return null + if (!JsonParser.object().from(playerResponse).has("captions")) return null; - JsonObject captions = JsonParser.object().from(playerResponse).getObject("captions"); + captions = JsonParser.object().from(playerResponse).getObject("captions"); + } catch (JsonParserException e) { + // Failed to parse subtitles + return null; + } JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks"); int captionsSize = captionsArray.size(); diff --git a/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java b/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java index a7c38da93..55bb2037f 100644 --- a/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java +++ b/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java @@ -112,9 +112,8 @@ public abstract class StreamExtractor extends Extractor { public abstract List getAudioStreams() throws IOException, ExtractionException; public abstract List getVideoStreams() throws IOException, ExtractionException; public abstract List getVideoOnlyStreams() throws IOException, ExtractionException; - public abstract List getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException; - - public abstract List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException; + public abstract List getSubtitlesDefault() throws IOException, ExtractionException; + public abstract List getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException; public abstract StreamType getStreamType() throws ParsingException; public abstract StreamInfoItem getNextVideo() throws IOException, ExtractionException; 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 9cf1c24ba..fe23298bf 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 @@ -107,13 +107,13 @@ public class SoundcloudStreamExtractorDefaultTest { } @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException { + public void testGetSubtitlesListDefault() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertTrue(extractor.getSubtitlesDefault() == null); } @Test - public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException { + public void testGetSubtitlesList() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == 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 fbc4d68dd..6e15b499e 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 @@ -149,13 +149,13 @@ public class YoutubeStreamExtractorDefaultTest { } @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException { + public void testGetSubtitlesListDefault() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertTrue(extractor.getSubtitlesDefault() == null); } @Test - public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException { + public void testGetSubtitlesList() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == 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 b0f1c30f4..65a11ebe1 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 @@ -108,13 +108,13 @@ public class YoutubeStreamExtractorRestrictedTest { @Test - public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException { + public void testGetSubtitlesListDefault() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertTrue(extractor.getSubtitlesDefault() == null); } @Test - public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException { + public void testGetSubtitlesList() throws IOException, ExtractionException { // Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null); }