Using Class instead of HashMap, removed downloadSubtitles method

This commit is contained in:
tonakriz 2017-11-23 11:47:08 +01:00
parent 72f9ac223e
commit f09b4e68d0
4 changed files with 9 additions and 21 deletions

View File

@ -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;
}

View File

@ -105,6 +105,6 @@ public class SoundcloudStreamExtractorDefaultTest {
@Test
public void testGetSubtitles() throws IOException, ExtractionException, JsonParserException {
assertTrue(extractor.getSubtitlesList() != null);
assertTrue(extractor.getSubtitles() != null);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}