summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-07-27 09:49:34 -0500
committerOmar Roth <omarroth@hotmail.com>2018-07-27 10:00:29 -0500
commitff563d075aa9c5f8a262986036a7223f08de449d (patch)
treeebe958a17e5247b6b889cd9a202d0689e0d51a17
parent8eb5d153b58177e8496148d355cfcad748383e55 (diff)
downloadinvidious-ff563d075aa9c5f8a262986036a7223f08de449d.tar.gz
invidious-ff563d075aa9c5f8a262986036a7223f08de449d.tar.bz2
invidious-ff563d075aa9c5f8a262986036a7223f08de449d.zip
Add '/api/v1/top'
-rw-r--r--src/invidious.cr46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index 4a944c7b..2ae210a8 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -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"]