From 62d64ca814ec494ac2cfa3d434ae9e2c8c9b6635 Mon Sep 17 00:00:00 2001 From: Fijxu Date: Fri, 11 Oct 2024 16:50:21 -0300 Subject: [PATCH] fixup! Feat: User supplied po_token and visitor_data --- src/invidious.cr | 10 +++++----- src/invidious/helpers/utils.cr | 2 +- src/invidious/videos.cr | 2 +- src/invidious/yt_backend/youtube_api.cr | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index fa65f2dd..c3e6ee7a 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -67,11 +67,11 @@ REDIS_DB = Redis::PooledClient.new(unixsocket: CONFIG.redis_socket || nil, url: if REDIS_DB.ping puts "Connected to redis" end -ARCHIVE_URL = URI.parse("https://archive.org") -PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com") -REDDIT_URL = URI.parse("https://www.reddit.com") -YT_URL = URI.parse("https://www.youtube.com") -HOST_URL = make_host_url(Kemal.config) +ARCHIVE_URL = URI.parse("https://archive.org") +PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com") +REDDIT_URL = URI.parse("https://www.reddit.com") +YT_URL = URI.parse("https://www.youtube.com") +HOST_URL = make_host_url(Kemal.config) EXT_VIDEOP_LIST = gen_videoplayback_proxy_list() CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 3e4764c4..d98c933b 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -384,7 +384,7 @@ def parse_link_endpoint(endpoint : JSON::Any, text : String, video_id : String) return text end -# Generates a list of external videoplayback proxies for +# Generates a list of external videoplayback proxies for # CSP def gen_videoplayback_proxy_list if !CONFIG.external_videoplayback_proxy.empty? diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index f1b46bf8..7e817928 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -294,7 +294,7 @@ struct Video predicate_bool upcoming, isUpcoming end -def get_video(id, refresh = true, region = nil, force_refresh = false, po_token = "", visitor_data = nil) +def get_video(id, refresh = true, region = nil, force_refresh = false, po_token = "", visitor_data = "") if (video = Invidious::Database::Videos.select(id)) && !region # If record was last updated over 10 minutes ago, or video has since premiered, # refresh (expire param in response lasts for 6 hours) diff --git a/src/invidious/yt_backend/youtube_api.cr b/src/invidious/yt_backend/youtube_api.cr index 8602cc2d..564976c3 100644 --- a/src/invidious/yt_backend/youtube_api.cr +++ b/src/invidious/yt_backend/youtube_api.cr @@ -3,6 +3,8 @@ # module YoutubeAPI + @@visitor_data : String = "" + extend self # For Android versions, see https://en.wikipedia.org/wiki/Android_version_history @@ -198,8 +200,6 @@ module YoutubeAPI # (this is passed as the `gl` parameter). property region : String | Nil - @@visitor_data : String | Nil - # Initialization function def initialize( *, @@ -322,8 +322,8 @@ module YoutubeAPI client_context["client"]["platform"] = platform end - if !@@visitor_data.not_nil!.empty? - client_context["client"]["visitorData"] = @@visitor_data.not_nil! + if !@@visitor_data.empty? + client_context["client"]["visitorData"] = @@visitor_data elsif CONFIG.visitor_data.is_a?(String) client_context["client"]["visitorData"] = CONFIG.visitor_data.as(String) end @@ -461,7 +461,7 @@ module YoutubeAPI params : String, client_config : ClientConfig | Nil = nil, po_token : String, - visitor_data : String | Nil + visitor_data : String ) if visitor_data @@visitor_data = visitor_data @@ -625,8 +625,8 @@ module YoutubeAPI headers["User-Agent"] = user_agent end - if !@@visitor_data.not_nil!.empty? - headers["X-Goog-Visitor-Id"] = @@visitor_data.not_nil! + if !@@visitor_data.empty? + headers["X-Goog-Visitor-Id"] = @@visitor_data elsif CONFIG.visitor_data.is_a?(String) headers["X-Goog-Visitor-Id"] = CONFIG.visitor_data.as(String) end