Skip to content

Commit d08331d

Browse files
AudricVStypox
authored andcommitted
[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.
1 parent 862a607 commit d08331d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,15 +1502,19 @@ public static String getVisitorDataFromInnertube(
15021502
@Nonnull final ContentCountry contentCountry,
15031503
@Nonnull final Map<String, List<String>> httpHeaders,
15041504
@Nonnull final String innerTubeDomain,
1505-
@Nullable final String embedUrl) throws IOException, ExtractionException {
1505+
@Nullable final String embedUrl,
1506+
final boolean useGuideEndpoint) throws IOException, ExtractionException {
15061507
final JsonBuilder<JsonObject> builder = prepareJsonBuilder(
15071508
localization, contentCountry, innertubeClientRequestInfo, embedUrl);
15081509

15091510
final byte[] body = JsonWriter.string(builder.done())
15101511
.getBytes(StandardCharsets.UTF_8);
15111512

15121513
final String visitorData = JsonUtils.toJsonObject(getValidJsonResponseBody(getDownloader()
1513-
.postWithContentTypeJson(innerTubeDomain + "visitor_id", httpHeaders, body)))
1514+
.postWithContentTypeJson(
1515+
innerTubeDomain + (useGuideEndpoint ? "guide" : "visitor_id")
1516+
+ "?" + DISABLE_PRETTY_PRINT_PARAMETER,
1517+
httpHeaders, body)))
15141518
.getObject("responseContext")
15151519
.getString("visitorData");
15161520

0 commit comments

Comments
 (0)