mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Add '/api/v1/top'
This commit is contained in:
parent
8eb5d153b5
commit
ff563d075a
1 changed files with 46 additions and 0 deletions
|
@ -958,6 +958,52 @@ get "/api/v1/trending" do |env|
|
|||
videos
|
||||
end
|
||||
|
||||
get "/api/v1/top" do |env|
|
||||
videos = JSON.build do |json|
|
||||
json.array do
|
||||
top_videos.each do |video|
|
||||
json.object do
|
||||
json.field "title", video.title
|
||||
json.field "videoId", video.id
|
||||
json.field "videoThumbnails" do
|
||||
json.object do
|
||||
qualities = [{name: "default", url: "default", width: 120, height: 90},
|
||||
{name: "high", url: "hqdefault", width: 480, height: 360},
|
||||
{name: "medium", url: "mqdefault", width: 320, height: 180},
|
||||
]
|
||||
qualities.each do |quality|
|
||||
json.field quality[:name] do
|
||||
json.object do
|
||||
json.field "url", "https://i.ytimg.com/vi/#{video.id}/#{quality["url"]}.jpg"
|
||||
json.field "width", quality[:width]
|
||||
json.field "height", quality[:height]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
json.field "lengthSeconds", video.info["length_seconds"].to_i
|
||||
json.field "views", video.views
|
||||
|
||||
json.field "author", video.author
|
||||
json.field "authorUrl", "/channel/#{video.ucid}"
|
||||
json.field "published", video.published.epoch
|
||||
|
||||
description = video.description.gsub("<br>", "\n")
|
||||
description = description.gsub("<br/>", "\n")
|
||||
description = XML.parse_html(description)
|
||||
json.field "description", description.content
|
||||
json.field "descriptionHtml", video.description
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
videos
|
||||
end
|
||||
|
||||
get "/embed/:id" do |env|
|
||||
if env.params.url["id"]?
|
||||
id = env.params.url["id"]
|
||||
|
|
Loading…
Reference in a new issue