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

This commit is contained in:
Omar Roth 2019-03-11 11:43:48 -05:00
parent bf11a46abe
commit fdc014af67
3 changed files with 47 additions and 22 deletions

View File

@ -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.query
fvip = query_params["fvip"]? || "3"
mn = query_params["mn"].split(",")[-1]
mn = query_params["mn"].split(",").pop
host = "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
end
region = query_params["region"]?
response = HTTP::Client::Response.new(403)
loop do
5.times do
begin
client = 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 ex
end
end
@ -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
end
client.get(url, headers) do |response|
env.response.status_code = response.status_code
@ -4342,11 +4363,12 @@ get "/vi/:id/:name" do |env|
end
url = "/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
end
client.get(url, headers) do |response|
env.response.status_code = response.status_code

View File

@ -731,11 +731,12 @@ end
def 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_unsafe
preferred_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 == 1
continue = continue == 1
related_videos = related_videos == 1
listen = listen == 1
local = local == 1
related_videos = related_videos == 1
video_loop = video_loop == 1
if 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,

View File

@ -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 %>