Add descriptionHtml to playlists

pull/186/head
Omar Roth 6 years ago
parent 40028e1462
commit e1bf7fa6cc

@ -2261,21 +2261,26 @@ get "/api/v1/channels/:ucid" do |env|
author = channel_html.xpath_node(%q(//a[contains(@class, "branded-page-header-title-link")])).not_nil!.content author = channel_html.xpath_node(%q(//a[contains(@class, "branded-page-header-title-link")])).not_nil!.content
author_url = channel_html.xpath_node(%q(//a[@class="channel-header-profile-image-container spf-link"])).not_nil!["href"] author_url = channel_html.xpath_node(%q(//a[@class="channel-header-profile-image-container spf-link"])).not_nil!["href"]
author_thumbnail = channel_html.xpath_node(%q(//img[@class="channel-header-profile-image"])).not_nil!["src"] author_thumbnail = channel_html.xpath_node(%q(//img[@class="channel-header-profile-image"])).not_nil!["src"]
description = channel_html.xpath_node(%q(//meta[@itemprop="description"])).not_nil!["content"] description_html = channel_html.xpath_node(%q(//div[contains(@class,"about-description")]))
description_html, description = html_to_content(description_html)
paid = channel_html.xpath_node(%q(//meta[@itemprop="paid"])).not_nil!["content"] == "True" paid = channel_html.xpath_node(%q(//meta[@itemprop="paid"])).not_nil!["content"] == "True"
is_family_friendly = channel_html.xpath_node(%q(//meta[@itemprop="isFamilyFriendly"])).not_nil!["content"] == "True" is_family_friendly = channel_html.xpath_node(%q(//meta[@itemprop="isFamilyFriendly"])).not_nil!["content"] == "True"
allowed_regions = channel_html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).not_nil!["content"].split(",") allowed_regions = channel_html.xpath_node(%q(//meta[@itemprop="regionsAllowed"])).not_nil!["content"].split(",")
anchor = channel_html.xpath_nodes(%q(//span[@class="about-stat"])) total_views = 0_i64
if anchor[0].content.includes? "views" sub_count = 0_i64
sub_count = 0 joined = Time.epoch(0)
total_views = anchor[0].content.delete("views •,").to_i64 metadata = channel_html.xpath_nodes(%q(//span[@class="about-stat"]))
joined = Time.parse(anchor[1].content.lchop("Joined "), "%b %-d, %Y", Time::Location.local) metadata.each do |item|
else case item.content
sub_count = anchor[0].content.delete("subscribers").delete(",").to_i64 when .includes? "views"
total_views = anchor[1].content.delete("views •,").to_i64 total_views = item.content.delete("views •,").to_i64
joined = Time.parse(anchor[2].content.lchop("Joined "), "%b %-d, %Y", Time::Location.local) when .includes? "subscribers"
sub_count = item.content.delete("subscribers").delete(",").to_i64
when .includes? "Joined"
joined = Time.parse(item.content.lchop("Joined "), "%b %-d, %Y", Time::Location.local)
end
end end
channel_info = JSON.build do |json| channel_info = JSON.build do |json|
@ -2326,6 +2331,8 @@ get "/api/v1/channels/:ucid" do |env|
json.field "isFamilyFriendly", is_family_friendly json.field "isFamilyFriendly", is_family_friendly
json.field "description", description json.field "description", description
json.field "descriptionHtml", description_html
json.field "allowedRegions", allowed_regions json.field "allowedRegions", allowed_regions
json.field "latestVideos" do json.field "latestVideos" do
@ -2518,6 +2525,7 @@ get "/api/v1/playlists/:plid" do |env|
json.field "authorUrl", "/channel/#{playlist.ucid}" json.field "authorUrl", "/channel/#{playlist.ucid}"
json.field "description", playlist.description json.field "description", playlist.description
json.field "descriptionHtml", playlist.description_html
json.field "videoCount", playlist.video_count json.field "videoCount", playlist.video_count
json.field "viewCount", playlist.views json.field "viewCount", playlist.views

@ -1,13 +1,14 @@
class Playlist class Playlist
add_mapping({ add_mapping({
title: String, title: String,
id: String, id: String,
author: String, author: String,
ucid: String, ucid: String,
description: String, description: String,
video_count: Int32, description_html: String,
views: Int64, video_count: Int32,
updated: Time, views: Int64,
updated: Time,
}) })
end end
@ -123,17 +124,8 @@ def fetch_playlist(plid)
title = document.xpath_node(%q(//h1[@class="pl-header-title"])).not_nil!.content title = document.xpath_node(%q(//h1[@class="pl-header-title"])).not_nil!.content
title = title.strip(" \n") title = title.strip(" \n")
description = document.xpath_node(%q(//span[@class="pl-header-description-text"]/div/div[1])) description_html = document.xpath_node(%q(//span[@class="pl-header-description-text"]/div/div[1]))
description ||= document.xpath_node(%q(//span[@class="pl-header-description-text"])) description, description_html = html_to_content(description_html)
if description
description = description.to_xml.strip(" \n")
description = description.split("<button ")[0]
description = fill_links(description, "https", "www.youtube.com")
description = replace_links(description)
else
description = ""
end
anchor = document.xpath_node(%q(//ul[@class="pl-header-details"])).not_nil! anchor = document.xpath_node(%q(//ul[@class="pl-header-details"])).not_nil!
author = anchor.xpath_node(%q(.//li[1]/a)).not_nil!.content author = anchor.xpath_node(%q(.//li[1]/a)).not_nil!.content
@ -151,6 +143,7 @@ def fetch_playlist(plid)
author, author,
ucid, ucid,
description, description,
description_html,
video_count, video_count,
views, views,
updated updated

Loading…
Cancel
Save