diff --git a/lib/podcast_feed/provider/archive/parser.ex b/lib/podcast_feed/provider/archive/parser.ex index 8f704b7..67e2fe5 100644 --- a/lib/podcast_feed/provider/archive/parser.ex +++ b/lib/podcast_feed/provider/archive/parser.ex @@ -82,14 +82,14 @@ defmodule PodcastFeed.Provider.Archive.Parser do defp items_data(files, identifier) do files |> filter_audio_files() - |> Enum.map(fn f -> to_feed_item(f, identifier) end) + |> Enum.map(fn f -> to_feed_item(f, identifier, files) end) end defp filter_audio_files(files) do files |> Enum.filter(fn f -> Map.get(f, "format") =~ ~r/MP3|OGG/i end) #FIXME:! mp3, ogg, boh end - defp to_feed_item(file, identifier) do + defp to_feed_item(file, identifier, files) do filename = Map.get(file, "name") %{ title: file["title"], @@ -99,9 +99,20 @@ defmodule PodcastFeed.Provider.Archive.Parser do length: (file |> Map.get("length") |> Float.parse() |> elem(0)) |> trunc(), size: file |> Map.get("size"), summary: "", - # image: "", #FIXME:! take the image from other files + image: Format.compile(@download_url, identifier: identifier, filename: fetch_image_of_audio(Map.get(file, "name"), files)), keywords: file |> Map.take(["album", "artist", "genre"]) |> Map.values(), explicit: "no", } end + + defp fetch_image_of_audio(audio_file, files) do + files + |> Enum.filter(fn + %{"format" => format, "source" => "derivative", "original" => ^audio_file} -> + format =~ ~r/JPG|JPEG|PNG|GIF/i + _ -> nil + end) + |> List.first() + |> Map.get("name", nil) + end end diff --git a/lib/podcast_feed_web/templates/feed/feed.xml.eex b/lib/podcast_feed_web/templates/feed/feed.xml.eex index 2a2942a..a111dd5 100644 --- a/lib/podcast_feed_web/templates/feed/feed.xml.eex +++ b/lib/podcast_feed_web/templates/feed/feed.xml.eex @@ -41,6 +41,9 @@ <%= item.summary %> Enum.join(", ") %>]]> <%= item.explicit %> + <%= if item.image != nil do %> + + <% end %> <% end %>