Skip to content

Commit

Permalink
allow handling video metadata cache if params contain weird chars
Browse files Browse the repository at this point in the history
  • Loading branch information
breunigs committed Feb 22, 2025
1 parent 9169c74 commit e8e7c5f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/video/metadata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ defmodule Video.Metadata do
|> Enum.sort()
|> Enum.map(&apply(Video.Constants, &1, []))

@json_path "data/cache/video_metadata_#{Enum.join(parameters, "_")}.json"
hash =
:crypto.hash(:md5, Enum.join(parameters, " "))
|> Base.encode16(case: :lower)

@json_path "data/cache/video_metadata_#{hash}.json"
@spec read_json() :: state()
def read_json() do
try do
Expand All @@ -217,7 +221,12 @@ defmodule Video.Metadata do
{key, {:ok, struct!(__MODULE__, struct)}}
end)
rescue
_ -> %{}
File.Error ->
write_json(%{})

err ->
IO.warn("failed to read video metadata JSON: #{inspect(err)}")
write_json(%{})
end
end

Expand Down

0 comments on commit e8e7c5f

Please sign in to comment.