summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-02-14 00:59:07 +0100
committerGitHub <noreply@github.com>2022-02-14 00:59:07 +0100
commit8af202e86b4d92f2411fe490986acba2b43be367 (patch)
tree4c31a9d86c6e982145fc68b9a774e4dca239884e
parent6c116e34c4a04bb5560d26e2601e91ce98af3273 (diff)
parentddf1e84f7c088051a20461f5c0b7fef069089c74 (diff)
downloadinvidious-8af202e86b4d92f2411fe490986acba2b43be367.tar.gz
invidious-8af202e86b4d92f2411fe490986acba2b43be367.tar.bz2
invidious-8af202e86b4d92f2411fe490986acba2b43be367.zip
Merge pull request #2892 from matthewmcgarvey/video-playability
Raise error if video not playable, also handle missing related videos
-rw-r--r--src/invidious/videos.cr21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index 335f6b60..81fce5b8 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -881,11 +881,13 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
player_response = YoutubeAPI.player(video_id: video_id, params: "", client_config: client_config)
- if player_response["playabilityStatus"]?.try &.["status"]?.try &.as_s != "OK"
- reason = player_response["playabilityStatus"]["errorScreen"]?.try &.["playerErrorMessageRenderer"]?.try &.["subreason"]?.try { |s|
- s["simpleText"]?.try &.as_s || s["runs"].as_a.map { |r| r["text"] }.join("")
- } || player_response["playabilityStatus"]["reason"].as_s
+ if player_response.dig?("playabilityStatus", "status").try &.as_s != "OK"
+ subreason = player_response.dig?("playabilityStatus", "errorScreen", "playerErrorMessageRenderer", "subreason")
+ reason = subreason.try &.[]?("simpleText").try &.as_s
+ reason ||= subreason.try &.[]("runs").as_a.map(&.[]("text")).join("")
+ reason ||= player_response.dig("playabilityStatus", "reason").as_s
params["reason"] = JSON::Any.new(reason)
+ return params
end
params["shortDescription"] = player_response.dig?("videoDetails", "shortDescription") || JSON::Any.new(nil)
@@ -928,11 +930,8 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
raise BrokenTubeException.new("twoColumnWatchNextResults") if !main_results
primary_results = main_results.dig?("results", "results", "contents")
- secondary_results = main_results
- .dig?("secondaryResults", "secondaryResults", "results")
raise BrokenTubeException.new("results") if !primary_results
- raise BrokenTubeException.new("secondaryResults") if !secondary_results
video_primary_renderer = primary_results
.as_a.find(&.["videoPrimaryInfoRenderer"]?)
@@ -952,7 +951,9 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
related = [] of JSON::Any
# Parse "compactVideoRenderer" items (under secondary results)
- secondary_results.as_a.each do |element|
+ secondary_results = main_results
+ .dig?("secondaryResults", "secondaryResults", "results")
+ secondary_results.try &.as_a.each do |element|
if item = element["compactVideoRenderer"]?
related_video = parse_related_video(item)
related << JSON::Any.new(related_video) if related_video
@@ -1119,7 +1120,9 @@ def fetch_video(id, region)
info = embed_info if !embed_info["reason"]?
end
- raise InfoException.new(info["reason"]?.try &.as_s || "") if !info["videoDetails"]?
+ if reason = info["reason"]?
+ raise InfoException.new(reason.as_s || "")
+ end
video = Video.new({
id: id,
a6c9a0f6fa9c14e3c18922e772dae26bf&follow=1'>Update Serbian translationHosted Weblate Co-authored-by: NEXI <nexiphotographer@gmail.com> 2023-10-07Update French translationHosted Weblate Update French translation Update French translation Co-authored-by: Samantaz Fox <translator-weblate@samantaz.fr> 2023-10-07Update Spanish translationHosted Weblate Update Spanish translation Co-authored-by: Jorge Maldonado Ventura <jorgesumle@freakspot.net> Co-authored-by: gallegonovato <fran-carro@hotmail.es> 2023-10-07Update Indonesian translationHosted Weblate Co-authored-by: Reza Almanda <rezaalmanda27@gmail.com> 2023-10-07Update Arabic translationHosted Weblate Co-authored-by: Rex_sa <rex.sa@pm.me> 2023-10-07Update Italian translationHosted Weblate Co-authored-by: Random <random-r@users.noreply.hosted.weblate.org> 2023-10-07Update Polish translationHosted Weblate Co-authored-by: Matthaiks <kitynska@gmail.com> 2023-10-07Update Croatian translationHosted Weblate Co-authored-by: Milo Ivir <mail@milotype.de> 2023-10-07Update Czech translationHosted Weblate Co-authored-by: Fjuro <ifjuro@proton.me> 2023-10-07Update Catalan translationHosted Weblate Co-authored-by: victor dargallo <victordargallo@disroot.org> 2023-10-07Update Japanese translationHosted Weblate Co-authored-by: maboroshin <maboroshin@users.noreply.hosted.weblate.org> 2023-10-07Update Ukrainian translationHosted Weblate Co-authored-by: Ihor Hordiichuk <igor_ck@outlook.com>