Skip to content

Commit aa7de1e

Browse files
committed
fix: fallback other yt clients no url found for adaptive formats (#5262)
1 parent 5f1f8ff commit aa7de1e

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/invidious/videos/parser.cr

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,20 @@ def extract_video_info(video_id : String)
108108
params = parse_video_info(video_id, player_response)
109109
params["reason"] = JSON::Any.new(reason) if reason
110110

111-
new_player_response = nil
112-
113-
# Don't use Android test suite client if po_token is passed because po_token doesn't
114-
# work for Android test suite client.
115-
if reason.nil? && CONFIG.po_token.nil?
116-
# Fetch the video streams using an Android client in order to get the
117-
# decrypted URLs and maybe fix throttling issues (#2194). See the
118-
# following issue for an explanation about decrypted URLs:
119-
# https://github.com/TeamNewPipe/NewPipeExtractor/issues/562
120-
client_config.client_type = YoutubeAPI::ClientType::AndroidTestSuite
121-
new_player_response = try_fetch_streaming_data(video_id, client_config)
122-
end
123-
124-
# Replace player response and reset reason
125-
if !new_player_response.nil?
126-
# Preserve captions & storyboard data before replacement
127-
new_player_response["storyboards"] = player_response["storyboards"] if player_response["storyboards"]?
128-
new_player_response["captions"] = player_response["captions"] if player_response["captions"]?
129-
130-
player_response = new_player_response
131-
params.delete("reason")
111+
if player_response["streamingData"]? && player_response.dig?("streamingData", "adaptiveFormats", 0, "url").nil?
112+
LOGGER.warn("Missing URLs for adaptive formats, falling back to other YT clients.")
113+
players_fallback = [YoutubeAPI::ClientType::WebMobile, YoutubeAPI::ClientType::TvHtml5]
114+
players_fallback.each do |player_fallback|
115+
client_config.client_type = player_fallback
116+
player_fallback_response = try_fetch_streaming_data(video_id, client_config)
117+
if player_fallback_response && player_fallback_response["streamingData"]? &&
118+
player_fallback_response.dig?("streamingData", "adaptiveFormats", 0, "url")
119+
streaming_data = player_response["streamingData"].as_h
120+
streaming_data["adaptiveFormats"] = player_fallback_response["streamingData"]["adaptiveFormats"]
121+
player_response["streamingData"] = JSON::Any.new(streaming_data)
122+
break
123+
end
124+
end
132125
end
133126

134127
{"captions", "playabilityStatus", "playerConfig", "storyboards"}.each do |f|

0 commit comments

Comments
 (0)