Browse Source

support subject as a string

danilo silva 3 years ago
parent
commit
8a7e8e1b80

+ 3 - 1
lib/podcast_feed/provider/archive/parser.ex

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

+ 9 - 0
test/podcast_feed/provider/archive/parser_test.exs

@@ -44,6 +44,15 @@ defmodule PodcastFeed.Provider.Archive.ParserTest do
     } == podcast
   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
     custom = %{state[:token].custom_metadata | "image" => %{
       "url" => nil,