Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create feed stream with bucket input #624

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion server/lib/orcasite/radio/feed_stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ defmodule Orcasite.Radio.FeedStream do

attribute :playlist_m3u8_path, :string do
public? true

description "S3 object path for playlist file (e.g. /rpi_orcasound_lab/hls/1541027406/live.m3u8)"
end

Expand Down Expand Up @@ -103,6 +104,7 @@ defmodule Orcasite.Radio.FeedStream do
argument :playlist_path, :string
argument :update_segments?, :boolean, default: false
argument :link_streams?, :boolean, default: false
argument :bucket, :string

change fn changeset, _context ->
path =
Expand Down Expand Up @@ -145,12 +147,15 @@ defmodule Orcasite.Radio.FeedStream do
changeset
|> Ash.Changeset.get_argument_or_attribute(:playlist_timestamp)

bucket_arg = Ash.Changeset.get_argument(changeset, :bucket)

feed
|> Map.take([:bucket, :bucket_region, :cloudfront_url])
|> Map.take([:bucket_region, :cloudfront_url])
|> Enum.reduce(changeset, fn {attribute, value}, acc ->
acc
|> Ash.Changeset.change_new_attribute(attribute, value)
end)
|> Ash.Changeset.change_new_attribute(:bucket, bucket_arg || feed.bucket)
|> Ash.Changeset.change_new_attribute(
:start_time,
playlist_timestamp
Expand Down
9 changes: 7 additions & 2 deletions server/lib/orcasite/radio/feed_stream_queue.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ defmodule Orcasite.Radio.FeedStreamQueue do
[]
end
end)
|> Enum.flat_map(fn %{"s3" => %{"object" => %{"key" => object_path}}} ->
|> Enum.flat_map(fn %{
"s3" => %{
"object" => %{"key" => object_path},
"bucket" => %{"name" => bucket}
}
} ->
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}]
[%{m3u8_path: object_path, bucket: bucket}]
else
[]
end
Expand Down
Loading