From 20c4d213d9565efa27bde05c17080a95ebb6b6d3 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 19 Jan 2019 09:10:52 -0600 Subject: [PATCH] Use config.domain in place of hardcoded value --- src/invidious.cr | 26 +++++++++++++++----------- src/invidious/helpers/helpers.cr | 5 ++++- src/invidious/helpers/utils.cr | 2 -- src/invidious/videos.cr | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 6f9097fcd..b20f0cd9c 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -364,7 +364,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, env.request.headers["Host"]?) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) host_params = env.request.query_params host_params.delete_all("v") @@ -466,7 +466,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, env.request.headers["Host"]?) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) host_params = env.request.query_params host_params.delete_all("v") @@ -552,14 +552,16 @@ 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) + XML.build(indent: " ", encoding: "UTF-8") do |xml| xml.element("OpenSearchDescription", xmlns: "http://a9.com/-/spec/opensearch/1.1/") do xml.element("ShortName") { xml.text "Invidious" } xml.element("LongName") { xml.text "Invidious Search" } xml.element("Description") { xml.text "Search for videos, channels, and playlists on Invidious" } xml.element("InputEncoding") { xml.text "UTF-8" } - xml.element("Image", width: 48, height: 48, type: "image/x-icon") { xml.text "https://invidio.us/favicon.ico" } - xml.element("Url", type: "text/html", method: "get", template: "https://invidio.us/search?q={searchTerms}") + xml.element("Image", width: 48, height: 48, type: "image/x-icon") { xml.text "#{host}/favicon.ico" } + xml.element("Url", type: "text/html", method: "get", template: "#{host}/search?q={searchTerms}") end end end @@ -1367,7 +1369,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, env.request.headers["Host"]?) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) if format == "json" env.response.content_type = "application/json" @@ -1915,7 +1917,7 @@ get "/feed/channel/:ucid" do |env| videos, count = get_60_videos(ucid, page, auto_generated) videos.select! { |video| !video.paid } - host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"]?) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) path = env.request.path feed = XML.build(indent: " ", encoding: "UTF-8") do |xml| @@ -2037,7 +2039,7 @@ get "/feed/private" do |env| videos = videos[0..max_results] end - host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"]?) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) path = env.request.path query = env.request.query.not_nil! @@ -2084,7 +2086,7 @@ get "/feed/playlist/:plid" do |env| plid = env.params.url["plid"] - host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"]?) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) path = env.request.path client = make_client(YT_URL) @@ -2521,7 +2523,8 @@ get "/api/v1/videos/:id" do |env| end if video.player_response["streamingData"]?.try &.["hlsManifestUrl"]? - host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"]?) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) + host_params = env.request.query_params host_params.delete_all("v") @@ -3536,7 +3539,8 @@ 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, env.request.headers["Host"]) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) + manifest = manifest.body manifest.gsub("https://www.youtube.com", host_url) end @@ -3549,7 +3553,7 @@ get "/api/manifest/hls_playlist/*" do |env| halt env, status_code: manifest.status_code end - host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, env.request.headers["Host"]) + host_url = make_host_url(Kemal.config.ssl || CONFIG.https_only, CONFIG.domain) 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/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 4af924c00..e25ea8801 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -15,7 +15,10 @@ class Config https_only: Bool?, hmac_key: String?, full_refresh: Bool, - domain: String?, + domain: { + type: String?, + default: "invidio.us", + }, }) end diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 496c3e0de..07c4bff33 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -205,8 +205,6 @@ def make_host_url(ssl, host) scheme = "http://" end - host ||= "invidio.us" - return "#{scheme}#{host}" end diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index b4705daa8..18a2ff8a2 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -137,7 +137,7 @@ BYPASS_REGIONS = { } VIDEO_THUMBNAILS = { - {name: "maxres", host: "invidio.us", url: "maxres", height: 720, width: 1280}, + {name: "maxres", host: "#{CONFIG.domain}", url: "maxres", height: 720, width: 1280}, {name: "maxresdefault", host: "i.ytimg.com", url: "maxresdefault", height: 720, width: 1280}, {name: "sddefault", host: "i.ytimg.com", url: "sddefault", height: 480, width: 640}, {name: "high", host: "i.ytimg.com", url: "hqdefault", height: 360, width: 480},