diff --git a/lib/algora/pipeline/storage.ex b/lib/algora/pipeline/storage.ex index c118ebf..6912252 100644 --- a/lib/algora/pipeline/storage.ex +++ b/lib/algora/pipeline/storage.ex @@ -87,7 +87,7 @@ defmodule Algora.Pipeline.Storage do state = process_contents(parent_id, name, contents, metadata, ctx, state) - |> update_sequence_numbers(sequence_number, manifest_name) + |> update_sequence_numbers(sequence_number, name, manifest_name) |> add_partial(name, ctx, partial_name, contents, manifest_name) {:ok, state} @@ -257,20 +257,17 @@ defmodule Algora.Pipeline.Storage do defp update_sequence_numbers( %{sequences: sequences} = state, new_partial_sn, + segment_name, manifest_name ) do - {segment_sn, partial_sn} = Map.get(sequences, manifest_name, {0, 0}) - new_segment? = new_partial_sn < partial_sn - sequence = if new_segment? do - { segment_sn + 1, new_partial_sn } - else - { segment_sn, new_partial_sn } - end + {segment_sn, _partial_sn} = Map.get(sequences, manifest_name, {0, 0}) + new_segment_sn = get_segment_number_from_name(segment_name) state = sequences - |> Map.put(manifest_name, sequence) + |> Map.put(manifest_name, {new_segment_sn, new_partial_sn}) |> then(&Map.put(state, :sequences, &1)) - # If there is a new segment we want to remove partials that are too old from ets - if new_segment? do + + # If there is a new segment we want to remove partials that are too old + if new_segment_sn > segment_sn do remove_partials(state, manifest_name) else state @@ -381,4 +378,13 @@ defmodule Algora.Pipeline.Storage do defp process_contents(_parent_id, _name, _contents, _metadata, _ctx, state) do state end + + # audio_segment_0_audio_master.m4s + defp get_segment_number_from_name(filename) do + filename + |> String.split("_") + |> Enum.drop(2) + |> List.first() + |> String.to_integer() + end end