Invidious is an alternative front-end to YouTube
Add administrator option to disable proxying
Omar Roth2cc25b1e6e5f
diff --git a/src/invidious.cr b/src/invidious.crindex 3fee0a36..79968448 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -4667,6 +4667,12 @@ get "/videoplayback" do |env|endif url.includes? "&file=seg.ts"+ if CONFIG.disabled?("livestreams")+ env.response.status_code = 403+ error_message = "Administrator has disabled this endpoint."+ next templated "error"+ end+beginclient = make_client(URI.parse(host), region)client.get(url, headers) do |response|@@ -4694,6 +4700,13 @@ get "/videoplayback" do |env|rescue exendelse+ if query_params["title"]? && CONFIG.disabled?("downloads") ||+ CONFIG.disabled?("dash")+ env.response.status_code = 403+ error_message = "Administrator has disabled this endpoint."+ next templated "error"+ end+content_length = nilfirst_chunk = truerange_start, range_end = parse_range(env.request.headers["Range"]?)diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.crindex 89fdfe91..43255972 100644--- a/src/invidious/helpers/helpers.cr+++ b/src/invidious/helpers/helpers.cr@@ -96,6 +96,19 @@ struct Configendend+ def disabled?(option)+ case disabled = CONFIG.disable_proxy+ when Bool+ return disabled+ when Array+ if disabled.includes? option+ return true+ else+ return false+ end+ end+ end+YAML.mapping({channel_threads: Int32, # Number of threads to use for crawling videos from channels (for updating subscriptions)feed_threads: Int32, # Number of threads to use for updating feeds@@ -118,11 +131,12 @@ struct Configdefault: Preferences.new(*ConfigPreferences.from_yaml("").to_tuple),converter: ConfigPreferencesConverter,},- dmca_content: {type: Array(String), default: [] of String}, # For compliance with DMCA, disables download widget using list of video IDs- check_tables: {type: Bool, default: false}, # Check table integrity, automatically try to add any missing columns, create tables, etc.- cache_annotations: {type: Bool, default: false}, # Cache annotations requested from IA, will not cache empty annotations or annotations that only contain cards- banner: {type: String?, default: nil}, # Optional banner to be displayed along top of page for announcements, etc.- hsts: {type: Bool?, default: true}, # Enables 'Strict-Transport-Security'. Ensure that `domain` and all subdomains are served securely+ dmca_content: {type: Array(String), default: [] of String}, # For compliance with DMCA, disables download widget using list of video IDs+ check_tables: {type: Bool, default: false}, # Check table integrity, automatically try to add any missing columns, create tables, etc.+ cache_annotations: {type: Bool, default: false}, # Cache annotations requested from IA, will not cache empty annotations or annotations that only contain cards+ banner: {type: String?, default: nil}, # Optional banner to be displayed along top of page for announcements, etc.+ hsts: {type: Bool?, default: true}, # Enables 'Strict-Transport-Security'. Ensure that `domain` and all subdomains are served securely+ disable_proxy: {type: Bool? | Array(String)?, default: false}, # Disable proxying server-wide: options: 'dash', 'livestreams', 'downloads', 'local'})enddiff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex dfaecbb2..b54e65b8 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -1292,6 +1292,14 @@ def process_video_params(query, preferences)related_videos = related_videos == 1video_loop = video_loop == 1+ if CONFIG.disabled?("dash") && quality == "dash"+ quality = "high"+ end++ if CONFIG.disabled?("local") && local+ local = false+ end+if query["t"]?video_start = decode_time(query["t"])enddiff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecrindex d128b0f6..491e8fb1 100644--- a/src/invidious/views/components/player.ecr+++ b/src/invidious/views/components/player.ecr@@ -6,7 +6,7 @@<% if params.autoplay %>autoplay<% end %><% if params.video_loop %>loop<% end %><% if params.controls %>controls<% end %>>- <% if hlsvp %>+ <% if hlsvp && !CONFIG.disabled?("livestreams") %><source src="<%= hlsvp %>?local=true" type="application/x-mpegURL" label="livestream"><% else %><% if params.listen %>diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecrindex 232ce224..2a1c43f2 100644--- a/src/invidious/views/preferences.ecr+++ b/src/invidious/views/preferences.ecr@@ -35,7 +35,7 @@ function update_value(element) {<div class="pure-control-group"><label for="local"><%= translate(locale, "Proxy videos? ") %></label>- <input name="local" id="local" type="checkbox" <% if preferences.local %>checked<% end %>>+ <input name="local" id="local" type="checkbox" <% if preferences.local && !CONFIG.disabled?("local") %>checked<% end %> <% if CONFIG.disabled?("local") %>disabled<% end %>></div><div class="pure-control-group">@@ -56,7 +56,9 @@ function update_value(element) {<label for="quality"><%= translate(locale, "Preferred video quality: ") %></label><select name="quality" id="quality"><% {"dash", "hd720", "medium", "small"}.each do |option| %>- <option value="<%= option %>" <% if preferences.quality == option %> selected <% end %>><%= translate(locale, option) %></option>+ <% if !(option == "dash" && CONFIG.disabled?("dash")) %>+ <option value="<%= option %>" <% if preferences.quality == option %> selected <% end %>><%= translate(locale, option) %></option>+ <% end %><% end %></select></div>diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecrindex 1d4557fa..a1239383 100644--- a/src/invidious/views/watch.ecr+++ b/src/invidious/views/watch.ecr@@ -98,7 +98,7 @@ var video_data = {<% end %></p>- <% if CONFIG.dmca_content.includes? video.id %>+ <% if CONFIG.dmca_content.includes?(video.id) || CONFIG.disabled?("downloads") %><p><%= translate(locale, "Download is disabled.") %></p><% else %><form class="pure-form pure-form-stacked" action="/latest_version" method="get" rel="noopener" target="_blank">