Fix video indexing

このコミットが含まれているのは:
Omar Roth 2018-02-04 19:42:13 -06:00
コミット d79c1ff3e9
2個のファイルの変更24行の追加9行の削除

ファイルの表示

@ -100,27 +100,38 @@ def fetch_video(id, client)
views = info["view_count"].to_i64
likes = html.xpath_node(%q(//button[@title="I like this"]/span))
likes = likes ? likes.content.delete(",").to_i : 1
likes = likes ? likes.content.delete(",").to_i : 0
dislikes = html.xpath_node(%q(//button[@title="I dislike this"]/span))
dislikes = dislikes ? dislikes.content.delete(",").to_i : 0
wilson_score = ci_lower_bound(likes, likes + dislikes)
published = html.xpath_node(%q(//strong[@class="watch-time-text"]))
published = html.xpath_node(%q(//strong[contains(@class,"watch-time-text")]))
if published
published = published.content
published = published.lchop("Published on ")
published = published.lchop("Streamed live on ")
published = published.lchop("Started streaming on ")
else
raise "Could not find date published"
end
published = published.lchop("Published ")
published = published.lchop("Streamed live ")
published = published.lchop("Started streaming ")
published = published.lchop("on ")
published = published.lchop("Scheduled for ")
if !published.includes?("ago")
published = Time.parse(published, "%b %-d, %Y")
else
# Time matches format "20 hours ago", "40 minutes ago"...
published = Time.now.date
end
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
published = Time.epoch(0)
raise "Could not parse #{published}"
end
end
video = Video.new(id, info, html, Time.now, title, views, likes, dislikes, wilson_score, published)
@ -165,7 +176,7 @@ def search(query, client)
end
def decrypt_signature(a)
a = a.split("");
a = a.split("")
a.delete_at(0..2)
a = a.reverse
c = a[0]

ファイルの表示

@ -182,7 +182,11 @@ get "/watch" do |env|
rating = video.info["avg_rating"].to_f64
engagement = ((video.dislikes.to_f + video.likes.to_f)/video.views * 100)
if video.likes > 0 || video.dislikes > 0
calculated_rating = (video.likes.to_f/(video.likes.to_f + video.dislikes.to_f) * 4 + 1)
else
calculated_rating = 0.0
end
templated "watch"
end