Use Downloader's postWithContentType and postWithContentTypeJson methods in services and extractors
This commit is contained in:
parent
b2862f3cd1
commit
3891542ca1
|
@ -61,10 +61,9 @@ public final class BandcampExtractorHelper {
|
|||
*/
|
||||
public static JsonObject getArtistDetails(final String id) throws ParsingException {
|
||||
try {
|
||||
return JsonParser.object().from(NewPipe.getDownloader().post(
|
||||
return JsonParser.object().from(NewPipe.getDownloader().postWithContentTypeJson(
|
||||
BASE_API_URL + "/mobile/22/band_details",
|
||||
Collections.singletonMap("Content-Type",
|
||||
Collections.singletonList("application/json")),
|
||||
Collections.emptyMap(),
|
||||
JsonWriter.string()
|
||||
.object()
|
||||
.value("band_id", id)
|
||||
|
|
|
@ -42,10 +42,9 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
|
|||
public void onFetchPage(@Nonnull final Downloader downloader)
|
||||
throws IOException, ExtractionException {
|
||||
try {
|
||||
json = JsonParser.object().from(getDownloader().post(
|
||||
json = JsonParser.object().from(getDownloader().postWithContentTypeJson(
|
||||
FEATURED_API_URL,
|
||||
Collections.singletonMap("Content-Type",
|
||||
Collections.singletonList("application/json")),
|
||||
Collections.emptyMap(),
|
||||
"{\"platform\":\"\",\"version\":0}".getBytes(StandardCharsets.UTF_8))
|
||||
.responseBody());
|
||||
} catch (final JsonParserException e) {
|
||||
|
|
|
@ -556,14 +556,13 @@ public final class YoutubeParsingHelper {
|
|||
|
||||
final Map<String, List<String>> headers = new HashMap<>();
|
||||
headers.put("X-YouTube-Client-Name", singletonList("1"));
|
||||
headers.put("X-YouTube-Client-Version",
|
||||
singletonList(HARDCODED_CLIENT_VERSION));
|
||||
headers.put("Content-Type", Collections.singletonList("application/json"));
|
||||
headers.put("X-YouTube-Client-Version", singletonList(HARDCODED_CLIENT_VERSION));
|
||||
|
||||
// This endpoint is fetched by the YouTube website to get the items of its main menu and is
|
||||
// pretty lightweight (around 30kB)
|
||||
final Response response = getDownloader().post(YOUTUBEI_V1_URL + "guide?key="
|
||||
+ HARDCODED_KEY + DISABLE_PRETTY_PRINT_PARAMETER, headers, body);
|
||||
final Response response = getDownloader().postWithContentTypeJson(
|
||||
YOUTUBEI_V1_URL + "guide?key=" + HARDCODED_KEY + DISABLE_PRETTY_PRINT_PARAMETER,
|
||||
headers, body);
|
||||
final String responseBody = response.responseBody();
|
||||
final int responseCode = response.responseCode();
|
||||
|
||||
|
@ -801,15 +800,12 @@ public final class YoutubeParsingHelper {
|
|||
// @formatter:on
|
||||
|
||||
final Map<String, List<String>> headers = new HashMap<>();
|
||||
headers.put("X-YouTube-Client-Name", singletonList(
|
||||
HARDCODED_YOUTUBE_MUSIC_KEY[1]));
|
||||
headers.put("X-YouTube-Client-Version", singletonList(
|
||||
HARDCODED_YOUTUBE_MUSIC_KEY[2]));
|
||||
headers.put("X-YouTube-Client-Name", singletonList(HARDCODED_YOUTUBE_MUSIC_KEY[1]));
|
||||
headers.put("X-YouTube-Client-Version", singletonList(HARDCODED_YOUTUBE_MUSIC_KEY[2]));
|
||||
headers.put("Origin", singletonList("https://music.youtube.com"));
|
||||
headers.put("Referer", singletonList("https://music.youtube.com"));
|
||||
headers.put("Content-Type", singletonList("application/json"));
|
||||
|
||||
final Response response = getDownloader().post(url, headers, json);
|
||||
final Response response = getDownloader().postWithContentTypeJson(url, headers, json);
|
||||
// Ensure to have a valid response
|
||||
return response.responseBody().length() > 500 && response.responseCode() == 200;
|
||||
}
|
||||
|
@ -1150,11 +1146,10 @@ public final class YoutubeParsingHelper {
|
|||
throws IOException, ExtractionException {
|
||||
final Map<String, List<String>> headers = new HashMap<>();
|
||||
addYouTubeHeaders(headers);
|
||||
headers.put("Content-Type", singletonList("application/json"));
|
||||
|
||||
return JsonUtils.toJsonObject(getValidJsonResponseBody(
|
||||
getDownloader().post(YOUTUBEI_V1_URL + endpoint + "?key=" + getKey()
|
||||
+ DISABLE_PRETTY_PRINT_PARAMETER, headers, body, localization)));
|
||||
getDownloader().postWithContentTypeJson(YOUTUBEI_V1_URL + endpoint + "?key="
|
||||
+ getKey() + DISABLE_PRETTY_PRINT_PARAMETER, headers, body, localization)));
|
||||
}
|
||||
|
||||
public static JsonObject getJsonAndroidPostResponse(
|
||||
|
@ -1185,13 +1180,12 @@ public final class YoutubeParsingHelper {
|
|||
final Map<String, List<String>> headers = new HashMap<>();
|
||||
headers.put("User-Agent", singletonList(userAgent));
|
||||
headers.put("X-Goog-Api-Format-Version", singletonList("2"));
|
||||
headers.put("Content-Type", singletonList("application/json"));
|
||||
|
||||
final String baseEndpointUrl = YOUTUBEI_V1_GAPIS_URL + endpoint + "?key=" + innerTubeApiKey
|
||||
+ DISABLE_PRETTY_PRINT_PARAMETER;
|
||||
|
||||
return JsonUtils.toJsonObject(getValidJsonResponseBody(
|
||||
getDownloader().post(isNullOrEmpty(endPartOfUrlRequest)
|
||||
getDownloader().postWithContentTypeJson(isNullOrEmpty(endPartOfUrlRequest)
|
||||
? baseEndpointUrl
|
||||
: baseEndpointUrl + endPartOfUrlRequest,
|
||||
headers, body, localization)));
|
||||
|
@ -1404,7 +1398,6 @@ public final class YoutubeParsingHelper {
|
|||
headers.put("X-YouTube-Client-Version", Collections.singletonList(youtubeMusicKey[2]));
|
||||
headers.put("Origin", Collections.singletonList("https://music.youtube.com"));
|
||||
headers.put("Referer", Collections.singletonList("https://music.youtube.com"));
|
||||
headers.put("Content-Type", Collections.singletonList("application/json"));
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
|
|||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -92,10 +91,10 @@ public class YoutubeMixPlaylistExtractor extends PlaylistExtractor {
|
|||
final Map<String, List<String>> headers = new HashMap<>();
|
||||
// Cookie is required due to consent
|
||||
addYouTubeHeaders(headers);
|
||||
headers.put("Content-Type", Collections.singletonList("application/json"));
|
||||
|
||||
final Response response = getDownloader().post(YOUTUBEI_V1_URL + "next?key=" + getKey()
|
||||
+ DISABLE_PRETTY_PRINT_PARAMETER, headers, body, localization);
|
||||
final Response response = getDownloader().postWithContentTypeJson(
|
||||
YOUTUBEI_V1_URL + "next?key=" + getKey() + DISABLE_PRETTY_PRINT_PARAMETER,
|
||||
headers, body, localization);
|
||||
|
||||
initialData = JsonUtils.toJsonObject(getValidJsonResponseBody(response));
|
||||
playlistData = initialData
|
||||
|
@ -226,10 +225,9 @@ public class YoutubeMixPlaylistExtractor extends PlaylistExtractor {
|
|||
final Map<String, List<String>> headers = new HashMap<>();
|
||||
// Cookie is required due to consent
|
||||
addYouTubeHeaders(headers);
|
||||
headers.put("Content-Type", Collections.singletonList("application/json"));
|
||||
|
||||
final Response response = getDownloader().post(page.getUrl(), headers, page.getBody(),
|
||||
getExtractorLocalization());
|
||||
final Response response = getDownloader().postWithContentTypeJson(page.getUrl(), headers,
|
||||
page.getBody(), getExtractorLocalization());
|
||||
final JsonObject ajaxJson = JsonUtils.toJsonObject(getValidJsonResponseBody(response));
|
||||
final JsonObject playlistJson = ajaxJson.getObject("contents")
|
||||
.getObject("twoColumnWatchNextResults").getObject("playlist").getObject("playlist");
|
||||
|
|
|
@ -115,8 +115,8 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||
.end().done().getBytes(StandardCharsets.UTF_8);
|
||||
// @formatter:on
|
||||
|
||||
final String responseBody = getValidJsonResponseBody(getDownloader().post(url,
|
||||
getYoutubeMusicHeaders(), json));
|
||||
final String responseBody = getValidJsonResponseBody(
|
||||
getDownloader().postWithContentTypeJson(url, getYoutubeMusicHeaders(), json));
|
||||
|
||||
try {
|
||||
initialData = JsonParser.object().from(responseBody);
|
||||
|
@ -243,8 +243,9 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
|||
.end().done().getBytes(StandardCharsets.UTF_8);
|
||||
// @formatter:on
|
||||
|
||||
final String responseBody = getValidJsonResponseBody(getDownloader().post(page.getUrl(),
|
||||
getYoutubeMusicHeaders(), json));
|
||||
final String responseBody = getValidJsonResponseBody(
|
||||
getDownloader().postWithContentTypeJson(
|
||||
page.getUrl(), getYoutubeMusicHeaders(), json));
|
||||
|
||||
final JsonObject ajaxJson;
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue