From ef8c9f093c0b6ea4b68b116d683e8d7f045ccd66 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 8 Jun 2019 10:18:45 -0500 Subject: Add premiere date to watch page --- src/invidious.cr | 2 +- src/invidious/videos.cr | 8 ++++++-- src/invidious/views/embed.ecr | 3 ++- src/invidious/views/watch.ecr | 13 +++++++++++-- 4 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/invidious.cr b/src/invidious.cr index 63c44177..2ea2c518 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -519,7 +519,7 @@ get "/watch" do |env| engagement = ((video.dislikes.to_f + video.likes.to_f)/video.views * 100) playability_status = video.player_response["playabilityStatus"]? - if playability_status && playability_status["status"] == "LIVE_STREAM_OFFLINE" + if playability_status && playability_status["status"] == "LIVE_STREAM_OFFLINE" && !video.premiere_timestamp reason = playability_status["reason"]?.try &.as_s end reason ||= "" diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 5765d0c8..78a52db3 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -851,8 +851,12 @@ def get_video(id, db, proxies = {} of String => Array({ip: String, port: Int32}) if db.query_one?("SELECT EXISTS (SELECT true FROM videos WHERE id = $1)", id, as: Bool) && !region video = db.query_one("SELECT * FROM videos WHERE id = $1", id, as: Video) - # If record was last updated over 10 minutes ago, refresh (expire param in response lasts for 6 hours) - if (refresh && Time.utc - video.updated > 10.minutes) || force_refresh + # If record was last updated over 10 minutes ago, or video has since premiered, + # refresh (expire param in response lasts for 6 hours) + if (refresh && + (Time.utc - video.updated > 10.minutes) || + (video.premiere_timestamp && video.premiere_timestamp.as(Time) < Time.utc)) || + force_refresh begin video = fetch_video(id, proxies, region) video_array = video.to_a diff --git a/src/invidious/views/embed.ecr b/src/invidious/views/embed.ecr index b6307b9c..7fa5f45b 100644 --- a/src/invidious/views/embed.ecr +++ b/src/invidious/views/embed.ecr @@ -30,7 +30,8 @@ var video_data = { length_seconds: '<%= video.info["length_seconds"].to_f %>', video_series: <%= video_series.to_json %>, params: <%= params.to_json %>, - preferences: <%= preferences.to_json %> + preferences: <%= preferences.to_json %>, + premiere_timestamp: <%= video.premiere_timestamp.try &.to_unix || "null" %> } diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 2f03190a..85ca8b8b 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -40,7 +40,8 @@ var video_data = { hide_replies_text: '<%= HTML.escape(translate(locale, "Hide replies")) %>', show_replies_text: '<%= HTML.escape(translate(locale, "Show replies")) %>', params: <%= params.to_json %>, - preferences: <%= preferences.to_json %> + preferences: <%= preferences.to_json %>, + premiere_timestamp: <%= video.premiere_timestamp.try &.to_unix || "null" %> } @@ -72,6 +73,10 @@ var video_data = {

<%= reason %>

+ <% elsif video.premiere_timestamp %> +

+ <%= translate(locale, "Premieres in `x`", recode_date((video.premiere_timestamp.as(Time) - Time.utc).ago, locale)) %> +

<% end %> @@ -172,7 +177,11 @@ var video_data = { <%= rendered "components/subscribe_widget" %>

- <%= translate(locale, "Shared `x`", video.published.to_s("%B %-d, %Y")) %> + <% if video.premiere_timestamp %> + <%= translate(locale, "Premieres `x`", video.premiere_timestamp.not_nil!.to_s("%B %-d, %R UTC")) %> + <% else %> + <%= translate(locale, "Shared `x`", video.published.to_s("%B %-d, %Y")) %> + <% end %>

-- cgit v1.2.3