From 09d78c9d3ab42ee8e80e96017fcb7d7434c79fde Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 28 Jul 2018 21:56:30 -0500 Subject: [PATCH] Add fix for videos that don't have description --- src/invidious.cr | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 5fd852b5..e7928e1b 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -902,10 +902,16 @@ get "/api/v1/trending" do |env| published, views = node.xpath_nodes(%q(.//ul[@class="yt-lockup-meta-info"]/li)) views = views.content.rchop(" views").delete(",").to_i - descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])).not_nil!.to_s - description = descriptionHtml.gsub("
", "\n") - description = description.gsub("
", "\n") - description = XML.parse_html(description) + descriptionHtml = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])) + if !descriptionHtml + description = "" + descriptionHtml = "" + else + descriptionHtml = descriptionHtml.to_s + description = descriptionHtml.gsub("
", "\n") + description = description.gsub("
", "\n") + description = XML.parse_html(description).content.strip("\n ") + end published = published.content.split(" ")[-3..-1].join(" ") published = decode_date(published) @@ -936,7 +942,7 @@ get "/api/v1/trending" do |env| json.field "author", author json.field "authorUrl", author_url json.field "published", published.epoch - json.field "description", description.content + json.field "description", description json.field "descriptionHtml", descriptionHtml 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 = view_count.content.rchop(" views").delete(",").to_i - descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])).not_nil!.to_s - description = descriptionHtml.gsub("
", "\n") - description = description.gsub("
", "\n") - description = XML.parse_html(description).content.strip("\n ") + descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])) + if !descriptionHtml + description = "" + descriptionHtml = "" + else + descriptionHtml = descriptionHtml.to_s + description = descriptionHtml.gsub("
", "\n") + description = description.gsub("
", "\n") + description = XML.parse_html(description).content.strip("\n ") + end published = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1])) 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 = view_count.content.rchop(" views").delete(",").to_i - descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])).not_nil!.to_s - description = descriptionHtml.gsub("
", "\n") - description = description.gsub("
", "\n") - description = XML.parse_html(description).content.strip("\n ") + descriptionHtml = item.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])) + if !descriptionHtml + description = "" + descriptionHtml = "" + else + descriptionHtml = descriptionHtml.to_s + description = descriptionHtml.gsub("
", "\n") + description = description.gsub("
", "\n") + description = XML.parse_html(description).content.strip("\n ") + end published = item.xpath_node(%q(.//div[@class="yt-lockup-meta"]/ul/li[1])) if !published