diff --git a/lib/podcast_feed/provider/archive/parser.ex b/lib/podcast_feed/provider/archive/parser.ex index 9a365c7..2f988ab 100644 --- a/lib/podcast_feed/provider/archive/parser.ex +++ b/lib/podcast_feed/provider/archive/parser.ex @@ -13,9 +13,21 @@ defmodule PodcastFeed.Provider.Archive.Parser do defp fetch_extra_metadata(identifier) do extra_metadata_url = Format.compile(@extra_metadata_url, identifier: identifier) - {:ok, 200, _headers, client_ref} = :hackney.get(extra_metadata_url, [], "", [follow_redirect: true]) - {:ok, extra_metadata_json} = :hackney.body(client_ref) - extra_metadata_json |> String.split("\n") |> Enum.join() |> Poison.decode!() + case :hackney.get(extra_metadata_url, [], "", [follow_redirect: true]) do + {:ok, 200, _headers, client_ref} -> + {: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 defp fetch_metadata(identifier) do @@ -27,12 +39,11 @@ defmodule PodcastFeed.Provider.Archive.Parser do end 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)} end - defp fetch_image(files, identifier) do + defp fetch_cover(files, identifier) do filename = files |> Enum.filter(fn f -> f["source"] == "original" end) |> Enum.filter(fn f -> f["format"] == "JPEG" end) #FIXME:! jpg, png, gif