fix: fallback other yt clients no url found for adaptive formats (#5262)

This commit is contained in:
Émilien (perso) 2025-05-02 14:57:02 +00:00 committed by Emilien
parent 5f1f8ff4b1
commit aa7de1ed4c

View File

@ -108,27 +108,20 @@ def extract_video_info(video_id : String)
params = parse_video_info(video_id, player_response) params = parse_video_info(video_id, player_response)
params["reason"] = JSON::Any.new(reason) if reason params["reason"] = JSON::Any.new(reason) if reason
new_player_response = nil if player_response["streamingData"]? && player_response.dig?("streamingData", "adaptiveFormats", 0, "url").nil?
LOGGER.warn("Missing URLs for adaptive formats, falling back to other YT clients.")
# Don't use Android test suite client if po_token is passed because po_token doesn't players_fallback = [YoutubeAPI::ClientType::WebMobile, YoutubeAPI::ClientType::TvHtml5]
# work for Android test suite client. players_fallback.each do |player_fallback|
if reason.nil? && CONFIG.po_token.nil? client_config.client_type = player_fallback
# Fetch the video streams using an Android client in order to get the player_fallback_response = try_fetch_streaming_data(video_id, client_config)
# decrypted URLs and maybe fix throttling issues (#2194). See the if player_fallback_response && player_fallback_response["streamingData"]? &&
# following issue for an explanation about decrypted URLs: player_fallback_response.dig?("streamingData", "adaptiveFormats", 0, "url")
# https://github.com/TeamNewPipe/NewPipeExtractor/issues/562 streaming_data = player_response["streamingData"].as_h
client_config.client_type = YoutubeAPI::ClientType::AndroidTestSuite streaming_data["adaptiveFormats"] = player_fallback_response["streamingData"]["adaptiveFormats"]
new_player_response = try_fetch_streaming_data(video_id, client_config) player_response["streamingData"] = JSON::Any.new(streaming_data)
break
end
end end
# Replace player response and reset reason
if !new_player_response.nil?
# Preserve captions & storyboard data before replacement
new_player_response["storyboards"] = player_response["storyboards"] if player_response["storyboards"]?
new_player_response["captions"] = player_response["captions"] if player_response["captions"]?
player_response = new_player_response
params.delete("reason")
end end
{"captions", "playabilityStatus", "playerConfig", "storyboards"}.each do |f| {"captions", "playabilityStatus", "playerConfig", "storyboards"}.each do |f|