fix: using defaults data when the json metadata file is missing

This commit is contained in:
danilo silva 2020-05-24 07:10:22 +00:00
parent 9a39d89ce8
commit b2f88145c7

View file

@ -13,9 +13,21 @@ defmodule PodcastFeed.Provider.Archive.Parser do
defp fetch_extra_metadata(identifier) do defp fetch_extra_metadata(identifier) do
extra_metadata_url = Format.compile(@extra_metadata_url, identifier: identifier) extra_metadata_url = Format.compile(@extra_metadata_url, identifier: identifier)
{:ok, 200, _headers, client_ref} = :hackney.get(extra_metadata_url, [], "", [follow_redirect: true]) case :hackney.get(extra_metadata_url, [], "", [follow_redirect: true]) do
{:ok, extra_metadata_json} = :hackney.body(client_ref) {:ok, 200, _headers, client_ref} ->
extra_metadata_json |> String.split("\n") |> Enum.join() |> Poison.decode!() {:ok, extra_metadata_json} = :hackney.body(client_ref)
extra_metadata_json |> String.split("\n") |> Enum.join() |> Poison.decode!()
_ -> %{
"link" => "",
"image" => %{
"url" => "",
"title" => "",
"link" => "",
},
"category" => "",
"explicit" => "",
}
end
end end
defp fetch_metadata(identifier) do defp fetch_metadata(identifier) do
@ -27,12 +39,11 @@ defmodule PodcastFeed.Provider.Archive.Parser do
end end
def parse(identifier, %{"metadata" => metadata, "files" => files}, extra) do def parse(identifier, %{"metadata" => metadata, "files" => files}, extra) do
_image = files |> fetch_image(identifier) # cover = files |> fetch_cover(identifier)
%{podcast: podcast_data(metadata, extra), items: items_data(files, identifier)} %{podcast: podcast_data(metadata, extra), items: items_data(files, identifier)}
end end
defp fetch_image(files, identifier) do defp fetch_cover(files, identifier) do
filename = files filename = files
|> Enum.filter(fn f -> f["source"] == "original" end) |> Enum.filter(fn f -> f["source"] == "original" end)
|> Enum.filter(fn f -> f["format"] == "JPEG" end) #FIXME:! jpg, png, gif |> Enum.filter(fn f -> f["format"] == "JPEG" end) #FIXME:! jpg, png, gif