From 8a7e8e1b8045cdee0243caf193825d6d9298760f Mon Sep 17 00:00:00 2001 From: danilo silva Date: Sun, 7 Jun 2020 20:23:29 +0000 Subject: [PATCH] support subject as a string --- lib/podcast_feed/provider/archive/parser.ex | 4 +++- test/podcast_feed/provider/archive/parser_test.exs | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/podcast_feed/provider/archive/parser.ex b/lib/podcast_feed/provider/archive/parser.ex index d992180..6041ad9 100644 --- a/lib/podcast_feed/provider/archive/parser.ex +++ b/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 diff --git a/test/podcast_feed/provider/archive/parser_test.exs b/test/podcast_feed/provider/archive/parser_test.exs index 49e55c9..cd70c88 100644 --- a/test/podcast_feed/provider/archive/parser_test.exs +++ b/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,