Simplify 'published' extraction

pull/38/head
Omar Roth 6 years ago
parent 0bb1da6bfd
commit 965a399492

@ -271,29 +271,8 @@ def fetch_video(id, client)
wilson_score = ci_lower_bound(likes, likes + dislikes) wilson_score = ci_lower_bound(likes, likes + dislikes)
published = html.xpath_node(%q(//strong[contains(@class,"watch-time-text")])) published = html.xpath_node(%q(//meta[@itemprop="datePublished"])).not_nil!["content"]
if published published = Time.parse(published, "%Y-%m-%d", Time::Location.local)
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
video = Video.new(id, info, Time.now, title, views, likes, dislikes, wilson_score, published, description, nil, author, ucid) video = Video.new(id, info, Time.now, title, views, likes, dislikes, wilson_score, published, description, nil, author, ucid)

Loading…
Cancel
Save