mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-26 15:37:23 +00:00
Add /api/v1/channels/latest/:ucid
This commit is contained in:
parent
58fb74179b
commit
a210327318
@ -3129,6 +3129,56 @@ end
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
["/api/v1/channels/:ucid/latest", "/api/v1/channels/latest/:ucid"].each do |route|
|
||||||
|
get route do |env|
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
|
ucid = env.params.url["ucid"]
|
||||||
|
|
||||||
|
begin
|
||||||
|
videos = get_latest_videos(ucid)
|
||||||
|
rescue ex
|
||||||
|
error_message = {"error" => ex.message}.to_json
|
||||||
|
halt env, status_code: 500, response: error_message
|
||||||
|
end
|
||||||
|
|
||||||
|
response = JSON.build do |json|
|
||||||
|
json.array do
|
||||||
|
videos.each do |video|
|
||||||
|
json.object do
|
||||||
|
json.field "title", video.title
|
||||||
|
json.field "videoId", video.id
|
||||||
|
|
||||||
|
json.field "authorId", ucid
|
||||||
|
json.field "authorUrl", "/channel/#{ucid}"
|
||||||
|
|
||||||
|
json.field "videoThumbnails" do
|
||||||
|
generate_thumbnails(json, video.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
json.field "description", video.description
|
||||||
|
json.field "descriptionHtml", video.description_html
|
||||||
|
|
||||||
|
json.field "viewCount", video.views
|
||||||
|
json.field "published", video.published.to_unix
|
||||||
|
json.field "publishedText", "#{recode_date(video.published)} ago"
|
||||||
|
json.field "lengthSeconds", video.length_seconds
|
||||||
|
json.field "liveNow", video.live_now
|
||||||
|
json.field "paid", video.paid
|
||||||
|
json.field "premium", video.premium
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if env.params.query["pretty"]? && env.params.query["pretty"] == "1"
|
||||||
|
JSON.parse(response).to_pretty_json
|
||||||
|
else
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
get "/api/v1/channels/search/:ucid" do |env|
|
get "/api/v1/channels/search/:ucid" do |env|
|
||||||
locale = LOCALES[env.get("locale").as(String)]?
|
locale = LOCALES[env.get("locale").as(String)]?
|
||||||
|
|
||||||
|
@ -460,3 +460,21 @@ def get_60_videos(ucid, page, auto_generated, sort_by = "newest")
|
|||||||
|
|
||||||
return videos, count
|
return videos, count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_latest_videos(ucid)
|
||||||
|
client = make_client(YT_URL)
|
||||||
|
videos = [] of SearchVideo
|
||||||
|
|
||||||
|
url = produce_channel_videos_url(ucid, 0)
|
||||||
|
response = client.get(url)
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
|
||||||
|
if json["content_html"]? && !json["content_html"].as_s.empty?
|
||||||
|
document = XML.parse_html(json["content_html"].as_s)
|
||||||
|
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")]))
|
||||||
|
|
||||||
|
videos = extract_videos(nodeset, ucid)
|
||||||
|
end
|
||||||
|
|
||||||
|
return videos
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user