Use host_url for generating thumbnails
This commit is contained in:
parent
c69fbb72d3
commit
c4d77bc18a
|
@ -2826,7 +2826,7 @@ get "/api/v1/videos/:id" do |env|
|
|||
json.field "title", video.title
|
||||
json.field "videoId", video.id
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
video.description, description = html_to_content(video.description)
|
||||
|
@ -2989,7 +2989,7 @@ get "/api/v1/videos/:id" do |env|
|
|||
json.field "videoId", rv["id"]
|
||||
json.field "title", rv["title"]
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, rv["id"])
|
||||
generate_thumbnails(json, rv["id"], config, Kemal.config)
|
||||
end
|
||||
json.field "author", rv["author"]
|
||||
json.field "lengthSeconds", rv["length_seconds"].to_i
|
||||
|
@ -3031,7 +3031,7 @@ get "/api/v1/trending" do |env|
|
|||
json.field "title", video.title
|
||||
json.field "videoId", video.id
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "lengthSeconds", video.length_seconds
|
||||
|
@ -3072,7 +3072,7 @@ get "/api/v1/popular" do |env|
|
|||
json.field "title", video.title
|
||||
json.field "videoId", video.id
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "lengthSeconds", video.length_seconds
|
||||
|
@ -3111,7 +3111,7 @@ get "/api/v1/top" do |env|
|
|||
json.field "title", video.title
|
||||
json.field "videoId", video.id
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "lengthSeconds", video.info["length_seconds"].to_i
|
||||
|
@ -3294,7 +3294,7 @@ get "/api/v1/channels/:ucid" do |env|
|
|||
end
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "description", video.description
|
||||
|
@ -3392,7 +3392,7 @@ end
|
|||
end
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "description", video.description
|
||||
|
@ -3444,7 +3444,7 @@ end
|
|||
json.field "authorUrl", "/channel/#{ucid}"
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "description", video.description
|
||||
|
@ -3515,7 +3515,7 @@ end
|
|||
json.field "lengthSeconds", video.length_seconds
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3568,7 +3568,7 @@ get "/api/v1/channels/search/:ucid" do |env|
|
|||
json.field "authorUrl", "/channel/#{item.ucid}"
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, item.id)
|
||||
generate_thumbnails(json, item.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "description", item.description
|
||||
|
@ -3600,7 +3600,7 @@ get "/api/v1/channels/search/:ucid" do |env|
|
|||
json.field "lengthSeconds", video.length_seconds
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3697,7 +3697,7 @@ get "/api/v1/search" do |env|
|
|||
json.field "authorUrl", "/channel/#{item.ucid}"
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, item.id)
|
||||
generate_thumbnails(json, item.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "description", item.description
|
||||
|
@ -3729,7 +3729,7 @@ get "/api/v1/search" do |env|
|
|||
json.field "lengthSeconds", video.length_seconds
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3845,7 +3845,7 @@ get "/api/v1/playlists/:plid" do |env|
|
|||
json.field "authorUrl", "/channel/#{video.ucid}"
|
||||
|
||||
json.field "videoThumbnails" do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
|
||||
json.field "index", video.index
|
||||
|
@ -3921,7 +3921,7 @@ get "/api/v1/mixes/:rdid" do |env|
|
|||
|
||||
json.field "videoThumbnails" do
|
||||
json.array do
|
||||
generate_thumbnails(json, video.id)
|
||||
generate_thumbnails(json, video.id, config, Kemal.config)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4332,7 +4332,7 @@ get "/vi/:id/:name" do |env|
|
|||
client = make_client(URI.parse(host))
|
||||
|
||||
if name == "maxres.jpg"
|
||||
VIDEO_THUMBNAILS.each do |thumb|
|
||||
build_thumbnails(id, config, Kemal.config).each do |thumb|
|
||||
if client.head("/vi/#{id}/#{thumb[:url]}.jpg").status_code == 200
|
||||
name = thumb[:url] + ".jpg"
|
||||
break
|
||||
|
|
|
@ -136,18 +136,6 @@ BYPASS_REGIONS = {
|
|||
"TR",
|
||||
}
|
||||
|
||||
VIDEO_THUMBNAILS = {
|
||||
{name: "maxres", host: "#{CONFIG.domain}", url: "maxres", height: 720, width: 1280},
|
||||
{name: "maxresdefault", host: "i.ytimg.com", url: "maxresdefault", height: 720, width: 1280},
|
||||
{name: "sddefault", host: "i.ytimg.com", url: "sddefault", height: 480, width: 640},
|
||||
{name: "high", host: "i.ytimg.com", url: "hqdefault", height: 360, width: 480},
|
||||
{name: "medium", host: "i.ytimg.com", url: "mqdefault", height: 180, width: 320},
|
||||
{name: "default", host: "i.ytimg.com", url: "default", height: 90, width: 120},
|
||||
{name: "start", host: "i.ytimg.com", url: "1", height: 90, width: 120},
|
||||
{name: "middle", host: "i.ytimg.com", url: "2", height: 90, width: 120},
|
||||
{name: "end", host: "i.ytimg.com", url: "3", height: 90, width: 120},
|
||||
}
|
||||
|
||||
# See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L380-#L476
|
||||
VIDEO_FORMATS = {
|
||||
"5" => {"ext" => "flv", "width" => 400, "height" => 240, "acodec" => "mp3", "abr" => 64, "vcodec" => "h263"},
|
||||
|
@ -826,12 +814,26 @@ def process_video_params(query, preferences)
|
|||
return params
|
||||
end
|
||||
|
||||
def generate_thumbnails(json, id)
|
||||
def build_thumbnails(id, config, kemal_config)
|
||||
return {
|
||||
{name: "maxres", host: "#{make_host_url(config, kemal_config)}", url: "maxres", height: 720, width: 1280},
|
||||
{name: "maxresdefault", host: "https://i.ytimg.com", url: "maxresdefault", height: 720, width: 1280},
|
||||
{name: "sddefault", host: "https://i.ytimg.com", url: "sddefault", height: 480, width: 640},
|
||||
{name: "high", host: "https://i.ytimg.com", url: "hqdefault", height: 360, width: 480},
|
||||
{name: "medium", host: "https://i.ytimg.com", url: "mqdefault", height: 180, width: 320},
|
||||
{name: "default", host: "https://i.ytimg.com", url: "default", height: 90, width: 120},
|
||||
{name: "start", host: "https://i.ytimg.com", url: "1", height: 90, width: 120},
|
||||
{name: "middle", host: "https://i.ytimg.com", url: "2", height: 90, width: 120},
|
||||
{name: "end", host: "https://i.ytimg.com", url: "3", height: 90, width: 120},
|
||||
}
|
||||
end
|
||||
|
||||
def generate_thumbnails(json, id, config, kemal_config)
|
||||
json.array do
|
||||
VIDEO_THUMBNAILS.each do |thumbnail|
|
||||
build_thumbnails(id, config, kemal_config).each do |thumbnail|
|
||||
json.object do
|
||||
json.field "quality", thumbnail[:name]
|
||||
json.field "url", "https://#{thumbnail[:host]}/vi/#{id}/#{thumbnail["url"]}.jpg"
|
||||
json.field "url", "#{thumbnail[:host]}/vi/#{id}/#{thumbnail["url"]}.jpg"
|
||||
json.field "width", thumbnail[:width]
|
||||
json.field "height", thumbnail[:height]
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue