Merge pull request #271 from mauriciocolli/improve-status-checking

[YouTube] Improve response status checks
This commit is contained in:
Tobias Groza 2020-03-01 15:30:53 +01:00 committed by GitHub
commit 6446abc6d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -623,7 +623,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
final JsonObject playabilityStatus = playerResponse.getObject("playabilityStatus", JsonUtils.DEFAULT_EMPTY); final JsonObject playabilityStatus = playerResponse.getObject("playabilityStatus", JsonUtils.DEFAULT_EMPTY);
final String status = playabilityStatus.getString("status"); final String status = playabilityStatus.getString("status");
if (status != null && status.toLowerCase().equals("error")) { // If status exist, and is not "OK", throw a ContentNotAvailableException with the reason.
if (status != null && !status.toLowerCase().equals("ok")) {
final String reason = playabilityStatus.getString("reason"); final String reason = playabilityStatus.getString("reason");
throw new ContentNotAvailableException("Got error: \"" + reason + "\""); throw new ContentNotAvailableException("Got error: \"" + reason + "\"");
} }

View File

@ -145,7 +145,7 @@ public class PeertubeStreamExtractorDefaultTest {
@Test @Test
public void testGetAgeLimit() throws ExtractionException, IOException { public void testGetAgeLimit() throws ExtractionException, IOException {
assertEquals(0, extractor.getAgeLimit()); assertEquals(0, extractor.getAgeLimit());
PeertubeStreamExtractor ageLimit = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.co.uk/videos/watch/6762bb04-cad5-407b-81ee-c18eac4715a7"); PeertubeStreamExtractor ageLimit = (PeertubeStreamExtractor) PeerTube.getStreamExtractor("https://peertube.co.uk/videos/watch/3c0da7fb-e4d9-442e-84e3-a8c47004ee28");
ageLimit.fetchPage(); ageLimit.fetchPage();
assertEquals(18, ageLimit.getAgeLimit()); assertEquals(18, ageLimit.getAgeLimit());
} }