Add '&local=true' to watch and embed pages

pull/411/head
Omar Roth 6 years ago
parent bf11a46abe
commit fdc014af67

@ -396,6 +396,12 @@ get "/watch" do |env|
fmt_stream = video.fmt_stream(decrypt_function) fmt_stream = video.fmt_stream(decrypt_function)
adaptive_fmts = video.adaptive_fmts(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) video_streams = video.video_streams(adaptive_fmts)
audio_streams = video.audio_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) fmt_stream = video.fmt_stream(decrypt_function)
adaptive_fmts = video.adaptive_fmts(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) video_streams = video.video_streams(adaptive_fmts)
audio_streams = video.audio_streams(adaptive_fmts) audio_streams = video.audio_streams(adaptive_fmts)
@ -4209,24 +4221,32 @@ get "/videoplayback" do |env|
query_params = env.params.query query_params = env.params.query
fvip = query_params["fvip"]? || "3" fvip = query_params["fvip"]? || "3"
mn = query_params["mn"].split(",")[-1] mn = query_params["mn"].split(",").pop
host = "https://r#{fvip}---#{mn}.googlevideo.com" host = "https://r#{fvip}---#{mn}.googlevideo.com"
url = "/videoplayback?#{query_params.to_s}" url = "/videoplayback?#{query_params.to_s}"
headers = env.request.headers headers = HTTP::Headers.new
headers.delete("Host") {"Range", "Accept", "Accept-Encoding"}.each do |header|
headers.delete("Cookie") if env.request.headers[header]?
headers.delete("User-Agent") headers[header] = env.request.headers[header]
headers.delete("Referer") end
end
region = query_params["region"]? region = query_params["region"]?
response = HTTP::Client::Response.new(403) response = HTTP::Client::Response.new(403)
loop do 5.times do
begin begin
client = make_client(URI.parse(host), proxies, region) client = make_client(URI.parse(host), proxies, region)
response = client.head(url, headers) response = client.head(url, headers)
break break
rescue Socket::Addrinfo::Error
if fvip == "3"
break
end
fvip = "3"
host = "https://r#{fvip}---#{mn}.googlevideo.com"
rescue ex rescue ex
end end
end end
@ -4284,11 +4304,12 @@ get "/ggpht/*" do |env|
client = make_client(URI.parse(host)) client = make_client(URI.parse(host))
url = env.request.path.lchop("/ggpht") url = env.request.path.lchop("/ggpht")
headers = env.request.headers headers = HTTP::Headers.new
headers.delete("Host") {"Range", "Accept", "Accept-Encoding"}.each do |header|
headers.delete("Cookie") if env.request.headers[header]?
headers.delete("User-Agent") headers[header] = env.request.headers[header]
headers.delete("Referer") end
end
client.get(url, headers) do |response| client.get(url, headers) do |response|
env.response.status_code = response.status_code env.response.status_code = response.status_code
@ -4342,11 +4363,12 @@ get "/vi/:id/:name" do |env|
end end
url = "/vi/#{id}/#{name}" url = "/vi/#{id}/#{name}"
headers = env.request.headers headers = HTTP::Headers.new
headers.delete("Host") {"Range", "Accept", "Accept-Encoding"}.each do |header|
headers.delete("Cookie") if env.request.headers[header]?
headers.delete("User-Agent") headers[header] = env.request.headers[header]
headers.delete("Referer") end
end
client.get(url, headers) do |response| client.get(url, headers) do |response|
env.response.status_code = response.status_code env.response.status_code = response.status_code

@ -731,11 +731,12 @@ end
def process_video_params(query, preferences) def process_video_params(query, preferences)
autoplay = query["autoplay"]?.try &.to_i? autoplay = query["autoplay"]?.try &.to_i?
continue = query["continue"]?.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 listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe
local = query["local"]? && (query["local"] == "true").to_unsafe
preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase } preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase }
quality = query["quality"]? quality = query["quality"]?
region = query["region"]? region = query["region"]?
related_videos = query["related_videos"]?
speed = query["speed"]?.try &.to_f? speed = query["speed"]?.try &.to_f?
video_loop = query["loop"]?.try &.to_i? video_loop = query["loop"]?.try &.to_i?
volume = query["volume"]?.try &.to_i? volume = query["volume"]?.try &.to_i?
@ -765,8 +766,9 @@ def process_video_params(query, preferences)
autoplay = autoplay == 1 autoplay = autoplay == 1
continue = continue == 1 continue = continue == 1
related_videos = related_videos == 1
listen = listen == 1 listen = listen == 1
local = local == 1
related_videos = related_videos == 1
video_loop = video_loop == 1 video_loop = video_loop == 1
if query["t"]? if query["t"]?
@ -799,6 +801,7 @@ def process_video_params(query, preferences)
continue: continue, continue: continue,
controls: controls, controls: controls,
listen: listen, listen: listen,
local: local,
preferred_captions: preferred_captions, preferred_captions: preferred_captions,
quality: quality, quality: quality,
raw: raw, raw: raw,

@ -11,7 +11,7 @@
<% else %> <% else %>
<% if params[:listen] %> <% if params[:listen] %>
<% audio_streams.each_with_index do |fmt, i| %> <% 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 %> <% end %>
<% else %> <% else %>
<% if params[:quality] == "dash" %> <% if params[:quality] == "dash" %>
@ -19,9 +19,9 @@
<% end %> <% end %>
<% fmt_stream.each_with_index do |fmt, i| %> <% fmt_stream.each_with_index do |fmt, i| %>
<% if params[:quality] %> <% 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 %> <% 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 %> <% end %>
<% end %> <% end %>

Loading…
Cancel
Save