Feat: Experimental support for potoken inside redis
All checks were successful
Invidious CI / build (push) Successful in 4m54s

Using https://git.nadeko.net/Fijxu/youtube-po-token-generator
This commit is contained in:
Fijxu 2024-10-12 02:04:14 -03:00
parent 62d64ca814
commit fc0a3ab307
Signed by: Fijxu
GPG key ID: 32C1DDF333EDA6A4
4 changed files with 21 additions and 7 deletions

View file

@ -397,3 +397,11 @@ def gen_videoplayback_proxy_list
end
return external_videoplayback_proxy
end
def get_po_token
REDIS_DB.get("invidious:po_token")
end
def get_visitor_data
REDIS_DB.get("invidious:visitor_data")
end

View file

@ -324,7 +324,7 @@ rescue DB::Error
end
def fetch_video(id, region, po_token, visitor_data)
info = extract_video_info(video_id: id, po_token: po_token, visitor_data: visitor_data)
info = extract_video_info(video_id: id, user_po_token: po_token, user_visitor_data: visitor_data)
if reason = info["reason"]?
if reason == "Video unavailable"

View file

@ -50,10 +50,16 @@ def parse_related_video(related : JSON::Any) : Hash(String, JSON::Any)?
}
end
def extract_video_info(video_id : String, po_token, visitor_data)
def extract_video_info(video_id : String, user_po_token, user_visitor_data)
# Init client config for the API
client_config = YoutubeAPI::ClientConfig.new
redis_po_token = get_po_token()
redis_visitor_data = get_visitor_data()
po_token = (user_po_token if !user_po_token.empty?) || redis_po_token || CONFIG.po_token
visitor_data = (user_visitor_data if !user_visitor_data.empty?) || redis_visitor_data || CONFIG.visitor_data
# Fetch data from the player endpoint
player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config, po_token: po_token, visitor_data: visitor_data)
@ -104,7 +110,7 @@ def extract_video_info(video_id : String, po_token, visitor_data)
# Don't use Android client if po_token is passed because po_token doesn't
# work for Android client.
if reason.nil? && CONFIG.po_token.nil?
if reason.nil? && po_token.nil?
# Fetch the video streams using an Android client in order to get the
# decrypted URLs and maybe fix throttling issues (#2194). See the
# following issue for an explanation about decrypted URLs:
@ -117,7 +123,7 @@ def extract_video_info(video_id : String, po_token, visitor_data)
# Only trigger if reason found and po_token or didn't work wth Android client.
# TvHtml5ScreenEmbed now requires sig helper for it to work but po_token is not required
# if the IP address is not blocked.
if CONFIG.po_token && reason || CONFIG.po_token.nil? && new_player_response.nil?
if po_token.nil? && reason || po_token.nil? && new_player_response.nil?
client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed
new_player_response = try_fetch_streaming_data(video_id, client_config, po_token, visitor_data)
end
@ -473,7 +479,7 @@ private def convert_url(fmt, po_token)
n = DECRYPT_FUNCTION.try &.decrypt_nsig(params["n"])
params["n"] = n if n
if !po_token.empty?
if !po_token.nil?
params["pot"] = po_token
elsif token = CONFIG.po_token
params["pot"] = token

View file

@ -460,8 +460,8 @@ module YoutubeAPI
*, # Force the following parameters to be passed by name
params : String,
client_config : ClientConfig | Nil = nil,
po_token : String,
visitor_data : String
po_token : String | Nil,
visitor_data : String | Nil,
)
if visitor_data
@@visitor_data = visitor_data