|
8 | 8 | import org.jsoup.Jsoup; |
9 | 9 | import org.jsoup.nodes.Document; |
10 | 10 | import org.schabi.newpipe.extractor.downloader.Response; |
| 11 | +import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; |
11 | 12 | import org.schabi.newpipe.extractor.exceptions.ExtractionException; |
12 | 13 | import org.schabi.newpipe.extractor.exceptions.ParsingException; |
13 | 14 | import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; |
@@ -349,14 +350,20 @@ public static JsonArray getJsonResponse(String url, Localization localization) t |
349 | 350 | Map<String, List<String>> headers = new HashMap<>(); |
350 | 351 | headers.put("X-YouTube-Client-Name", Collections.singletonList("1")); |
351 | 352 | 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); |
353 | 354 |
|
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 |
355 | 362 | throw new ParsingException("JSON response is too short"); |
356 | 363 | } |
357 | 364 |
|
358 | 365 | try { |
359 | | - return JsonParser.array().from(response); |
| 366 | + return JsonParser.array().from(responseBody); |
360 | 367 | } catch (JsonParserException e) { |
361 | 368 | throw new ParsingException("Could not parse JSON", e); |
362 | 369 | } |
|
0 commit comments