From 9e11d59af407c9666d53a78706e2a5f031c4315e Mon Sep 17 00:00:00 2001 From: Emilien Devos <4016501+unixfox@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:19:20 +0200 Subject: [PATCH] Add ability to set po_token and visitordata ID --- config/config.example.yml | 10 ++++++++++ src/invidious/config.cr | 5 +++++ src/invidious/yt_backend/youtube_api.cr | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/config/config.example.yml b/config/config.example.yml index 38085a20..41a57e00 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -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 diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 09c2168b..5340d4f5 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -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 diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 727ce9a3..f8470e8a 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -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}")