Skip to content

Commit 0308acb

Browse files
committed
Videos: Add fallback to TvSimply client (#5345)
2 parents cac2397 + d51e1cb commit 0308acb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/invidious/videos/parser.cr

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,17 @@ def extract_video_info(video_id : String)
111111
if !CONFIG.invidious_companion.present?
112112
if player_response.dig?("streamingData", "adaptiveFormats", 0, "url").nil?
113113
LOGGER.warn("Missing URLs for adaptive formats, falling back to other YT clients.")
114-
players_fallback = {YoutubeAPI::ClientType::TvHtml5, YoutubeAPI::ClientType::WebMobile}
114+
players_fallback = {YoutubeAPI::ClientType::TvSimply, YoutubeAPI::ClientType::WebMobile}
115115

116116
players_fallback.each do |player_fallback|
117117
client_config.client_type = player_fallback
118118

119119
next if !(player_fallback_response = try_fetch_streaming_data(video_id, client_config))
120120

121-
if player_fallback_response.dig?("streamingData", "adaptiveFormats", 0, "url")
121+
adaptive_formats = player_fallback_response.dig?("streamingData", "adaptiveFormats")
122+
if adaptive_formats && (adaptive_formats.dig?(0, "url") || adaptive_formats.dig?(0, "signatureCipher"))
122123
streaming_data = player_response["streamingData"].as_h
123-
streaming_data["adaptiveFormats"] = player_fallback_response["streamingData"]["adaptiveFormats"]
124+
streaming_data["adaptiveFormats"] = adaptive_formats
124125
player_response["streamingData"] = JSON::Any.new(streaming_data)
125126
break
126127
end
@@ -146,7 +147,11 @@ def extract_video_info(video_id : String)
146147
if streaming_data = player_response["streamingData"]?
147148
%w[formats adaptiveFormats].each do |key|
148149
streaming_data.as_h[key]?.try &.as_a.each do |format|
149-
format.as_h["url"] = JSON::Any.new(convert_url(format))
150+
format = format.as_h
151+
if format["url"]?.nil?
152+
format["url"] = format["signatureCipher"]
153+
end
154+
format["url"] = JSON::Any.new(convert_url(format))
150155
end
151156
end
152157

0 commit comments

Comments
 (0)