Skip to content

Commit

Permalink
remove ternary + use web client if po_token if not let android client
Browse files Browse the repository at this point in the history
  • Loading branch information
unixfox committed Jul 20, 2024
1 parent a24a3a6 commit 991c8dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/invidious/videos/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/invidious/yt_backend/youtube_api.cr
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ module YoutubeAPI
},
},
"serviceIntegrityDimensions" => {
"poToken" => CONFIG.po_token ? CONFIG.po_token.as(String) : nil,
"poToken" => CONFIG.po_token,
},
}

Expand Down

0 comments on commit 991c8dd

Please sign in to comment.