summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-11-25 18:13:11 -0600
committerOmar Roth <omarroth@hotmail.com>2018-11-25 18:13:11 -0600
commit18bb397c7d10bb782f2a3c7f99390974e6479aa3 (patch)
treef5f0fdcb848a118619c8a236035f80ac3c8826b7
parent3c98601f35270fd3cf06b138de17b2c5e6919521 (diff)
downloadinvidious-18bb397c7d10bb782f2a3c7f99390974e6479aa3.tar.gz
invidious-18bb397c7d10bb782f2a3c7f99390974e6479aa3.tar.bz2
invidious-18bb397c7d10bb782f2a3c7f99390974e6479aa3.zip
Add '/api/v1/popular'
-rw-r--r--src/invidious.cr34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index e1b337b5..cd1da476 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -2606,6 +2606,40 @@ get "/api/v1/trending" do |env|
videos
end
+get "/api/v1/popular" do |env|
+ videos = JSON.build do |json|
+ json.array do
+ popular_videos.each do |video|
+ json.object do
+ json.field "title", video.title
+ json.field "videoId", video.id
+ json.field "videoThumbnails" do
+ generate_thumbnails(json, video.id)
+ end
+
+ json.field "lengthSeconds", video.info["length_seconds"].to_i
+ json.field "viewCount", video.views
+
+ json.field "author", video.author
+ json.field "authorId", video.ucid
+ json.field "authorUrl", "/channel/#{video.ucid}"
+ json.field "published", video.published.to_unix
+ json.field "publishedText", "#{recode_date(video.published)} ago"
+
+ 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 "/api/v1/top" do |env|
videos = JSON.build do |json|
json.array do