Invidious is an alternative front-end to YouTube
Update code for Crystal 0.36.0
saltycrys5f03a583d198
diff --git a/src/invidious.cr b/src/invidious.crindex a63d6aca..ec6df302 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -1428,9 +1428,9 @@ get "/feed/playlist/:plid" do |env|node.attributes.each do |attribute|case attribute.namewhen "url", "href"- full_path = URI.parse(node[attribute.name]).full_path- query_string_opt = full_path.starts_with?("/watch?v=") ? "&#{params}" : ""- node[attribute.name] = "#{HOST_URL}#{full_path}#{query_string_opt}"+ request_target = URI.parse(node[attribute.name]).request_target+ query_string_opt = request_target.starts_with?("/watch?v=") ? "&#{params}" : ""+ node[attribute.name] = "#{HOST_URL}#{request_target}#{query_string_opt}"else nil # Skipendend@@ -1439,7 +1439,7 @@ get "/feed/playlist/:plid" do |env|document = document.to_xml(options: XML::SaveOptions::NO_DECL)document.scan(/<uri>(?<url>[^<]+)<\/uri>/).each do |match|- content = "#{HOST_URL}#{URI.parse(match["url"]).full_path}"+ content = "#{HOST_URL}#{URI.parse(match["url"]).request_target}"document = document.gsub(match[0], "<uri>#{content}</uri>")end@@ -1634,7 +1634,7 @@ endget "/attribution_link" do |env|if query = env.params.query["u"]?- url = URI.parse(query).full_path+ url = URI.parse(query).request_targetelseurl = "/"end@@ -1978,7 +1978,7 @@ get "/api/v1/captions/:id" do |env|caption = caption[0]end- url = URI.parse("#{caption.baseUrl}&tlang=#{tlang}").full_path+ url = URI.parse("#{caption.baseUrl}&tlang=#{tlang}").request_target# Auto-generated captions often have cues that aren't aligned properly with the video,# as well as some other markup that makes it cumbersome, so we try to fix that here@@ -3184,7 +3184,7 @@ get "/api/manifest/dash/id/:id" do |env|endif dashmpd = video.dash_manifest_url- manifest = YT_POOL.client &.get(URI.parse(dashmpd).full_path).body+ manifest = YT_POOL.client &.get(URI.parse(dashmpd).request_target).bodymanifest = manifest.gsub(/<BaseURL>[^<]+<\/BaseURL>/) do |baseurl|url = baseurl.lchop("<BaseURL>")@@ -3192,7 +3192,7 @@ get "/api/manifest/dash/id/:id" do |env|if localuri = URI.parse(url)- url = "#{uri.full_path}host/#{uri.host}/"+ url = "#{uri.request_target}host/#{uri.host}/"end"<BaseURL>#{url}</BaseURL>"@@ -3205,7 +3205,7 @@ get "/api/manifest/dash/id/:id" do |env|if localadaptive_fmts.each do |fmt|- fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).full_path)+ fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target)endend@@ -3403,7 +3403,7 @@ get "/latest_version" do |env|nextend- url = URI.parse(url).full_path.not_nil! if local+ url = URI.parse(url).request_target.not_nil! if localurl = "#{url}&title=#{title}" if titleenv.redirect url@@ -3515,7 +3515,7 @@ get "/videoplayback" do |env|client = make_client(URI.parse(new_host), region)end- url = "#{location.full_path}&host=#{location.host}#{region ? "®ion=#{region}" : ""}"+ url = "#{location.request_target}&host=#{location.host}#{region ? "®ion=#{region}" : ""}"elsebreakend@@ -3555,7 +3555,7 @@ get "/videoplayback" do |env|if location = response.headers["Location"]?location = URI.parse(location)- location = "#{location.full_path}&host=#{location.host}"+ location = "#{location.request_target}&host=#{location.host}"if regionlocation += "®ion=#{region}"@@ -3619,7 +3619,7 @@ get "/videoplayback" do |env|if location = response.headers["Location"]?location = URI.parse(location)- location = "#{location.full_path}&host=#{location.host}#{region ? "®ion=#{region}" : ""}"+ location = "#{location.request_target}&host=#{location.host}#{region ? "®ion=#{region}" : ""}"env.redirect locationbreak@@ -3859,7 +3859,7 @@ endget "/watch_videos" do |env|response = YT_POOL.client &.get(env.request.resource)if url = response.headers["Location"]?- url = URI.parse(url).full_path+ url = URI.parse(url).request_targetnext env.redirect urlend@@ -3874,7 +3874,7 @@ error 404 do |env|response = YT_POOL.client &.get("/#{item}")if response.status_code == 301- response = YT_POOL.client &.get(URI.parse(response.headers["Location"]).full_path)+ response = YT_POOL.client &.get(URI.parse(response.headers["Location"]).request_target)endif response.body.empty?diff --git a/src/invidious/comments.cr b/src/invidious/comments.crindex 0ac99ba5..a8bbf74b 100644--- a/src/invidious/comments.cr+++ b/src/invidious/comments.cr@@ -294,7 +294,7 @@ def template_youtube_comments(comments, locale, thin_mode)endif !thin_mode- author_thumbnail = "/ggpht#{URI.parse(child["authorThumbnails"][-1]["url"].as_s).full_path}"+ author_thumbnail = "/ggpht#{URI.parse(child["authorThumbnails"][-1]["url"].as_s).request_target}"elseauthor_thumbnail = ""end@@ -322,7 +322,7 @@ def template_youtube_comments(comments, locale, thin_mode)html << <<-END_HTML<div class="pure-g"><div class="pure-u-1 pure-u-md-1-2">- <img style="width:100%" src="/ggpht#{URI.parse(attachment["url"].as_s).full_path}">+ <img style="width:100%" src="/ggpht#{URI.parse(attachment["url"].as_s).request_target}"></div></div>END_HTML@@ -375,7 +375,7 @@ def template_youtube_comments(comments, locale, thin_mode)if child["creatorHeart"]?if !thin_mode- creator_thumbnail = "/ggpht#{URI.parse(child["creatorHeart"]["creatorThumbnail"].as_s).full_path}"+ creator_thumbnail = "/ggpht#{URI.parse(child["creatorHeart"]["creatorThumbnail"].as_s).request_target}"elsecreator_thumbnail = ""end@@ -473,7 +473,7 @@ def replace_links(html)params = HTTP::Params.parse(url.query.not_nil!)anchor["href"] = params["q"]?else- anchor["href"] = url.full_path+ anchor["href"] = url.request_targetendelsif url.to_s == "#"begin@@ -544,7 +544,7 @@ def content_to_comment_html(content)if url.path == "/redirect"url = HTTP::Params.parse(url.query.not_nil!)["q"]else- url = url.full_path+ url = url.request_targetendenddiff --git a/src/invidious/helpers/proxy.cr b/src/invidious/helpers/proxy.crindex 7a42ef41..3418d887 100644--- a/src/invidious/helpers/proxy.cr+++ b/src/invidious/helpers/proxy.cr@@ -71,14 +71,14 @@ endclass HTTPClient < HTTP::Clientdef set_proxy(proxy : HTTPProxy)begin- @socket = proxy.open(host: @host, port: @port, tls: @tls, connection_options: proxy_connection_options)+ @io = proxy.open(host: @host, port: @port, tls: @tls, connection_options: proxy_connection_options)rescue IO::Error- @socket = nil+ @io = nilendenddef unset_proxy- @socket = nil+ @io = nilenddef proxy_connection_optionsdiff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.crindex 7d94a6e5..2c95a373 100644--- a/src/invidious/helpers/utils.cr+++ b/src/invidious/helpers/utils.cr@@ -329,7 +329,7 @@ def get_referer(env, fallback = "/", unroll = true)endend- referer = referer.full_path+ referer = referer.request_targetreferer = "/" + referer.gsub(/[^\/?@&%=\-_.0-9a-zA-Z]/, "").lstrip("/\\")if referer == env.request.pathdiff --git a/src/invidious/jobs/bypass_captcha_job.cr b/src/invidious/jobs/bypass_captcha_job.crindex 8b1aed5f..4269e123 100644--- a/src/invidious/jobs/bypass_captcha_job.cr+++ b/src/invidious/jobs/bypass_captcha_job.cr@@ -60,7 +60,7 @@ class Invidious::Jobs::BypassCaptchaJob < Invidious::Jobs::BaseJobelsif response.headers["Location"]?.try &.includes?("/sorry/index")location = response.headers["Location"].try { |u| URI.parse(u) }headers = HTTP::Headers{":authority" => location.host.not_nil!}- response = YT_POOL.client &.get(location.full_path, headers)+ response = YT_POOL.client &.get(location.request_target, headers)html = XML.parse_html(response.body)form = html.xpath_node(%(//form[@action="index"])).not_nil!diff --git a/src/invidious/routes/embed.cr b/src/invidious/routes/embed.crindex 4fd265c9..5db32788 100644--- a/src/invidious/routes/embed.cr+++ b/src/invidious/routes/embed.cr@@ -144,8 +144,8 @@ class Invidious::Routes::Embed < Invidious::Routes::BaseRouteadaptive_fmts = video.adaptive_fmtsif params.local- fmt_stream.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).full_path) }- adaptive_fmts.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).full_path) }+ fmt_stream.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) }+ adaptive_fmts.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) }endvideo_streams = video.video_streamsdiff --git a/src/invidious/routes/login.cr b/src/invidious/routes/login.crindex 662fdf13..ffe5f568 100644--- a/src/invidious/routes/login.cr+++ b/src/invidious/routes/login.cr@@ -255,7 +255,7 @@ class Invidious::Routes::Login < Invidious::Routes::BaseRoutetraceback << "Unhandled dialog /b/0/SmsAuthInterstitial."end- login = client.get(location.full_path, headers)+ login = client.get(location.request_target, headers)headers = login.cookies.add_request_headers(headers)location = login.headers["Location"]?.try { |u| URI.parse(u) }diff --git a/src/invidious/routes/watch.cr b/src/invidious/routes/watch.crindex 65604a88..8169e1ed 100644--- a/src/invidious/routes/watch.cr+++ b/src/invidious/routes/watch.cr@@ -126,8 +126,8 @@ class Invidious::Routes::Watch < Invidious::Routes::BaseRouteadaptive_fmts = video.adaptive_fmtsif params.local- fmt_stream.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).full_path) }- adaptive_fmts.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).full_path) }+ fmt_stream.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) }+ adaptive_fmts.each { |fmt| fmt["url"] = JSON::Any.new(URI.parse(fmt["url"].as_s).request_target) }endvideo_streams = video.video_streamsdiff --git a/src/invidious/views/channel.ecr b/src/invidious/views/channel.ecrindex caa0ad0e..061d7eec 100644--- a/src/invidious/views/channel.ecr+++ b/src/invidious/views/channel.ecr@@ -5,7 +5,7 @@<% if channel.banner %><div class="h-box">- <img style="width:100%" src="/ggpht<%= URI.parse(channel.banner.not_nil!.gsub("=w1060-", "=w1280-")).full_path %>">+ <img style="width:100%" src="/ggpht<%= URI.parse(channel.banner.not_nil!.gsub("=w1060-", "=w1280-")).request_target %>"></div><div class="h-box">@@ -16,7 +16,7 @@<div class="pure-g h-box"><div class="pure-u-2-3"><div class="channel-profile">- <img src="/ggpht<%= URI.parse(channel.author_thumbnail).full_path %>">+ <img src="/ggpht<%= URI.parse(channel.author_thumbnail).request_target %>"><span><%= channel.author %></span></div></div>diff --git a/src/invidious/views/community.ecr b/src/invidious/views/community.ecrindex 69724390..3c4eaabb 100644--- a/src/invidious/views/community.ecr+++ b/src/invidious/views/community.ecr@@ -4,7 +4,7 @@<% if channel.banner %><div class="h-box">- <img style="width:100%" src="/ggpht<%= URI.parse(channel.banner.not_nil!.gsub("=w1060-", "=w1280-")).full_path %>">+ <img style="width:100%" src="/ggpht<%= URI.parse(channel.banner.not_nil!.gsub("=w1060-", "=w1280-")).request_target %>"></div><div class="h-box">@@ -15,7 +15,7 @@<div class="pure-g h-box"><div class="pure-u-2-3"><div class="channel-profile">- <img src="/ggpht<%= URI.parse(channel.author_thumbnail).full_path %>">+ <img src="/ggpht<%= URI.parse(channel.author_thumbnail).request_target %>"><span><%= channel.author %></span></div></div>diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecrindex e4a60697..1380d754 100644--- a/src/invidious/views/components/item.ecr+++ b/src/invidious/views/components/item.ecr@@ -5,7 +5,7 @@<a style="width:100%" href="/channel/<%= item.ucid %>"><% if !env.get("preferences").as(Preferences).thin_mode %><center>- <img style="width:56.25%" src="/ggpht<%= URI.parse(item.author_thumbnail).full_path %>"/>+ <img style="width:56.25%" src="/ggpht<%= URI.parse(item.author_thumbnail).request_target %>"/></center><% end %><p><%= item.author %></p>@@ -15,7 +15,7 @@<h5><%= item.description_html %></h5><% when SearchPlaylist, InvidiousPlaylist %><% if item.id.starts_with? "RD" %>- <% url = "/mix?list=#{item.id}&continuation=#{URI.parse(item.thumbnail || "/vi/-----------").full_path.split("/")[2]}" %>+ <% url = "/mix?list=#{item.id}&continuation=#{URI.parse(item.thumbnail || "/vi/-----------").request_target.split("/")[2]}" %><% else %><% url = "/playlist?list=#{item.id}" %><% end %>@@ -23,7 +23,7 @@<a style="width:100%" href="<%= url %>"><% if !env.get("preferences").as(Preferences).thin_mode %><div class="thumbnail">- <img class="thumbnail" src="<%= URI.parse(item.thumbnail || "/").full_path %>"/>+ <img class="thumbnail" src="<%= URI.parse(item.thumbnail || "/").request_target %>"/><p class="length"><%= number_with_separator(item.video_count) %> videos</p></div><% end %>diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecrindex 625c6fee..a898a41f 100644--- a/src/invidious/views/components/player.ecr+++ b/src/invidious/views/components/player.ecr@@ -4,7 +4,7 @@<% if params.video_loop %>loop<% end %><% if params.controls %>controls<% end %>><% if (hlsvp = video.hls_manifest_url) && !CONFIG.disabled?("livestreams") %>- <source src="<%= URI.parse(hlsvp).full_path %><% if params.local %>?local=true<% end %>" type="application/x-mpegURL" label="livestream">+ <source src="<%= URI.parse(hlsvp).request_target %><% if params.local %>?local=true<% end %>" type="application/x-mpegURL" label="livestream"><% else %><% if params.listen %><% audio_streams.each_with_index do |fmt, i| %>diff --git a/src/invidious/views/playlists.ecr b/src/invidious/views/playlists.ecrindex a77d106d..44bdb94d 100644--- a/src/invidious/views/playlists.ecr+++ b/src/invidious/views/playlists.ecr@@ -4,7 +4,7 @@<% if channel.banner %><div class="h-box">- <img style="width:100%" src="/ggpht<%= URI.parse(channel.banner.not_nil!.gsub("=w1060-", "=w1280-")).full_path %>">+ <img style="width:100%" src="/ggpht<%= URI.parse(channel.banner.not_nil!.gsub("=w1060-", "=w1280-")).request_target %>"></div><div class="h-box">@@ -15,7 +15,7 @@<div class="pure-g h-box"><div class="pure-u-2-3"><div class="channel-profile">- <img src="/ggpht<%= URI.parse(channel.author_thumbnail).full_path %>">+ <img src="/ggpht<%= URI.parse(channel.author_thumbnail).request_target %>"><span><%= channel.author %></span></div></div>diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecrindex 786a88b6..7cbe5e3f 100644--- a/src/invidious/views/watch.ecr+++ b/src/invidious/views/watch.ecr@@ -203,7 +203,7 @@<a href="/channel/<%= video.ucid %>" style="display:block;width:fit-content;width:-moz-fit-content"><div class="channel-profile"><% if !video.author_thumbnail.empty? %>- <img src="/ggpht<%= URI.parse(video.author_thumbnail).full_path %>">+ <img src="/ggpht<%= URI.parse(video.author_thumbnail).request_target %>"><% end %><span id="channel-name"><%= video.author %></span></div>