Invidious is an alternative front-end to YouTube
Parse HTML properly instead of relying on regexes
Omar Rothd573461a671a
diff --git a/src/helpers.cr b/src/helpers.crindex 45204132..094d7dc1 100644--- a/src/helpers.cr+++ b/src/helpers.cr@@ -132,8 +132,19 @@ def fetch_video(id, client)dislikes = dislikes ? dislikes.content.delete(",").to_i : 0description = html.xpath_node(%q(//p[@id="eow-description"]))+ if description+ description.xpath_nodes(%q(//a/@href)).each do |match|+ uri = URI.parse(match.content)++ if uri.host =~ /(www\.)?youtube.com/+ uri = uri.full_path+ puts uri+ end++ match.content = uri.to_s+ end+ enddescription = description ? description.to_xml : ""- description = description.gsub(/(https:\/\/)|(http:\/\/)?(www\.)?(youtube\.com)/, "")wilson_score = ci_lower_bound(likes, likes + dislikes)@@ -278,6 +289,20 @@ def template_comments(root)author = child["data"]["author"]score = child["data"]["score"]body_html = HTML.unescape(child["data"]["body_html"].as_s)+ body_html = XML.parse_html(body_html)++ body_html.xpath_nodes(%q(//a/@href)).each do |match|+ uri = URI.parse(match.content)++ if uri.host =~ /(www\.)?youtube.com/+ uri = uri.full_path+ puts uri+ end++ match.content = uri.to_s+ end++ body_html = body_html.to_sreplies_html = ""if child["data"]["replies"] != ""@@ -317,8 +342,6 @@ def template_comments(root)endend- html = html.gsub(/(https:\/\/)|(http:\/\/)?(www\.)?(youtube\.com)/, "")-return htmlend