defmodule PodcastFeed.Provider.Archive.Parser do
def feed(url) do
url
|> fetch_xml()
|> parse()
|> IO.inspect()
|> filter_mp3()
|> compose()
end
defp fetch_xml(url) do
{:ok, {_, _, xml}} = :httpc.request(:get, {url, []}, [], [body_format: :binary])
xml
end
defp parse(xml) do
xml |> XmlToMap.naive_map() |> Map.get("files") |> Map.get("file") |> Enum.map(fn f -> Map.get(f, "#content") |> Map.put("filename", Map.get(f, "-name")) end)
end
defp filter_mp3(files) do
files |> Enum.filter(fn f -> Map.get(f, "format") =~ ~r/MP3/i end)
end
defp compose(files) do
files
|> Enum.map(&to_feed_item/1)
end
# -
# Episode Name 2
#
# http://podcast.example.com/episode2.mp4
#
# Sat, 02 Jan 2016 16:00:00 PDT
#
# The full length episode 2 description
#
#
#
# http://podcast.example.com/episode2.mp4
#
# 19:07
#
# The full length episode 2 description
#
#
#
# comma,separated,key,words
#
# no
#
# %{
# "album" => "Incontri al Piano Terra",
# "artist" => "APE Milano",
# "crc32" => "f1820595",
# "creator" => "APE Milano",
# "format" => "VBR MP3",
# "genre" => "podcast",
# "height" => "0",
# "length" => "3943.31",
# "md5" => "9ca26043a3e82e6f86c3a9309b88f4f5",
# "mtime" => "1590154757",
# "sha1" => "dcacfa46fcad1d656312784ad06886b5614c6420",
# "size" => "47148690",
# "title" => "Presentazione di Montagna femminile plurale con N1DM",
# "track" => "03",
# "width" => "0"
# }
defp to_feed_item(file) do
%{
title: file |> Map.get("title"),
link: "http://archive.org/download/incontri-a-piano-terra/" <> (file |> Map.get("filename")) |> URI.encode(), #FIXME:! identifier should by dynamic
pubDate: file |> Map.get("mtime") |> Integer.parse() |> elem(0) |> DateTime.from_unix!(:second),
description: "",
length: (file |> Map.get("length") |> Float.parse() |> elem(0)) * 100,
guid: "",
duration: "",
summary: "",
image: "",
keywords: file |> Map.take(["album", "artist", "genre"]) |> Map.values(),
explicit: "no",
}
end
end
#
#
#
# http://www.YourSite.com
# en-us
# ©2013
# your@email.com (Your Name)
# your@email.com (Your Name)
#
# http://www.YourSite.com/ImageSize300X300.jpg
# Title or description of your logo
# http://www.YourSite.com
#
#
# Your Name
# your@email.com
#
#
#
#
# separate, by, comma, and, space
# no
#
#
# Sun, 01 Jan 2012 00:00:00 EST
# Verbose title of the podcast
# College, school, or department owning the podcast
# Verbose description of the podcast.
# Duplicate of above verbose description.
# Short description of the podcast - 255 character max.
# Thu, 02 Feb 2012 00:00:00 EST
# -
# Verbose title of the episode
# Verbose description of the episode.
# Duplicate of above verbose description.
# Short description of the episode - 255 character max.
#
#
# http://www.YourSite.com/FILE.EXT
# H:MM:SS
# Thu, 02 Feb 2012 00:00:00 EST
#
#
#