Skip to content

Commit 98e3594

Browse files
mauriciocolliTobiGr
authored andcommitted
[YouTube] Detect simple 404s in the standard fetch method
1 parent 408f042 commit 98e3594

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeParsingHelper.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.jsoup.Jsoup;
99
import org.jsoup.nodes.Document;
1010
import org.schabi.newpipe.extractor.downloader.Response;
11+
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
1112
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1213
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1314
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
@@ -349,14 +350,20 @@ public static JsonArray getJsonResponse(String url, Localization localization) t
349350
Map<String, List<String>> headers = new HashMap<>();
350351
headers.put("X-YouTube-Client-Name", Collections.singletonList("1"));
351352
headers.put("X-YouTube-Client-Version", Collections.singletonList(getClientVersion()));
352-
final String response = getDownloader().get(url, headers, localization).responseBody();
353+
final Response response = getDownloader().get(url, headers, localization);
353354

354-
if (response.length() < 50) { // ensure to have a valid response
355+
if (response.responseCode() == 404) {
356+
throw new ContentNotAvailableException("Not found" +
357+
" (\"" + response.responseCode() + " " + response.responseMessage() + "\")");
358+
}
359+
360+
final String responseBody = response.responseBody();
361+
if (responseBody.length() < 50) { // ensure to have a valid response
355362
throw new ParsingException("JSON response is too short");
356363
}
357364

358365
try {
359-
return JsonParser.array().from(response);
366+
return JsonParser.array().from(responseBody);
360367
} catch (JsonParserException e) {
361368
throw new ParsingException("Could not parse JSON", e);
362369
}

0 commit comments

Comments
 (0)