Using Class instead of HashMap, removed downloadSubtitles method
This commit is contained in:
parent
72f9ac223e
commit
f09b4e68d0
|
@ -426,14 +426,17 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
JsonObject playerConfig = getPlayerConfig(getPageHtml());
|
JsonObject playerConfig = getPlayerConfig(getPageHtml());
|
||||||
String playerResponse = playerConfig.getObject("args").getString("player_response");
|
String playerResponse = playerConfig.getObject("args").getString("player_response");
|
||||||
|
|
||||||
|
// Captions does not exist, return null
|
||||||
if (!JsonParser.object().from(playerResponse).has("captions")) return null;
|
if (!JsonParser.object().from(playerResponse).has("captions")) return null;
|
||||||
|
|
||||||
JsonObject captions = JsonParser.object().from(playerResponse).getObject("captions");
|
JsonObject captions = JsonParser.object().from(playerResponse).getObject("captions");
|
||||||
JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks");
|
JsonArray captionsArray = captions.getObject("playerCaptionsTracklistRenderer").getArray("captionTracks");
|
||||||
|
|
||||||
int captionsSize = captionsArray.size();
|
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++) {
|
for (int x = 0; x < captionsSize; x++) {
|
||||||
String baseUrl = captionsArray.getObject(x).getString("baseUrl");
|
String baseUrl = captionsArray.getObject(x).getString("baseUrl");
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,6 @@ public class SoundcloudStreamExtractorDefaultTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSubtitles() throws IOException, ExtractionException, JsonParserException {
|
public void testGetSubtitles() throws IOException, ExtractionException, JsonParserException {
|
||||||
assertTrue(extractor.getSubtitlesList() != null);
|
assertTrue(extractor.getSubtitles() != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,17 +153,7 @@ public class YoutubeStreamExtractorDefaultTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
||||||
assertTrue(extractor.getSubtitlesList() != null);
|
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||||
}
|
assertTrue(extractor.getSubtitles() != 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,11 +107,6 @@ public class YoutubeStreamExtractorRestrictedTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
public void testGetSubtitlesList() throws IOException, ExtractionException, JsonParserException {
|
||||||
assertTrue(extractor.getSubtitlesList() != null);
|
assertTrue(extractor.getSubtitles() != null);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDownloadSubtitles() throws Exception {
|
|
||||||
assertTrue(extractor.downloadSubtitles("https://youtu.be/FmG385_uUys?t=174") != null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue