diff --git a/config/config.example.yml b/config/config.example.yml index 759b81e0..99362b91 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -210,6 +210,14 @@ http_proxy: # po_token: "" # visitor_data: "" +## +## Monitor config for tokens each 1 minute +## +## Accepted values: true, false +## Default: true +## +tokenmon_enabled : true + # ----------------------------- # Logging # ----------------------------- diff --git a/src/invidious.cr b/src/invidious.cr index f7155f44..fbbddbba 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -196,7 +196,9 @@ Invidious::Jobs.register Invidious::Jobs::NotificationJob.new(CONNECTION_CHANNEL Invidious::Jobs.register Invidious::Jobs::ClearExpiredItemsJob.new -Invidious::Jobs.register Invidious::Jobs::MonitorCfgTokensJob.new() +if CONFIG.tokenmon_enabled + Invidious::Jobs.register Invidious::Jobs::MonitorCfgTokensJob.new() +end Invidious::Jobs.register Invidious::Jobs::InstanceListRefreshJob.new diff --git a/src/invidious/config.cr b/src/invidious/config.cr index 45efc3ff..ead857ba 100644 --- a/src/invidious/config.cr +++ b/src/invidious/config.cr @@ -99,6 +99,7 @@ class Config property hmac_key : String = "" # Domain to be used for links to resources on the site where an absolute URL is required property domain : String? + property tokenmon_enabled : Bool = true # Subscribe to channels using PubSubHubbub (requires domain, hmac_key) property use_pubsub_feeds : Bool | Int32 = false property popular_enabled : Bool = true diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 1b640bc2..3570efbe 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -23,6 +23,9 @@ module YoutubeAPI private WINDOWS_VERSION = "10.0" + pot = "" + vdata = "" + # Enumerate used to select one of the clients supported by the API enum ClientType Web @@ -273,6 +276,17 @@ module YoutubeAPI # youtube API endpoints. # private def make_context(client_config : ClientConfig | Nil, video_id = "dQw4w9WgXcQ") : Hash + # determine po_token and visitor_data + if CONFIG.tokenmon_enabled + # get the pot/vdata for usage later + pot = ReloadTokens.pot.as(String) + vdata = ReloadTokens.vdata.as(String) + else + # Use the configured pot + pot = CONFIG.po_token.as(String) + vdata = CONFIG.visitor_data.as(String) + end + # Use the default client config if nil is passed client_config ||= DEFAULT_CLIENT_CONFIG @@ -320,8 +334,8 @@ module YoutubeAPI client_context["client"]["platform"] = platform end - if ReloadTokens.vdata.is_a?(String) - client_context["client"]["visitorData"] = ReloadTokens.vdata.as(String) + if vdata.is_a?(String) + client_context["client"]["visitorData"] = vdata end return client_context @@ -469,6 +483,17 @@ module YoutubeAPI end end + # determine po_token and visitor_data + if CONFIG.tokenmon_enabled + # get the pot/vdata for usage later + pot = ReloadTokens.pot.as(String) + vdata = ReloadTokens.vdata.as(String) + else + # Use the configured pot + pot = CONFIG.po_token.as(String) + vdata = CONFIG.visitor_data.as(String) + end + # JSON Request data, required by the API data = { "contentCheckOk" => true, @@ -482,7 +507,7 @@ module YoutubeAPI "contentPlaybackContext" => playback_ctx, }, "serviceIntegrityDimensions" => { - "poToken" => ReloadTokens.pot.as(String), + "poToken" => pot, }, } @@ -616,8 +641,19 @@ module YoutubeAPI headers["User-Agent"] = user_agent end - if ReloadTokens.vdata.is_a?(String) - headers["X-Goog-Visitor-Id"] = ReloadTokens.vdata.as(String) + # determine po_token and visitor_data + if CONFIG.tokenmon_enabled + # get the pot/vdata for usage later + pot = ReloadTokens.pot.as(String) + vdata = ReloadTokens.vdata.as(String) + else + # Use the configured pot + pot = CONFIG.po_token.as(String) + vdata = CONFIG.visitor_data.as(String) + end + + if vdata.is_a?(String) + headers["X-Goog-Visitor-Id"] = vdata end # Logging