Invidious is an alternative front-end to YouTube
Minor refactor
Omar Roth7b88d0efe3db
diff --git a/src/invidious.cr b/src/invidious.crindex 5d011a5c..5ab779de 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -3841,10 +3841,10 @@ get "/api/v1/captions/:id" do |env|env.response.content_type = "text/vtt; charset=UTF-8"- caption = captions.select { |caption| caption.name.simpleText == label }-if langcaption = captions.select { |caption| caption.languageCode == lang }+ else+ caption = captions.select { |caption| caption.name.simpleText == label }endif caption.empty?@@ -5155,7 +5155,7 @@ get "/api/manifest/dash/id/:id" do |env|# Since some implementations create playlists based on resolution regardless of different codecs,# we can opt to only add a source to a representation if it has a unique height within that representation- unique_res = env.params.query["unique_res"]? && (env.params.query["unique_res"] == "true" || env.params.query["unique_res"] == "1")+ unique_res = env.params.query["unique_res"]?.try { |q| (q == "true" || q == "1").to_unsafe }beginvideo = get_video(id, PG_DB, region: region)@@ -5167,7 +5167,7 @@ get "/api/manifest/dash/id/:id" do |env|endif dashmpd = video.player_response["streamingData"]?.try &.["dashManifestUrl"]?.try &.as_s- manifest = YT_POOL.client &.get(dashmpd).body+ manifest = YT_POOL.client &.get(URI.parse(dashmpd).full_path).bodymanifest = manifest.gsub(/<BaseURL>[^<]+<\/BaseURL>/) do |baseurl|url = baseurl.lchop("<BaseURL>")@@ -5192,7 +5192,7 @@ get "/api/manifest/dash/id/:id" do |env|endaudio_streams = video.audio_streams(adaptive_fmts)- video_streams = video.video_streams(adaptive_fmts).sort_by { |stream| stream["fps"].to_i }.reverse+ video_streams = video.video_streams(adaptive_fmts).sort_by { |stream| {stream["size"].split("x")[0].to_i, stream["fps"].to_i} }.reverseXML.build(indent: " ", encoding: "UTF-8") do |xml|xml.element("MPD", "xmlns": "urn:mpeg:dash:schema:mpd:2011",@@ -5230,9 +5230,7 @@ get "/api/manifest/dash/id/:id" do |env|{"video/mp4", "video/webm"}.each do |mime_type|mime_streams = video_streams.select { |stream| stream["type"].starts_with? mime_type }- if mime_streams.empty?- next- end+ next if mime_streams.empty?heights = [] of Int32xml.element("AdaptationSet", id: i, mimeType: mime_type, startWithSAP: 1, subsegmentAlignment: true, scanType: "progressive") dodiff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex e9aee092..1c7599f8 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -621,10 +621,7 @@ struct Videoif fmts = player_response["streamingData"]?.try &.["adaptiveFormats"]?fmts.as_a.each do |adaptive_fmt|- if !adaptive_fmt.as_h?- next- end-+ next if !adaptive_fmt.as_h?fmt = {} of String => Stringif init = adaptive_fmt["initRange"]?