Invidious is an alternative front-end to YouTube
Add additional handling for unplayable videos
Omar Rothcfb68e3bff72
diff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex 829b384b..4d662e9a 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -316,10 +316,10 @@ struct Videojson.field "premiereTimestamp", self.premiere_timestamp.not_nil!.to_unixend- if self.player_response["streamingData"]?.try &.["hlsManifestUrl"]?+ if player_response["streamingData"]?.try &.["hlsManifestUrl"]?host_url = make_host_url(config, kemal_config)- hlsvp = self.player_response["streamingData"]["hlsManifestUrl"].as_s+ hlsvp = player_response["streamingData"]["hlsManifestUrl"].as_shlsvp = hlsvp.gsub("https://manifest.googlevideo.com", host_url)json.field "hlsUrl", hlsvp@@ -489,7 +489,7 @@ struct Videoenddef live_now- live_now = self.player_response["videoDetails"]?.try &.["isLive"]?.try &.as_bool+ live_now = player_response["videoDetails"]?.try &.["isLive"]?.try &.as_boolif live_now.nil?return false@@ -536,7 +536,7 @@ struct Videoenddef keywords- keywords = self.player_response["videoDetails"]?.try &.["keywords"]?.try &.as_a+ keywords = player_response["videoDetails"]?.try &.["keywords"]?.try &.as_akeywords ||= [] of Stringreturn keywords@@ -545,7 +545,7 @@ struct Videodef fmt_stream(decrypt_function)streams = [] of HTTP::Params- if fmt_streams = self.player_response["streamingData"]?.try &.["formats"]?+ if fmt_streams = player_response["streamingData"]?.try &.["formats"]?fmt_streams.as_a.each do |fmt_stream|if !fmt_stream.as_h?next@@ -619,7 +619,7 @@ struct Videodef adaptive_fmts(decrypt_function)adaptive_fmts = [] of HTTP::Params- if fmts = self.player_response["streamingData"]?.try &.["adaptiveFormats"]?+ if fmts = player_response["streamingData"]?.try &.["adaptiveFormats"]?fmts.as_a.each do |adaptive_fmt|if !adaptive_fmt.as_h?next@@ -712,12 +712,12 @@ struct Videoenddef storyboards- storyboards = self.player_response["storyboards"]?+ storyboards = player_response["storyboards"]?.try &.as_h.try &.["playerStoryboardSpecRenderer"]?if !storyboards- storyboards = self.player_response["storyboards"]?+ storyboards = player_response["storyboards"]?.try &.as_h.try &.["playerLiveStoryboardSpecRenderer"]?@@ -784,13 +784,8 @@ struct Videoenddef paid- reason = self.player_response["playabilityStatus"]?.try &.["reason"]?-- if reason == "This video requires payment to watch."- paid = true- else- paid = false- end+ reason = player_response["playabilityStatus"]?.try &.["reason"]?+ paid = reason == "This video requires payment to watch." ? true : falsereturn paidend@@ -836,7 +831,7 @@ struct Videoenddef length_seconds- self.player_response["videoDetails"]["lengthSeconds"].as_s.to_i+ player_response["videoDetails"]["lengthSeconds"].as_s.to_ienddb_mapping({@@ -1210,6 +1205,11 @@ def fetch_video(id, region)player_json = JSON.parse(info["player_response"])+ reason = player_json["playabilityStatus"]?.try &.["reason"]?.try &.as_s+ if reason == "This video is not available."+ raise "This video is not available."+ end+title = player_json["videoDetails"]["title"].as_sauthor = player_json["videoDetails"]["author"]?.try &.as_s || ""ucid = player_json["videoDetails"]["channelId"]?.try &.as_s || ""