Add 'videoCount' to playlists in search

This commit is contained in:
Omar Roth 2018-09-22 11:14:57 -05:00
parent f80f4f2521
commit 1ab04638e3
2 changed files with 6 additions and 1 deletions

View File

@ -2645,6 +2645,7 @@ get "/api/v1/channels/search/:ucid" do |env|
json.field "authorId", item.ucid json.field "authorId", item.ucid
json.field "authorUrl", "/channel/#{item.ucid}" json.field "authorUrl", "/channel/#{item.ucid}"
json.field "videoCount", item.video_count
json.field "videos" do json.field "videos" do
json.array do json.array do
item.videos.each do |video| item.videos.each do |video|
@ -2765,6 +2766,7 @@ get "/api/v1/search" do |env|
json.field "authorId", item.ucid json.field "authorId", item.ucid
json.field "authorUrl", "/channel/#{item.ucid}" json.field "authorUrl", "/channel/#{item.ucid}"
json.field "videoCount", item.video_count
json.field "videos" do json.field "videos" do
json.array do json.array do
item.videos.each do |video| item.videos.each do |video|

View File

@ -238,7 +238,10 @@ def extract_items(nodeset, ucid = nil)
when .includes? "yt-lockup-playlist" when .includes? "yt-lockup-playlist"
plid = HTTP::Params.parse(URI.parse(id).query.not_nil!)["list"] plid = HTTP::Params.parse(URI.parse(id).query.not_nil!)["list"]
anchor = node.xpath_node(%q(.//ul[@class="yt-lockup-meta-info"]/li/a)) anchor = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-meta")]/a))
if !anchor
anchor = node.xpath_node(%q(.//ul[@class="yt-lockup-meta-info"]/li/a))
end
if anchor if anchor
video_count = anchor.content.match(/View full playlist \((?<count>\d+)/).try &.["count"].to_i? video_count = anchor.content.match(/View full playlist \((?<count>\d+)/).try &.["count"].to_i?
end end