remove ternary + use web client if po_token if not let android client

This commit is contained in:
Emilien Devos 2024-07-20 13:24:01 +02:00
parent a24a3a608e
commit 991c8ddfdb
2 changed files with 9 additions and 4 deletions

View File

@ -55,7 +55,7 @@ def extract_video_info(video_id : String)
client_config = YoutubeAPI::ClientConfig.new
# Fetch data from the player endpoint
player_response = YoutubeAPI.player(video_id: video_id, params: "", client_config: client_config)
player_response = YoutubeAPI.player(video_id: video_id, params: "2AMB", client_config: client_config)
playability_status = player_response.dig?("playabilityStatus", "status").try &.as_s
@ -102,7 +102,9 @@ def extract_video_info(video_id : String)
new_player_response = nil
if reason.nil?
# 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?
# 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:
@ -112,7 +114,10 @@ def extract_video_info(video_id : String)
end
# Last hope
if new_player_response.nil?
# 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?
client_config.client_type = YoutubeAPI::ClientType::TvHtml5ScreenEmbed
new_player_response = try_fetch_streaming_data(video_id, client_config)
end

View File

@ -493,7 +493,7 @@ module YoutubeAPI
},
},
"serviceIntegrityDimensions" => {
"poToken" => CONFIG.po_token ? CONFIG.po_token.as(String) : nil,
"poToken" => CONFIG.po_token,
},
}