Invidious is an alternative front-end to YouTube
Add published field
Omar Roth26c9a87e88f9
diff --git a/src/helpers.cr b/src/helpers.crindex a9866cee..061d28bd 100644--- a/src/helpers.cr+++ b/src/helpers.cr@@ -11,7 +11,7 @@ class Videoendend- def initialize(id, info, html, updated, title, views, likes, dislikes, wilson_score)+ def initialize(id, info, html, updated, title, views, likes, dislikes, wilson_score, published)@id = id@info = info@html = html@@ -21,10 +21,11 @@ class Video@likes = likes@dislikes = dislikes@wilson_score = wilson_score+ @published = publishedenddef to_a- return [@id, @info, @html, @updated, @title, @views, @likes, @dislikes, @wilson_score]+ return [@id, @info, @html, @updated, @title, @views, @likes, @dislikes, @wilson_score, @published]endDB.mapping({@@ -45,6 +46,7 @@ class Videolikes: Int32,dislikes: Int32,wilson_score: Float64,+ published: Time,})end@@ -101,7 +103,23 @@ def fetch_video(id, client)wilson_score = ci_lower_bound(likes, likes + dislikes)- video = Video.new(id, info, html, Time.now, title, views, likes, dislikes, wilson_score)+ published = html.xpath_node(%q(//strong[@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 ")+ 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+ else+ published = Time.epoch(0)+ end++ video = Video.new(id, info, html, Time.now, title, views, likes, dislikes, wilson_score, published)return videoend@@ -114,11 +132,11 @@ def get_video(id, client, db, refresh = true)if refresh && Time.now - video.updated > 1.hoursvideo = fetch_video(id, client)db.exec("UPDATE videos SET info = $2, html = $3, updated = $4,\- title = $5, views = $6, likes = $7, dislikes = $8, wilson_score = $9 WHERE id = $1", video.to_a)+ title = $5, views = $6, likes = $7, dislikes = $8, wilson_score = $9, published = $10 WHERE id = $1", video.to_a)endelsevideo = fetch_video(id, client)- db.exec("INSERT INTO videos VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)", video.to_a)+ db.exec("INSERT INTO videos VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", video.to_a)endreturn videodiff --git a/videos.sql b/videos.sqlindex b505fdf8..9a9b0782 100644--- a/videos.sql+++ b/videos.sql@@ -11,6 +11,7 @@ CREATE TABLE public.videoslikes integer,dislikes integer,wilson_score double precision,+ published timestamp with time zone,CONSTRAINT videos_pkey PRIMARY KEY (id))WITH (