From ff563d075aa9c5f8a262986036a7223f08de449d Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 27 Jul 2018 09:49:34 -0500 Subject: [PATCH] Add '/api/v1/top' --- src/invidious.cr | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) 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("
", "\n") + description = description.gsub("
", "\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"]