2
0
mirror of https://github.com/TeamNewPipe/NewPipeExtractor synced 2025-08-31 14:26:14 +00:00

[YouTube] Add ability to use the guide endpoint to get a visitorData

Some clients like TVHTML5 are not allowed on the visitor_id endpoint
(with this client, a 400 HTTP response is returned with a precondition
check failed error).

Also disable pretty printing for these requests, like we do for others.
This commit is contained in:
AudricV
2025-01-31 11:23:58 +01:00
committed by Stypox
parent 862a607fc6
commit d08331dbcf

View File

@@ -1502,7 +1502,8 @@ public final class YoutubeParsingHelper {
@Nonnull final ContentCountry contentCountry,
@Nonnull final Map<String, List<String>> httpHeaders,
@Nonnull final String innerTubeDomain,
@Nullable final String embedUrl) throws IOException, ExtractionException {
@Nullable final String embedUrl,
final boolean useGuideEndpoint) throws IOException, ExtractionException {
final JsonBuilder<JsonObject> builder = prepareJsonBuilder(
localization, contentCountry, innertubeClientRequestInfo, embedUrl);
@@ -1510,7 +1511,10 @@ public final class YoutubeParsingHelper {
.getBytes(StandardCharsets.UTF_8);
final String visitorData = JsonUtils.toJsonObject(getValidJsonResponseBody(getDownloader()
.postWithContentTypeJson(innerTubeDomain + "visitor_id", httpHeaders, body)))
.postWithContentTypeJson(
innerTubeDomain + (useGuideEndpoint ? "guide" : "visitor_id")
+ "?" + DISABLE_PRETTY_PRINT_PARAMETER,
httpHeaders, body)))
.getObject("responseContext")
.getString("visitorData");