Add ability to set po_token and visitordata ID

This commit is contained in:
Emilien Devos 2024-07-11 23:19:20 +02:00
parent 1ae14cc224
commit 9e11d59af4
3 changed files with 26 additions and 0 deletions

View File

@ -173,6 +173,16 @@ https_only: false
##
# use_innertube_for_captions: false
##
## Send Google session informations. This gives more identifiable information to Google.
##
## Useful when Invidious is blocked by the message "This helps protect our community." See https://github.com/iv-org/invidious/issues/4734
##
## Accepted values: true, false
## Default: false
##
# po_token: XXX
# visitor_data: XXX
# -----------------------------
# Logging

View File

@ -130,6 +130,11 @@ class Config
# Use Innertube's transcripts API instead of timedtext for closed captions
property use_innertube_for_captions : Bool = false
# visitor data ID for Google session
property visitor_data : String? = nil
# poToken for passing bot attestation
property po_token : String? = nil
# Saved cookies in "name1=value1; name2=value2..." format
@[YAML::Field(converter: Preferences::StringToCookies)]
property cookies : HTTP::Cookies = HTTP::Cookies.new

View File

@ -341,6 +341,10 @@ module YoutubeAPI
client_context["client"]["platform"] = platform
end
if CONFIG.visitor_data.is_a?(String)
client_context["client"]["visitorData"] = CONFIG.visitor_data.as(String)
end
return client_context
end
@ -488,6 +492,9 @@ module YoutubeAPI
"html5Preference": "HTML5_PREF_WANTS",
},
},
"serviceIntegrityDimensions" => {
"poToken" => CONFIG.po_token ? CONFIG.po_token.as(String) : nil,
},
}
# Append the additional parameters if those were provided
@ -620,6 +627,10 @@ module YoutubeAPI
headers["User-Agent"] = user_agent
end
if CONFIG.visitor_data.is_a?(String)
headers["X-Goog-Visitor-Id"] = CONFIG.visitor_data.as(String)
end
# Logging
LOGGER.debug("YoutubeAPI: Using endpoint: \"#{endpoint}\"")
LOGGER.trace("YoutubeAPI: ClientConfig: #{client_config}")