Invidious is an alternative front-end to YouTube
refactor: Move top level constants to it's own modules
Fijxu067a426235b9
diff --git a/src/invidious.cr b/src/invidious.crindex ec518453..d7c5b80b 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -67,20 +67,9 @@ rescue exputs "Check your 'config.yml' database settings or PostgreSQL settings."exit(1)end-ARCHIVE_URL = URI.parse("https://archive.org")-PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")-REDDIT_URL = URI.parse("https://www.reddit.com")-YT_URL = URI.parse("https://www.youtube.com")-HOST_URL = make_host_url(Kemal.config)--CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"-TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"}+HOST_URL = make_host_url(Kemal.config)MAX_ITEMS_PER_PAGE = 1500-REQUEST_HEADERS_WHITELIST = {"accept", "accept-encoding", "cache-control", "content-length", "if-none-match", "range"}-RESPONSE_HEADERS_BLACKLIST = {"access-control-allow-origin", "alt-svc", "server", "cross-origin-opener-policy-report-only", "report-to", "cross-origin", "timing-allow-origin", "cross-origin-resource-policy"}-HTTP_CHUNK_SIZE = 10485760 # ~10MB-CURRENT_BRANCH = {{ "#{`git branch | sed -n '/* /s///p'`.strip}" }}CURRENT_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }}CURRENT_VERSION = {{ "#{`git log -1 --format=%ci | awk '{print $1}' | sed s/-/./g`.strip}" }}@@ -97,7 +86,7 @@ SOFTWARE = {"branch" => "#{CURRENT_BRANCH}",}-YT_POOL = YoutubeConnectionPool.new(YT_URL, capacity: CONFIG.pool_size)+YT_POOL = YoutubeConnectionPool.new(URI.parse("https://www.youtube.com"), capacity: CONFIG.pool_size)# Image request pooldiff --git a/src/invidious/comments/reddit.cr b/src/invidious/comments/reddit.crindex ba9c19f1..e128350c 100644--- a/src/invidious/comments/reddit.cr+++ b/src/invidious/comments/reddit.cr@@ -1,5 +1,6 @@module Invidious::Commentsextend self+ private REDDIT_URL = URI.parse("https://www.reddit.com")def fetch_reddit(id, sort_by = "confidence")client = make_client(REDDIT_URL)diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.crindex 6add0237..ab694b1f 100644--- a/src/invidious/helpers/helpers.cr+++ b/src/invidious/helpers/helpers.cr@@ -1,5 +1,7 @@require "./macros"+TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"}+struct Nonceinclude DB::Serializablediff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.crindex 5637e533..24b20ed9 100644--- a/src/invidious/helpers/utils.cr+++ b/src/invidious/helpers/utils.cr@@ -1,3 +1,5 @@+PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")+# See http://www.evanmiller.org/how-not-to-sort-by-average-rating.htmldef ci_lower_bound(pos, n)if n == 0diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.crindex 6a3eb8ae..fc3de695 100644--- a/src/invidious/routes/api/v1/videos.cr+++ b/src/invidious/routes/api/v1/videos.cr@@ -1,6 +1,9 @@require "html"module Invidious::Routes::API::V1::Videos+ private INTERNET_ARCHIVE_URL = URI.parse("https://archive.org")+ private CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"+def self.videos(env)locale = env.get("preferences").as(Preferences).locale@@ -279,7 +282,7 @@ module Invidious::Routes::API::V1::Videosfile = URI.encode_www_form("#{id[0, 3]}/#{id}.xml")- location = make_client(ARCHIVE_URL, &.get("/download/youtubeannotations_#{index}/#{id[0, 2]}.tar/#{file}"))+ location = make_client(INTERNET_ARCHIVE_URL, &.get("/download/youtubeannotations_#{index}/#{id[0, 2]}.tar/#{file}"))if !location.headers["Location"]?env.response.status_code = location.status_codediff --git a/src/invidious/routes/routes.cr b/src/invidious/routes/routes.crnew file mode 100644index 00000000..57f10d35--- /dev/null+++ b/src/invidious/routes/routes.cr@@ -0,0 +1,21 @@+module Invidious::Routes+ private REQUEST_HEADERS_WHITELIST = {+ "accept",+ "accept-encoding",+ "cache-control",+ "content-length",+ "if-none-match",+ "range",+ }+ private RESPONSE_HEADERS_BLACKLIST = {+ "access-control-allow-origin",+ "alt-svc",+ "server",+ "cross-origin-opener-policy-report-only",+ "report-to",+ "cross-origin",+ "timing-allow-origin",+ "cross-origin-resource-policy+ ",+ }+enddiff --git a/src/invidious/routes/video_playback.cr b/src/invidious/routes/video_playback.crindex 083087a9..7c01aa36 100644--- a/src/invidious/routes/video_playback.cr+++ b/src/invidious/routes/video_playback.cr@@ -1,4 +1,6 @@module Invidious::Routes::VideoPlayback+ private HTTP_CHUNK_SIZE = 10485760 # ~10MB+# /videoplaybackdef self.get_video_playback(env)locale = env.get("preferences").as(Preferences).locale