Invidious is an alternative front-end to YouTube
Add '&local=true' to watch and embed pages
Omar Rothfdc014af6781
diff --git a/src/invidious.cr b/src/invidious.crindex a5fc3658..6ea4b54b 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -396,6 +396,12 @@ get "/watch" do |env|fmt_stream = video.fmt_stream(decrypt_function)adaptive_fmts = video.adaptive_fmts(decrypt_function)++ if params[:local]+ fmt_stream.each { |fmt| fmt["url"] = URI.parse(fmt["url"]).query.not_nil! }+ adaptive_fmts.each { |fmt| fmt["url"] = URI.parse(fmt["url"]).query.not_nil! }+ end+video_streams = video.video_streams(adaptive_fmts)audio_streams = video.audio_streams(adaptive_fmts)@@ -496,6 +502,12 @@ get "/embed/:id" do |env|fmt_stream = video.fmt_stream(decrypt_function)adaptive_fmts = video.adaptive_fmts(decrypt_function)++ if params[:local]+ fmt_stream.each { |fmt| fmt["url"] = URI.parse(fmt["url"]).query.not_nil! }+ adaptive_fmts.each { |fmt| fmt["url"] = URI.parse(fmt["url"]).query.not_nil! }+ end+video_streams = video.video_streams(adaptive_fmts)audio_streams = video.audio_streams(adaptive_fmts)@@ -4209,24 +4221,32 @@ get "/videoplayback" do |env|query_params = env.params.queryfvip = query_params["fvip"]? || "3"- mn = query_params["mn"].split(",")[-1]+ mn = query_params["mn"].split(",").pophost = "https://r#{fvip}---#{mn}.googlevideo.com"url = "/videoplayback?#{query_params.to_s}"- headers = env.request.headers- headers.delete("Host")- headers.delete("Cookie")- headers.delete("User-Agent")- headers.delete("Referer")+ headers = HTTP::Headers.new+ {"Range", "Accept", "Accept-Encoding"}.each do |header|+ if env.request.headers[header]?+ headers[header] = env.request.headers[header]+ end+ endregion = query_params["region"]?response = HTTP::Client::Response.new(403)- loop do+ 5.times dobeginclient = make_client(URI.parse(host), proxies, region)response = client.head(url, headers)break+ rescue Socket::Addrinfo::Error+ if fvip == "3"+ break+ end++ fvip = "3"+ host = "https://r#{fvip}---#{mn}.googlevideo.com"rescue exendend@@ -4284,11 +4304,12 @@ get "/ggpht/*" do |env|client = make_client(URI.parse(host))url = env.request.path.lchop("/ggpht")- headers = env.request.headers- headers.delete("Host")- headers.delete("Cookie")- headers.delete("User-Agent")- headers.delete("Referer")+ headers = HTTP::Headers.new+ {"Range", "Accept", "Accept-Encoding"}.each do |header|+ if env.request.headers[header]?+ headers[header] = env.request.headers[header]+ end+ endclient.get(url, headers) do |response|env.response.status_code = response.status_code@@ -4342,11 +4363,12 @@ get "/vi/:id/:name" do |env|endurl = "/vi/#{id}/#{name}"- headers = env.request.headers- headers.delete("Host")- headers.delete("Cookie")- headers.delete("User-Agent")- headers.delete("Referer")+ headers = HTTP::Headers.new+ {"Range", "Accept", "Accept-Encoding"}.each do |header|+ if env.request.headers[header]?+ headers[header] = env.request.headers[header]+ end+ endclient.get(url, headers) do |response|env.response.status_code = response.status_codediff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex cd24afdc..b5bd2083 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -731,11 +731,12 @@ enddef process_video_params(query, preferences)autoplay = query["autoplay"]?.try &.to_i?continue = query["continue"]?.try &.to_i?- related_videos = query["related_videos"]?listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe+ local = query["local"]? && (query["local"] == "true").to_unsafepreferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase }quality = query["quality"]?region = query["region"]?+ related_videos = query["related_videos"]?speed = query["speed"]?.try &.to_f?video_loop = query["loop"]?.try &.to_i?volume = query["volume"]?.try &.to_i?@@ -765,8 +766,9 @@ def process_video_params(query, preferences)autoplay = autoplay == 1continue = continue == 1- related_videos = related_videos == 1listen = listen == 1+ local = local == 1+ related_videos = related_videos == 1video_loop = video_loop == 1if query["t"]?@@ -799,6 +801,7 @@ def process_video_params(query, preferences)continue: continue,controls: controls,listen: listen,+ local: local,preferred_captions: preferred_captions,quality: quality,raw: raw,diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecrindex e2cfa3a1..cecb9b2f 100644--- a/src/invidious/views/components/player.ecr+++ b/src/invidious/views/components/player.ecr@@ -11,7 +11,7 @@<% else %><% if params[:listen] %><% audio_streams.each_with_index do |fmt, i| %>- <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %>" type='<%= fmt["type"] %>' label="<%= fmt["bitrate"] %>k" selected="<%= i == 0 ? true : false %>">+ <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %><% if params[:local] %>&local=true<% end %>" type='<%= fmt["type"] %>' label="<%= fmt["bitrate"] %>k" selected="<%= i == 0 ? true : false %>"><% end %><% else %><% if params[:quality] == "dash" %>@@ -19,9 +19,9 @@<% end %><% fmt_stream.each_with_index do |fmt, i| %><% if params[:quality] %>- <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= params[:quality] == fmt["label"].split(" - ")[0] %>">+ <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %><% if params[:local] %>&local=true<% end %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= params[:quality] == fmt["label"].split(" - ")[0] %>"><% else %>- <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>">+ <source src="/latest_version?id=<%= video.id %>&itag=<%= fmt["itag"] %><% if params[:local] %>&local=true<% end %>" type='<%= fmt["type"] %>' label="<%= fmt["label"] %>" selected="<%= i == 0 ? true : false %>"><% end %><% end %><% end %>