mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Proxy thumbnails
This commit is contained in:
parent
4287c0d96a
commit
429a4b2dec
5 changed files with 61 additions and 13 deletions
|
@ -264,8 +264,7 @@ get "/watch" do |env|
|
|||
hlsvp = hlsvp.gsub("https://manifest.googlevideo.com", host_url)
|
||||
end
|
||||
|
||||
# TODO: Find highest resolution thumbnail automatically
|
||||
thumbnail = "https://i.ytimg.com/vi/#{video.id}/mqdefault.jpg"
|
||||
thumbnail = "/vi/#{video.id}/maxres.jpg"
|
||||
|
||||
if params[:raw]
|
||||
url = fmt_stream[0]["url"]
|
||||
|
@ -364,8 +363,7 @@ get "/embed/:id" do |env|
|
|||
hlsvp = hlsvp.gsub("https://manifest.googlevideo.com", host_url)
|
||||
end
|
||||
|
||||
# TODO: Find highest resolution thumbnail automatically
|
||||
thumbnail = "https://i.ytimg.com/vi/#{video.id}/mqdefault.jpg"
|
||||
thumbnail = "/vi/#{video.id}/maxres.jpg"
|
||||
|
||||
if params[:raw]
|
||||
url = fmt_stream[0]["url"]
|
||||
|
@ -1478,7 +1476,7 @@ get "/feed/channel/:ucid" do |env|
|
|||
|
||||
xml.element("media:group") do
|
||||
xml.element("media:title") { xml.text video.title }
|
||||
xml.element("media:thumbnail", url: "https://i.ytimg.com/vi/#{video.id}/mqdefault.jpg",
|
||||
xml.element("media:thumbnail", url: "/vi/#{video.id}/mqdefault.jpg",
|
||||
width: "320", height: "180")
|
||||
xml.element("media:description") { xml.text video.description }
|
||||
end
|
||||
|
@ -1583,7 +1581,7 @@ get "/feed/private" do |env|
|
|||
|
||||
xml.element("media:group") do
|
||||
xml.element("media:title") { xml.text video.title }
|
||||
xml.element("media:thumbnail", url: "https://i.ytimg.com/vi/#{video.id}/mqdefault.jpg",
|
||||
xml.element("media:thumbnail", url: "/vi/#{video.id}/mqdefault.jpg",
|
||||
width: "320", height: "180")
|
||||
end
|
||||
end
|
||||
|
@ -2969,6 +2967,46 @@ get "/videoplayback" do |env|
|
|||
end
|
||||
end
|
||||
|
||||
get "/vi/:id/:name" do |env|
|
||||
id = env.params.url["id"]
|
||||
name = env.params.url["name"]
|
||||
|
||||
host = "https://i.ytimg.com"
|
||||
client = make_client(URI.parse(host))
|
||||
|
||||
if name == "maxres.jpg"
|
||||
VIDEO_THUMBNAILS.each do |thumb|
|
||||
if client.head("/vi/#{id}/#{thumb[:url]}.jpg").status_code == 200
|
||||
name = thumb[:url] + ".jpg"
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
url = "/vi/#{id}/#{name}"
|
||||
|
||||
client.get(url) do |response|
|
||||
env.response.status_code = response.status_code
|
||||
|
||||
response.headers.each do |key, value|
|
||||
env.response.headers[key] = value
|
||||
end
|
||||
|
||||
env.response.headers["Access-Control-Allow-Origin"] = "*"
|
||||
|
||||
begin
|
||||
chunk_size = 4096
|
||||
size = 1
|
||||
while size > 0
|
||||
size = IO.copy(response.body_io, env.response.output, chunk_size)
|
||||
env.response.flush
|
||||
Fiber.yield
|
||||
end
|
||||
rescue ex
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
error 404 do |env|
|
||||
error_message = "404 Page not found"
|
||||
templated "error"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue