feat; added image for single episore

This commit is contained in:
danilo silva 2020-05-24 21:37:18 +00:00
parent 0904223664
commit 4cead58a0b
2 changed files with 17 additions and 3 deletions

View file

@ -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

View file

@ -41,6 +41,9 @@
<itunes:summary><%= item.summary %></itunes:summary>
<itunes:keywords><![CDATA[<%= item.keywords |> Enum.join(", ") %>]]></itunes:keywords>
<itunes:explicit><%= item.explicit %></itunes:explicit>
<%= if item.image != nil do %>
<itunes:image href="<%= item.image %>" />
<% end %>
</item>
<% end %>
</channel>