support subject as a string

This commit is contained in:
danilo silva 2020-06-07 20:23:29 +00:00
parent 3050ac6791
commit 8a7e8e1b80
2 changed files with 12 additions and 1 deletions

View file

@ -52,7 +52,7 @@ defmodule PodcastFeed.Provider.Archive.Parser do
name: metadata["creator"], name: metadata["creator"],
email: metadata["uploader"], email: metadata["uploader"],
}, },
keywords: metadata["subject"], keywords: parse_subject(metadata["subject"]),
pubDate: metadata["publicdate"] |> NaiveDateTime.from_iso8601!() |> DateTime.from_naive!("Etc/UTC"), pubDate: metadata["publicdate"] |> NaiveDateTime.from_iso8601!() |> DateTime.from_naive!("Etc/UTC"),
lastBuildDate: last_updated |> DateTime.from_unix!(:second), lastBuildDate: last_updated |> DateTime.from_unix!(:second),
author: metadata["creator"], author: metadata["creator"],
@ -156,4 +156,6 @@ defmodule PodcastFeed.Provider.Archive.Parser do
%Parser{token | custom_metadata: fetch_custom_metadata(token.identifier)} %Parser{token | custom_metadata: fetch_custom_metadata(token.identifier)}
end end
defp parse_subject(subject) when is_list(subject), do: subject
defp parse_subject(subject) when is_binary(subject), do: subject |> String.split(";")
end end

View file

@ -44,6 +44,15 @@ defmodule PodcastFeed.Provider.Archive.ParserTest do
} == podcast } == podcast
end end
test "podcast subject metadata can also be a string", state do
token = state[:token] |> Map.update!(:archive_metadata, fn metadata -> put_in(metadata, ["metadata", "subject"], "foo;bar;baz") end)
%{podcast: podcast} = Parser.to_podcast_feed_data(token)
assert %{
keywords: ["foo", "bar", "baz"],
} = podcast
end
test "using first `original` image found on archive when image is missing on custom metadata", state do test "using first `original` image found on archive when image is missing on custom metadata", state do
custom = %{state[:token].custom_metadata | "image" => %{ custom = %{state[:token].custom_metadata | "image" => %{
"url" => nil, "url" => nil,