|
|
@ -3,17 +3,8 @@ module Invidious::Routes::Images
|
|
|
|
def self.ggpht(env)
|
|
|
|
def self.ggpht(env)
|
|
|
|
url = env.request.path.lchop("/ggpht")
|
|
|
|
url = env.request.path.lchop("/ggpht")
|
|
|
|
|
|
|
|
|
|
|
|
headers = (
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
headers[":authority"] = "yt3.ggpht.com" if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
|
|
|
|
HTTP::Headers{":authority" => "yt3.ggpht.com"}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
{% else %}
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
|
|
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
|
|
|
if env.request.headers[header]?
|
|
|
|
if env.request.headers[header]?
|
|
|
@ -42,22 +33,16 @@ module Invidious::Routes::Images
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp|
|
|
|
|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% else %}
|
|
|
|
else
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp|
|
|
|
|
HTTP::Client.get("https://yt3.ggpht.com#{url}") do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
end
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -77,10 +62,7 @@ module Invidious::Routes::Images
|
|
|
|
url = "/sb/#{id}/#{storyboard}/#{index}?#{env.params.query}"
|
|
|
|
url = "/sb/#{id}/#{storyboard}/#{index}?#{env.params.query}"
|
|
|
|
|
|
|
|
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
|
|
|
|
headers[":authority"] = "#{authority}.ytimg.com" if CONFIG.use_quic
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
|
|
|
|
headers[":authority"] = "#{authority}.ytimg.com"
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
|
|
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
|
|
|
if env.request.headers[header]?
|
|
|
|
if env.request.headers[header]?
|
|
|
@ -107,22 +89,16 @@ module Invidious::Routes::Images
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Client.get("https://#{authority}.ytimg.com#{url}") do |resp|
|
|
|
|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% else %}
|
|
|
|
else
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
HTTP::Client.get("https://#{authority}.ytimg.com#{url}") do |resp|
|
|
|
|
HTTP::Client.get("https://#{authority}.ytimg.com#{url}") do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
end
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -133,17 +109,8 @@ module Invidious::Routes::Images
|
|
|
|
name = env.params.url["name"]
|
|
|
|
name = env.params.url["name"]
|
|
|
|
url = env.request.resource
|
|
|
|
url = env.request.resource
|
|
|
|
|
|
|
|
|
|
|
|
headers = (
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
headers[":authority"] = "i9.ytimg.com" if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
|
|
|
|
HTTP::Headers{":authority" => "i9.ytimg.com"}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
{% else %}
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
|
|
|
REQUEST_HEADERS_WHITELIST.each do |header|
|
|
|
|
if env.request.headers[header]?
|
|
|
|
if env.request.headers[header]?
|
|
|
@ -169,22 +136,16 @@ module Invidious::Routes::Images
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Client.get("https://i9.ytimg.com#{url}") do |resp|
|
|
|
|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% else %}
|
|
|
|
else
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
HTTP::Client.get("https://i9.ytimg.com#{url}") do |resp|
|
|
|
|
HTTP::Client.get("https://i9.ytimg.com#{url}") do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
end
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -223,41 +184,26 @@ module Invidious::Routes::Images
|
|
|
|
id = env.params.url["id"]
|
|
|
|
id = env.params.url["id"]
|
|
|
|
name = env.params.url["name"]
|
|
|
|
name = env.params.url["name"]
|
|
|
|
|
|
|
|
|
|
|
|
headers = (
|
|
|
|
headers = HTTP::Headers.new
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
headers[":authority"] = "i.ytimg.com" if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
|
|
|
|
HTTP::Headers{":authority" => "i.ytimg.com"}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
{% else %}
|
|
|
|
|
|
|
|
HTTP::Headers.new
|
|
|
|
|
|
|
|
{% end %}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if name == "maxres.jpg"
|
|
|
|
if name == "maxres.jpg"
|
|
|
|
build_thumbnails(id).each do |thumb|
|
|
|
|
build_thumbnails(id).each do |thumb|
|
|
|
|
thumbnail_resource_path = "/vi/#{id}/#{thumb[:url]}.jpg"
|
|
|
|
thumbnail_resource_path = "/vi/#{id}/#{thumb[:url]}.jpg"
|
|
|
|
|
|
|
|
|
|
|
|
# Logic here is short enough that manually typing them out should be fine.
|
|
|
|
# Logic here is short enough that manually typing them out should be fine.
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
if YT_POOL.client &.head(thumbnail_resource_path, headers).status_code == 200
|
|
|
|
if YT_POOL.client &.head(thumbnail_resource_path, headers).status_code == 200
|
|
|
|
name = thumb[:url] + ".jpg"
|
|
|
|
name = thumb[:url] + ".jpg"
|
|
|
|
break
|
|
|
|
break
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200
|
|
|
|
|
|
|
|
name = thumb[:url] + ".jpg"
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% else %}
|
|
|
|
else
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200
|
|
|
|
if HTTP::Client.head("https://i.ytimg.com#{thumbnail_resource_path}").status_code == 200
|
|
|
|
name = thumb[:url] + ".jpg"
|
|
|
|
name = thumb[:url] + ".jpg"
|
|
|
|
break
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -287,22 +233,16 @@ module Invidious::Routes::Images
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
{% unless flag?(:disable_quic) %}
|
|
|
|
if CONFIG.use_quic
|
|
|
|
if CONFIG.use_quic
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
YT_POOL.client &.get(url, headers) do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
HTTP::Client.get("https://i.ytimg.com#{url}") do |resp|
|
|
|
|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% else %}
|
|
|
|
else
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
# This can likely be optimized into a (small) pool sometime in the future.
|
|
|
|
HTTP::Client.get("https://i.ytimg.com#{url}") do |resp|
|
|
|
|
HTTP::Client.get("https://i.ytimg.com#{url}") do |resp|
|
|
|
|
return request_proc.call(resp)
|
|
|
|
return request_proc.call(resp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
end
|
|
|
|
rescue ex
|
|
|
|
rescue ex
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|