Browse Source

fetching custom metadata from op_* metadata instead of fetching them on metadata.json file

danilo silva 3 years ago
parent
commit
2009f37d15

+ 7 - 27
lib/podcast_feed/provider/archive/parser.ex

@@ -7,7 +7,6 @@ defmodule PodcastFeed.Provider.Archive.Parser do
   alias PodcastFeed.Utility.Format
   alias __MODULE__
 
-  @custom_metadata_url "https://archive.org/download/{identifier}/metadata.json"
   @archive_metadata_url "http://archive.org/metadata/{identifier}"
   @download_url "https://archive.org/download/{identifier}/{filename}"
   @podcast_link "https://archive.org/details/{identifier}"
@@ -30,7 +29,6 @@ defmodule PodcastFeed.Provider.Archive.Parser do
   def by_identifier(identifier) do
     %Parser{identifier: identifier}
     |> enrich_with_archive_metadata()
-    |> enrich_with_custom_metadata()
     |> to_podcast_feed_data()
   end
 
@@ -41,7 +39,7 @@ defmodule PodcastFeed.Provider.Archive.Parser do
     }
   end
 
-  defp podcast_data(token = %{custom_metadata: custom, archive_metadata: %{"metadata" => metadata, "item_last_updated" => last_updated}}) do
+  defp podcast_data(token = %{archive_metadata: %{"metadata" => metadata, "item_last_updated" => last_updated}}) do
     link = Format.compile(@podcast_link, identifier: token.identifier)
     %{
       title: metadata["title"],
@@ -58,13 +56,13 @@ defmodule PodcastFeed.Provider.Archive.Parser do
       author: metadata["creator"],
       language: metadata["language"],
       image: %{
-        url: get_in(custom, ["image", "url"]) || fetch_cover(token),
-        title: get_in(custom, ["image", "title"]) || metadata["title"],
-        link: get_in(custom, ["image", "link"]) || link,
+        url: fetch_cover(token),
+        title: metadata["title"],
+        link: Map.get(metadata, "op_link") || link,
       },
-      link: Map.get(custom, "link") || link,
-      category: Map.get(custom, "category", ""),
-      explicit: Map.get(custom, "explicit", "no"),
+      link: Map.get(metadata, "op_link") || link,
+      category: Map.get(metadata, "op_category", ""),
+      explicit: Map.get(metadata, "op_explicit", "no"),
     }
   end
 
@@ -74,20 +72,6 @@ defmodule PodcastFeed.Provider.Archive.Parser do
     |> Enum.map(fn f -> to_feed_item(f, identifier, files) end)
   end
 
-  defp fetch_custom_metadata(identifier) do
-    custom_metadata_url = Format.compile(@custom_metadata_url, identifier: identifier)
-    parse_custom_metadata_response(:hackney.get(custom_metadata_url, [], "", [follow_redirect: true]))
-  end
-
-  defp parse_custom_metadata_response({:ok, 200, _headers, client_ref}) do
-    {:ok, custom_metadata_json} = :hackney.body(client_ref)
-    custom_metadata_json
-    |> String.split("\n")
-    |> Enum.join()
-    |> Jason.decode!()
-  end
-  defp parse_custom_metadata_response(_), do: @custom_metadata_defaults
-
   defp fetch_archive_metadata(identifier) do
     metadata_url = Format.compile(@archive_metadata_url, identifier: identifier)
     {:ok, 200, _headers, client_ref} = :hackney.get(metadata_url, [], "", [follow_redirect: true, connect_timeout: 30_000, recv_timeout: 30_000])
@@ -152,10 +136,6 @@ defmodule PodcastFeed.Provider.Archive.Parser do
     %Parser{token | archive_metadata: fetch_archive_metadata(token.identifier)}
   end
 
-  defp enrich_with_custom_metadata(token) 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

File diff suppressed because it is too large
+ 0 - 0
test/podcast_feed/provider/archive/parser_test.exs


Some files were not shown because too many files changed in this diff