Invidious is an alternative front-end to YouTube
Add port number to host URL
Omar Roth1435516a9cea
diff --git a/src/invidious.cr b/src/invidious.crindex 9c3248ab..3556ef14 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -417,7 +417,7 @@ get "/watch" do |env|video.description = replace_links(video.description)description = video.short_description- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)host_params = env.request.query_paramshost_params.delete_all("v")@@ -517,7 +517,7 @@ get "/embed/:id" do |env|video.description = replace_links(video.description)description = video.short_description- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)host_params = env.request.query_paramshost_params.delete_all("v")@@ -603,7 +603,7 @@ get "/opensearch.xml" do |env|locale = LOCALES[env.get("locale").as(String)]?env.response.content_type = "application/opensearchdescription+xml"- host = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host = make_host_url(config, Kemal.config)XML.build(indent: " ", encoding: "UTF-8") do |xml|xml.element("OpenSearchDescription", xmlns: "http://a9.com/-/spec/opensearch/1.1/") do@@ -1500,7 +1500,7 @@ get "/subscription_manager" do |env|subscriptions.sort_by! { |channel| channel.author.downcase }if action_takeout- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)if format == "json"env.response.content_type = "application/json"@@ -2057,7 +2057,8 @@ endget "/feed/channel/:ucid" do |env|locale = LOCALES[env.get("locale").as(String)]?- env.response.content_type = "text/xml"+ env.response.content_type = "application/atom+xml"+ucid = env.params.url["ucid"]begin@@ -2101,7 +2102,7 @@ get "/feed/channel/:ucid" do |env|)end- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)path = env.request.pathfeed = XML.build(indent: " ", encoding: "UTF-8") do |xml|@@ -2168,6 +2169,8 @@ endget "/feed/private" do |env|locale = LOCALES[env.get("locale").as(String)]?+ env.response.content_type = "application/atom+xml"+token = env.params.query["token"]?if !token@@ -2235,7 +2238,7 @@ get "/feed/private" do |env|videos = videos[0..max_results]end- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)path = env.request.pathquery = env.request.query.not_nil!@@ -2281,16 +2284,17 @@ get "/feed/private" do |env|endend- env.response.content_type = "application/atom+xml"feedendget "/feed/playlist/:plid" do |env|locale = LOCALES[env.get("locale").as(String)]?+ env.response.content_type = "application/atom+xml"+plid = env.params.url["plid"]- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)path = env.request.pathclient = make_client(YT_URL)@@ -2315,7 +2319,6 @@ get "/feed/playlist/:plid" do |env|document = document.gsub(match[0], "<uri>#{content}</uri>")end- env.response.content_type = "text/xml"documentend@@ -2897,7 +2900,7 @@ get "/api/v1/videos/:id" do |env|endif video.player_response["streamingData"]?.try &.["hlsManifestUrl"]?- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)host_params = env.request.query_paramshost_params.delete_all("v")@@ -4091,7 +4094,7 @@ get "/api/manifest/hls_variant/*" do |env|env.response.content_type = "application/x-mpegURL"env.response.headers.add("Access-Control-Allow-Origin", "*")- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)manifest = manifest.bodymanifest.gsub("https://www.youtube.com", host_url)@@ -4105,7 +4108,7 @@ get "/api/manifest/hls_playlist/*" do |env|halt env, status_code: manifest.status_codeend- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)manifest = manifest.body.gsub("https://www.youtube.com", host_url)manifest = manifest.gsub(/https:\/\/r\d---.{11}\.c\.youtube\.com/, host_url)diff --git a/src/invidious/channels.cr b/src/invidious/channels.crindex b38c5e1a..5ce9775f 100644--- a/src/invidious/channels.cr+++ b/src/invidious/channels.cr@@ -197,7 +197,7 @@ def subscribe_pubsub(ucid, key, config)nonce = Random::Secure.hex(4)signature = "#{time}:#{nonce}"- host_url = make_host_url(Kemal.config.ssl || config.https_only, config.domain)+ host_url = make_host_url(config, Kemal.config)body = {"hub.callback" => "#{host_url}/feed/webhook/v1:#{time}:#{nonce}:#{OpenSSL::HMAC.hexdigest(:sha1, key, signature)}",diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.crindex 5ccc1009..c200801f 100644--- a/src/invidious/helpers/utils.cr+++ b/src/invidious/helpers/utils.cr@@ -193,19 +193,28 @@ def arg_array(array, start = 1)return argsend-def make_host_url(ssl, host)+def make_host_url(config, kemal_config)+ ssl = config.https_only || kemal_config.ssl+if sslscheme = "https://"elsescheme = "http://"end- if host- host = host.lchop(".")- return "#{scheme}#{host}"+ if kemal_config.port != 80 && kemal_config.port != 443+ port = ":#{kemal_config.port}"else+ port = ""+ end++ if !config.domainreturn ""end++ host = config.domain.not_nil!.lchop(".")++ return "#{scheme}#{host}#{port}"enddef get_referer(env, fallback = "/")