summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-07-23 13:48:43 -0500
committerOmar Roth <omarroth@hotmail.com>2018-07-23 13:48:43 -0500
commit965a3994922ab77f73c61ad8a6bfca163ab9f330 (patch)
tree6cef40978032676c24fcd60aa19f438c2f3eaf1a /src
parent0bb1da6bfd4362e3285f587f652ff417c9f43eb6 (diff)
downloadinvidious-965a3994922ab77f73c61ad8a6bfca163ab9f330.tar.gz
invidious-965a3994922ab77f73c61ad8a6bfca163ab9f330.tar.bz2
invidious-965a3994922ab77f73c61ad8a6bfca163ab9f330.zip
Simplify 'published' extraction
Diffstat (limited to 'src')
-rw-r--r--src/invidious/helpers.cr25
1 files 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)