|
9 | 9 | import org.schabi.newpipe.extractor.InfoItem; |
10 | 10 | import org.schabi.newpipe.extractor.StreamingService; |
11 | 11 | import org.schabi.newpipe.extractor.downloader.Downloader; |
12 | | -import org.schabi.newpipe.extractor.downloader.Response; |
13 | | -import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; |
14 | 12 | import org.schabi.newpipe.extractor.exceptions.ExtractionException; |
15 | 13 | import org.schabi.newpipe.extractor.exceptions.ParsingException; |
16 | 14 | import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; |
|
31 | 29 | import javax.annotation.Nonnull; |
32 | 30 |
|
33 | 31 | import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl; |
| 32 | +import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getValidResponseBody; |
34 | 33 | import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject; |
35 | 34 | import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getUrlFromNavigationEndpoint; |
36 | 35 | import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_ALBUMS; |
@@ -112,23 +111,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException |
112 | 111 | headers.put("Referer", Collections.singletonList("music.youtube.com")); |
113 | 112 | headers.put("Content-Type", Collections.singletonList("application/json")); |
114 | 113 |
|
115 | | - final Response response = getDownloader().post(url, headers, json); |
116 | | - |
117 | | - if (response.responseCode() == 404) { |
118 | | - throw new ContentNotAvailableException("Not found" + |
119 | | - " (\"" + response.responseCode() + " " + response.responseMessage() + "\")"); |
120 | | - } |
121 | | - |
122 | | - final String responseBody = response.responseBody(); |
123 | | - if (responseBody.length() < 50) { // ensure to have a valid response |
124 | | - throw new ParsingException("JSON response is too short"); |
125 | | - } |
126 | | - |
127 | | - final String responseContentType = response.getHeader("Content-Type"); |
128 | | - if (responseContentType != null && responseContentType.toLowerCase().contains("text/html")) { |
129 | | - throw new ParsingException("Got HTML document, expected JSON response" + |
130 | | - " (latest url was: \"" + response.latestUrl() + "\")"); |
131 | | - } |
| 114 | + final String responseBody = getValidResponseBody(getDownloader().post(url, headers, json)); |
132 | 115 |
|
133 | 116 | try { |
134 | 117 | initialData = JsonParser.object().from(responseBody); |
@@ -232,23 +215,7 @@ public InfoItemsPage<InfoItem> getPage(final String pageUrl) throws IOException, |
232 | 215 | headers.put("Referer", Collections.singletonList("music.youtube.com")); |
233 | 216 | headers.put("Content-Type", Collections.singletonList("application/json")); |
234 | 217 |
|
235 | | - final Response response = getDownloader().post(pageUrl, headers, json); |
236 | | - |
237 | | - if (response.responseCode() == 404) { |
238 | | - throw new ContentNotAvailableException("Not found" + |
239 | | - " (\"" + response.responseCode() + " " + response.responseMessage() + "\")"); |
240 | | - } |
241 | | - |
242 | | - final String responseBody = response.responseBody(); |
243 | | - if (responseBody.length() < 50) { // ensure to have a valid response |
244 | | - throw new ParsingException("JSON response is too short"); |
245 | | - } |
246 | | - |
247 | | - final String responseContentType = response.getHeader("Content-Type"); |
248 | | - if (responseContentType != null && responseContentType.toLowerCase().contains("text/html")) { |
249 | | - throw new ParsingException("Got HTML document, expected JSON response" + |
250 | | - " (latest url was: \"" + response.latestUrl() + "\")"); |
251 | | - } |
| 218 | + final String responseBody = getValidResponseBody(getDownloader().post(pageUrl, headers, json)); |
252 | 219 |
|
253 | 220 | final JsonObject ajaxJson; |
254 | 221 | try { |
|
0 commit comments