diff options
Diffstat (limited to 'src/invidious.cr')
| -rw-r--r-- | src/invidious.cr | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index 5d011a5c..f5fe4b3d 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -207,7 +207,7 @@ spawn do end end -decrypt_function = [] of {name: String, value: Int32} +decrypt_function = [] of {SigProc, Int32} spawn do update_decrypt_function do |function| decrypt_function = function @@ -2602,13 +2602,9 @@ post "/data_control" do |env| next match["channel"] elsif match = channel["url"].as_s.match(/\/user\/(?<user>.+)/) response = YT_POOL.client &.get("/user/#{match["user"]}?disable_polymer=1&hl=en&gl=US") - document = XML.parse_html(response.body) - canonical = document.xpath_node(%q(//link[@rel="canonical"])) - - if canonical - ucid = canonical["href"].split("/")[-1] - next ucid - end + html = XML.parse_html(response.body) + ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1] + next ucid if ucid end nil @@ -3841,10 +3837,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 lang caption = captions.select { |caption| caption.languageCode == lang } + else + caption = captions.select { |caption| caption.name.simpleText == label } end if caption.empty? @@ -5155,7 +5151,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 } begin video = get_video(id, PG_DB, region: region) @@ -5167,7 +5163,7 @@ get "/api/manifest/dash/id/:id" do |env| end if 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).body manifest = manifest.gsub(/<BaseURL>[^<]+<\/BaseURL>/) do |baseurl| url = baseurl.lchop("<BaseURL>") @@ -5192,7 +5188,7 @@ get "/api/manifest/dash/id/:id" do |env| end audio_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} }.reverse XML.build(indent: " ", encoding: "UTF-8") do |xml| xml.element("MPD", "xmlns": "urn:mpeg:dash:schema:mpd:2011", @@ -5230,9 +5226,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 Int32 xml.element("AdaptationSet", id: i, mimeType: mime_type, startWithSAP: 1, subsegmentAlignment: true, scanType: "progressive") do @@ -5875,7 +5869,7 @@ error 404 do |env| response = YT_POOL.client &.get("/#{item}") if response.status_code == 301 - response = YT_POOL.client &.get(response.headers["Location"]) + response = YT_POOL.client &.get(URI.parse(response.headers["Location"]).full_path) end if response.body.empty? @@ -5884,10 +5878,10 @@ error 404 do |env| end html = XML.parse_html(response.body) - ucid = html.xpath_node(%q(//meta[@itemprop="channelId"])) + ucid = html.xpath_node(%q(//link[@rel="canonical"])).try &.["href"].split("/")[-1] if ucid - env.response.headers["Location"] = "/channel/#{ucid["content"]}" + env.response.headers["Location"] = "/channel/#{ucid}" halt env, status_code: 302 end |
