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 GitHub
parent d567c6be6e
commit 7579adc3a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -109,27 +109,20 @@ def extract_video_info(video_id : String)
params["reason"] = JSON::Any.new(reason) if reason params["reason"] = JSON::Any.new(reason) if reason
if !CONFIG.invidious_companion.present? if !CONFIG.invidious_companion.present?
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)
end break
end
# Replace player response and reset reason end
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
end end