@@ -881,11 +881,13 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
881881
882882 player_response = YoutubeAPI .player(video_id: video_id, params: " " , client_config: client_config)
883883
884- if player_response[" playabilityStatus" ]?.try & .[" status" ]?.try & .as_s != " OK"
885- reason = player_response[" playabilityStatus" ][" errorScreen" ]?.try & .[" playerErrorMessageRenderer" ]?.try & .[" subreason" ]?.try { |s |
886- s[" simpleText" ]?.try & .as_s || s[" runs" ].as_a.map { |r | r[" text" ] }.join(" " )
887- } || player_response[" playabilityStatus" ][" reason" ].as_s
884+ if player_response.dig?(" playabilityStatus" , " status" ).try & .as_s != " OK"
885+ subreason = player_response.dig?(" playabilityStatus" , " errorScreen" , " playerErrorMessageRenderer" , " subreason" )
886+ reason = subreason.try & .[]?(" simpleText" ).try & .as_s
887+ reason ||= subreason.try & .[](" runs" ).as_a.map(& .[](" text" )).join(" " )
888+ reason ||= player_response.dig(" playabilityStatus" , " reason" ).as_s
888889 params[" reason" ] = JSON ::Any .new(reason)
890+ return params
889891 end
890892
891893 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_
928930 raise BrokenTubeException .new(" twoColumnWatchNextResults" ) if ! main_results
929931
930932 primary_results = main_results.dig?(" results" , " results" , " contents" )
931- secondary_results = main_results
932- .dig?(" secondaryResults" , " secondaryResults" , " results" )
933933
934934 raise BrokenTubeException .new(" results" ) if ! primary_results
935- raise BrokenTubeException .new(" secondaryResults" ) if ! secondary_results
936935
937936 video_primary_renderer = primary_results
938937 .as_a.find(& .[" videoPrimaryInfoRenderer" ]?)
@@ -952,7 +951,9 @@ def extract_video_info(video_id : String, proxy_region : String? = nil, context_
952951 related = [] of JSON ::Any
953952
954953 # Parse "compactVideoRenderer" items (under secondary results)
955- secondary_results.as_a.each do |element |
954+ secondary_results = main_results
955+ .dig?(" secondaryResults" , " secondaryResults" , " results" )
956+ secondary_results.try & .as_a.each do |element |
956957 if item = element[" compactVideoRenderer" ]?
957958 related_video = parse_related_video(item)
958959 related << JSON ::Any .new(related_video) if related_video
@@ -1119,7 +1120,9 @@ def fetch_video(id, region)
11191120 info = embed_info if ! embed_info[" reason" ]?
11201121 end
11211122
1122- raise InfoException .new(info[" reason" ]?.try & .as_s || " " ) if ! info[" videoDetails" ]?
1123+ if reason = info[" reason" ]?
1124+ raise InfoException .new(reason.as_s || " " )
1125+ end
11231126
11241127 video = Video .new({
11251128 id: id,
0 commit comments