Add fix for videos that don't have description

This commit is contained in:
Omar Roth 2018-07-28 21:56:30 -05:00
parent 573e909785
commit 09d78c9d3a

View file

@ -902,10 +902,16 @@ get "/api/v1/trending" do |env|
published, views = node.xpath_nodes(%q(.//ul[@class="yt-lockup-meta-info"]/li)) published, views = node.xpath_nodes(%q(.//ul[@class="yt-lockup-meta-info"]/li))
views = views.content.rchop(" views").delete(",").to_i views = views.content.rchop(" views").delete(",").to_i
descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])).not_nil!.to_s descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
description = descriptionHtml.gsub("<br>", "\n") if !descriptionHtml
description = description.gsub("<br/>", "\n") description = ""
description = XML.parse_html(description) descriptionHtml = ""
else
descriptionHtml = descriptionHtml.to_s
description = descriptionHtml.gsub("<br>", "\n")
description = description.gsub("<br/>", "\n")
description = XML.parse_html(description).content.strip("\n ")
end
published = published.content.split(" ")[-3..-1].join(" ") published = published.content.split(" ")[-3..-1].join(" ")
published = decode_date(published) published = decode_date(published)
@ -936,7 +942,7 @@ get "/api/v1/trending" do |env|
json.field "author", author json.field "author", author
json.field "authorUrl", author_url json.field "authorUrl", author_url
json.field "published", published.epoch json.field "published", published.epoch
json.field "description", description.content json.field "description", description
json.field "descriptionHtml", descriptionHtml json.field "descriptionHtml", descriptionHtml
end end
end end
@ -1133,10 +1139,16 @@ get "/api/v1/channels/:ucid/videos" do |env|
view_count = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[2])).not_nil! view_count = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[2])).not_nil!
view_count = view_count.content.rchop(" views").delete(",").to_i view_count = view_count.content.rchop(" views").delete(",").to_i
descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])).not_nil!.to_s descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
description = descriptionHtml.gsub("<br>", "\n") if !descriptionHtml
description = description.gsub("<br/>", "\n") description = ""
description = XML.parse_html(description).content.strip("\n ") descriptionHtml = ""
else
descriptionHtml = descriptionHtml.to_s
description = descriptionHtml.gsub("<br>", "\n")
description = description.gsub("<br/>", "\n")
description = XML.parse_html(description).content.strip("\n ")
end
published = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1])) published = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1]))
if !published if !published
@ -1835,10 +1847,16 @@ get "/feed/channel/:ucid" do |env|
view_count = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[2])).not_nil! view_count = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[2])).not_nil!
view_count = view_count.content.rchop(" views").delete(",").to_i view_count = view_count.content.rchop(" views").delete(",").to_i
descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])).not_nil!.to_s descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
description = descriptionHtml.gsub("<br>", "\n") if !descriptionHtml
description = description.gsub("<br/>", "\n") description = ""
description = XML.parse_html(description).content.strip("\n ") descriptionHtml = ""
else
descriptionHtml = descriptionHtml.to_s
description = descriptionHtml.gsub("<br>", "\n")
description = description.gsub("<br/>", "\n")
description = XML.parse_html(description).content.strip("\n ")
end
published = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1])) published = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1]))
if !published if !published