From 965a3994922ab77f73c61ad8a6bfca163ab9f330 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 23 Jul 2018 13:48:43 -0500 Subject: [PATCH] Simplify 'published' extraction --- src/invidious/helpers.cr | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/invidious/helpers.cr b/src/invidious/helpers.cr index 4523ab81..4f87fc67 100644 --- a/src/invidious/helpers.cr +++ b/src/invidious/helpers.cr @@ -271,29 +271,8 @@ def fetch_video(id, client) wilson_score = ci_lower_bound(likes, likes + dislikes) - published = html.xpath_node(%q(//strong[contains(@class,"watch-time-text")])) - if published - published = published.content - else - raise "Could not find date published" - end - - published = published.split(" ") - published = published[-3..-1].join(" ") - if !published.includes?("ago") - published = Time.parse(published, "%b %-d, %Y", Time::Location.local) - else - # Time matches format "20 hours ago", "40 minutes ago"... - delta = published.split(" ")[0].to_i - case published - when .includes? "minute" - published = Time.now - delta.minutes - when .includes? "hour" - published = Time.now - delta.hours - else - raise "Could not parse #{published}" - end - end + published = html.xpath_node(%q(//meta[@itemprop="datePublished"])).not_nil!["content"] + published = Time.parse(published, "%Y-%m-%d", Time::Location.local) video = Video.new(id, info, Time.now, title, views, likes, dislikes, wilson_score, published, description, nil, author, ucid)