From 30e43805b2fc10e7e23d6b948c01b5ba7db5151d Mon Sep 17 00:00:00 2001 From: Skander Mzali Date: Mon, 9 Sep 2024 13:11:19 -0700 Subject: [PATCH] Update feed stream queue to skip anything before today (2024/09/09) in preparation for backfilling new bucket data --- .../lib/orcasite/radio/feed_stream_queue.ex | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server/lib/orcasite/radio/feed_stream_queue.ex b/server/lib/orcasite/radio/feed_stream_queue.ex index 4719ddb7..f63c02f4 100644 --- a/server/lib/orcasite/radio/feed_stream_queue.ex +++ b/server/lib/orcasite/radio/feed_stream_queue.ex @@ -48,7 +48,8 @@ defmodule Orcasite.Radio.FeedStreamQueue do end end) |> Enum.flat_map(fn %{"s3" => %{"object" => %{"key" => object_path}}} -> - if String.ends_with?(object_path, ".m3u8") do + if String.ends_with?(object_path, ".m3u8") and + select_recent_timestamp(object_path, ~U[2024-09-09 00:00:00Z]) do [%{m3u8_path: object_path}] else [] @@ -71,4 +72,22 @@ defmodule Orcasite.Radio.FeedStreamQueue do messages end + + def select_recent_timestamp(object_path, after_date) do + with {:path, %{"timestamp" => timestamp}} <- + {:path, + Regex.named_captures( + ~r|(?[^/]+)/hls/(?[^/]+)/live.m3u8|, + object_path + )}, + timestamp_time = + timestamp + |> String.to_integer() + |> DateTime.from_unix!(), + :gt <- DateTime.compare(timestamp_time, after_date) do + true + else + _ -> false + end + end end