Skip to content

Commit 2c7acc7

Browse files
committed
Fixed exceptions as requested
1 parent 310b345 commit 2c7acc7

6 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionExc
148148
}
149149

150150
@Override
151-
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException {
151+
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException {
152152
return null;
153153
}
154154

155155
@Override
156-
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException {
156+
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
157157
return null;
158158
}
159159

src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractor.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,19 +380,25 @@ public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionExc
380380
}
381381

382382
@Override
383-
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException {
383+
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException {
384384
return getSubtitles(SubtitlesFormat.TTML);
385385
}
386386

387387
@Override
388-
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException {
388+
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
389389
JsonObject playerConfig = getPlayerConfig(getPageHtml());
390390
String playerResponse = playerConfig.getObject("args").getString("player_response");
391391

392-
// Captions does not exist, return null
393-
if (!JsonParser.object().from(playerResponse).has("captions")) return null;
392+
JsonObject captions;
393+
try {
394+
// Captions does not exist, return null
395+
if (!JsonParser.object().from(playerResponse).has("captions")) return null;
394396

395-
JsonObject captions = JsonParser.object().from(playerResponse).getObject("captions");
397+
captions = JsonParser.object().from(playerResponse).getObject("captions");
398+
} catch (JsonParserException e) {
399+
// Failed to parse subtitles
400+
return null;
401+
}
396402
JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks");
397403

398404
int captionsSize = captionsArray.size();

src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,8 @@ protected long getTimestampSeconds(String regexPattern) throws ParsingException
112112
public abstract List<AudioStream> getAudioStreams() throws IOException, ExtractionException;
113113
public abstract List<VideoStream> getVideoStreams() throws IOException, ExtractionException;
114114
public abstract List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException;
115-
public abstract List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException, JsonParserException;
116-
117-
public abstract List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException, JsonParserException;
115+
public abstract List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException;
116+
public abstract List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException;
118117

119118
public abstract StreamType getStreamType() throws ParsingException;
120119
public abstract StreamInfoItem getNextVideo() throws IOException, ExtractionException;

src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractorDefaultTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ public void testGetRelatedVideos() throws ExtractionException, IOException {
107107
}
108108

109109
@Test
110-
public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException {
110+
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
111111
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
112112
assertTrue(extractor.getSubtitlesDefault() == null);
113113
}
114114

115115
@Test
116-
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
116+
public void testGetSubtitlesList() throws IOException, ExtractionException {
117117
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
118118
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
119119
}

src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorDefaultTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ public void testGetRelatedVideos() throws ExtractionException, IOException {
149149
}
150150

151151
@Test
152-
public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException {
152+
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
153153
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
154154
assertTrue(extractor.getSubtitlesDefault() == null);
155155
}
156156

157157
@Test
158-
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
158+
public void testGetSubtitlesList() throws IOException, ExtractionException {
159159
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
160160
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
161161
}

src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ public void testGetVideoStreams() throws IOException, ExtractionException {
108108

109109

110110
@Test
111-
public void testGetSubtitlesListDefault() throws IOException, ExtractionException, JsonParserException {
111+
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
112112
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
113113
assertTrue(extractor.getSubtitlesDefault() == null);
114114
}
115115

116116
@Test
117-
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
117+
public void testGetSubtitlesList() throws IOException, ExtractionException {
118118
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
119119
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
120120
}

0 commit comments

Comments
 (0)