mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2026-02-20 15:36:06 +00:00
Extract API routes from invidious.cr (2/?)
- Video playback endpoints - Search feed api - Video info api
This commit is contained in:
46
src/invidious/routes/api/v1/feeds.cr
Normal file
46
src/invidious/routes/api/v1/feeds.cr
Normal file
@@ -0,0 +1,46 @@
|
||||
module Invidious::Routes::APIv1
|
||||
def self.trending(env)
|
||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
region = env.params.query["region"]?
|
||||
trending_type = env.params.query["type"]?
|
||||
|
||||
begin
|
||||
trending, plid = fetch_trending(trending_type, region, locale)
|
||||
rescue ex
|
||||
return error_json(500, ex)
|
||||
end
|
||||
|
||||
videos = JSON.build do |json|
|
||||
json.array do
|
||||
trending.each do |video|
|
||||
video.to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
videos
|
||||
end
|
||||
|
||||
def self.popular(env)
|
||||
locale = LOCALES[env.get("preferences").as(Preferences).locale]?
|
||||
|
||||
env.response.content_type = "application/json"
|
||||
|
||||
if !CONFIG.popular_enabled
|
||||
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
|
||||
env.response.status_code = 400
|
||||
return error_message
|
||||
end
|
||||
|
||||
JSON.build do |json|
|
||||
json.array do
|
||||
popular_videos.each do |video|
|
||||
video.to_json(locale, json)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user