forked from midou/invidious
Update API to match documented schema
This commit is contained in:
parent
b78c773e5d
commit
626aed2d07
106
src/invidious.cr
106
src/invidious.cr
@ -1793,18 +1793,17 @@ get "/api/v1/videos/:id" do |env|
|
|||||||
json.field "title", video.title
|
json.field "title", video.title
|
||||||
json.field "videoId", video.id
|
json.field "videoId", video.id
|
||||||
json.field "videoThumbnails" do
|
json.field "videoThumbnails" do
|
||||||
json.object do
|
qualities = [{name: "default", url: "default", width: 120, height: 90},
|
||||||
qualities = [{name: "default", url: "default", width: 120, height: 90},
|
{name: "high", url: "hqdefault", width: 480, height: 360},
|
||||||
{name: "high", url: "hqdefault", width: 480, height: 360},
|
{name: "medium", url: "mqdefault", width: 320, height: 180},
|
||||||
{name: "medium", url: "mqdefault", width: 320, height: 180},
|
]
|
||||||
]
|
json.array do
|
||||||
qualities.each do |quality|
|
qualities.each do |quality|
|
||||||
json.field quality[:name] do
|
json.object do
|
||||||
json.object do
|
json.field "quality", quality[:name]
|
||||||
json.field "url", "https://i.ytimg.com/vi/#{id}/#{quality["url"]}.jpg"
|
json.field "url", "https://i.ytimg.com/vi/#{id}/#{quality["url"]}.jpg"
|
||||||
json.field "width", quality[:width]
|
json.field "width", quality[:width]
|
||||||
json.field "height", quality[:height]
|
json.field "height", quality[:height]
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1936,24 +1935,21 @@ get "/api/v1/videos/:id" do |env|
|
|||||||
json.field "videoId", rv["id"]
|
json.field "videoId", rv["id"]
|
||||||
json.field "title", rv["title"]
|
json.field "title", rv["title"]
|
||||||
json.field "videoThumbnails" do
|
json.field "videoThumbnails" do
|
||||||
json.object do
|
qualities = [{name: "default", url: "default", width: 120, height: 90},
|
||||||
qualities = [{name: "default", url: "default", width: 120, height: 90},
|
{name: "high", url: "hqdefault", width: 480, height: 360},
|
||||||
{name: "high", url: "hqdefault", width: 480, height: 360},
|
{name: "medium", url: "mqdefault", width: 320, height: 180},
|
||||||
{name: "medium", url: "mqdefault", width: 320, height: 180},
|
]
|
||||||
]
|
json.array do
|
||||||
qualities.each do |quality|
|
qualities.each do |quality|
|
||||||
json.field quality[:name] do
|
json.field "quality", quality[:name]
|
||||||
json.object do
|
json.field "url", "https://i.ytimg.com/vi/#{rv["id"]}/#{quality["url"]}.jpg"
|
||||||
json.field "url", "https://i.ytimg.com/vi/#{rv["id"]}/#{quality["url"]}.jpg"
|
json.field "width", quality[:width]
|
||||||
json.field "width", quality[:width]
|
json.field "height", quality[:height]
|
||||||
json.field "height", quality[:height]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
json.field "author", rv["author"]
|
json.field "author", rv["author"]
|
||||||
json.field "lengthSeconds", rv["length_seconds"]
|
json.field "lengthSeconds", rv["length_seconds"].to_i
|
||||||
json.field "viewCountText", rv["short_view_count_text"].rchop(" views")
|
json.field "viewCountText", rv["short_view_count_text"].rchop(" views")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1974,22 +1970,30 @@ get "/api/v1/trending" do |env|
|
|||||||
videos = JSON.build do |json|
|
videos = JSON.build do |json|
|
||||||
json.array do
|
json.array do
|
||||||
trending.xpath_nodes(%q(//ul/li[@class="expanded-shelf-content-item-wrapper"])).each do |node|
|
trending.xpath_nodes(%q(//ul/li[@class="expanded-shelf-content-item-wrapper"])).each do |node|
|
||||||
length_seconds = decode_length_seconds(node.xpath_node(%q(.//span[@class="video-time"])).not_nil!.content)
|
anchor = node.xpath_node(%q(.//h3/a)).not_nil!
|
||||||
|
|
||||||
video = node.xpath_node(%q(.//h3/a)).not_nil!
|
title = anchor.content
|
||||||
title = video.content
|
id = anchor["href"].lchop("/watch?v=")
|
||||||
id = video["href"].lchop("/watch?v=")
|
|
||||||
|
|
||||||
channel = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-byline")]/a)).not_nil!
|
anchor = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-byline")]/a)).not_nil!
|
||||||
author = channel.content
|
author = anchor.content
|
||||||
author_url = channel["href"]
|
author_url = anchor["href"]
|
||||||
|
|
||||||
published, view_count = node.xpath_nodes(%q(.//ul[@class="yt-lockup-meta-info"]/li))
|
metadata = node.xpath_nodes(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li))
|
||||||
view_count = view_count.content.rchop(" views")
|
if metadata.size == 0
|
||||||
if view_count == "No"
|
next
|
||||||
view_count = 0
|
elsif metadata.size == 1
|
||||||
|
view_count = metadata[0].content.rchop(" watching").delete(",").to_i64
|
||||||
|
published = Time.now
|
||||||
else
|
else
|
||||||
view_count = view_count.delete(",").to_i64
|
published = decode_date(metadata[0].content)
|
||||||
|
|
||||||
|
view_count = metadata[1].content.rchop(" views")
|
||||||
|
if view_count == "No"
|
||||||
|
view_count = 0_i64
|
||||||
|
else
|
||||||
|
view_count = view_count.delete(",").to_i64
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
||||||
@ -2003,8 +2007,7 @@ get "/api/v1/trending" do |env|
|
|||||||
description = XML.parse_html(description).content.strip("\n ")
|
description = XML.parse_html(description).content.strip("\n ")
|
||||||
end
|
end
|
||||||
|
|
||||||
published = published.content.split(" ")[-3..-1].join(" ")
|
length_seconds = decode_length_seconds(node.xpath_node(%q(.//span[@class="video-time"])).not_nil!.content)
|
||||||
published = decode_date(published).epoch
|
|
||||||
|
|
||||||
json.object do
|
json.object do
|
||||||
json.field "title", title
|
json.field "title", title
|
||||||
@ -2259,22 +2262,21 @@ get "/api/v1/channels/:ucid/videos" do |env|
|
|||||||
title = anchor.content.strip
|
title = anchor.content.strip
|
||||||
video_id = anchor["href"].lchop("/watch?v=")
|
video_id = anchor["href"].lchop("/watch?v=")
|
||||||
|
|
||||||
published = node.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[1]))
|
metadata = node.xpath_nodes(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li))
|
||||||
if !published
|
if metadata.size == 0
|
||||||
next
|
next
|
||||||
end
|
elsif metadata.size == 1
|
||||||
published = published.content
|
view_count = metadata[0].content.rchop(" watching").delete(",").to_i64
|
||||||
if published.ends_with? "watching"
|
published = Time.now
|
||||||
next
|
|
||||||
end
|
|
||||||
published = decode_date(published).epoch
|
|
||||||
|
|
||||||
view_count = node.xpath_node(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li[2])).not_nil!
|
|
||||||
view_count = view_count.content.rchop(" views")
|
|
||||||
if view_count == "No"
|
|
||||||
view_count = 0
|
|
||||||
else
|
else
|
||||||
view_count = view_count.delete(",").to_i64
|
published = decode_date(metadata[0].content)
|
||||||
|
|
||||||
|
view_count = metadata[1].content.rchop(" views")
|
||||||
|
if view_count == "No"
|
||||||
|
view_count = 0_i64
|
||||||
|
else
|
||||||
|
view_count = view_count.delete(",").to_i64
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
|
||||||
|
Loading…
Reference in New Issue
Block a user