diff --git a/assets/css/app.scss b/assets/css/app.scss index c0e41cd..204a611 100644 --- a/assets/css/app.scss +++ b/assets/css/app.scss @@ -79,6 +79,12 @@ h6 { font-size: 2rem; } +.author { + font-size: 14px; + margin-top: -8px; + margin-bottom: 10px; +} + @media (min-width: 576px) { } diff --git a/config/config.exs b/config/config.exs index 54bc159..33f2e6c 100644 --- a/config/config.exs +++ b/config/config.exs @@ -19,7 +19,16 @@ config :openpod, OpenpodWeb.Endpoint, live_view: [signing_salt: "6jHv46Xw"] config :openpod, - cache_duration: :timer.hours(24) + cache_duration: :timer.hours(24), + base_url: "https://openpod.abbiamoundominio.org/", + podders: [ + "uau-pod", + "fuori-fase", + "incontri-a-piano-terra", + "la_blogosfera_podcast", + "prnt_scrn_podcast", + "anarcotraffico-001-20200611.128" + ] # Configures Elixir's Logger config :logger, :console, @@ -31,7 +40,7 @@ config :phoenix, :json_library, Jason config :openpod, Openpod.Boundary.ArchiveScheduler, jobs: [ - {"0 6-18 * * *", {Openpod.Boundary.ArchiveReloader, :reload, []}}, + {"0 6-18 * * *", {Openpod.Boundary.ArchiveReloader, :reload, []}} ] # Import environment specific config. This must remain at the bottom diff --git a/lib/openpod/provider/archive/parser.ex b/lib/openpod/provider/archive/parser.ex index 2a32503..7797949 100644 --- a/lib/openpod/provider/archive/parser.ex +++ b/lib/openpod/provider/archive/parser.ex @@ -16,15 +16,20 @@ defmodule Openpod.Provider.Archive.Parser do "image" => %{ "url" => nil, "title" => nil, - "link" => nil, + "link" => nil }, "category" => "", "explicit" => "no", - "version" => "1", + "version" => "1" } @enforce_keys [:identifier] - defstruct [:identifier, :podcast_data, :archive_metadata, custom_metadata: @custom_metadata_defaults] + defstruct [ + :identifier, + :podcast_data, + :archive_metadata, + custom_metadata: @custom_metadata_defaults + ] def by_identifier(identifier) do %Parser{identifier: identifier} @@ -39,8 +44,13 @@ defmodule Openpod.Provider.Archive.Parser do } end - defp podcast_data(token = %{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"], description: metadata["description"], @@ -48,21 +58,22 @@ defmodule Openpod.Provider.Archive.Parser do managingEditor: metadata["uploader"], owner: %{ name: metadata["creator"], - email: metadata["uploader"], + email: metadata["uploader"] }, keywords: parse_subject(metadata["subject"]), - pubDate: metadata["publicdate"] |> NaiveDateTime.from_iso8601!() |> DateTime.from_naive!("Etc/UTC"), + pubDate: + metadata["publicdate"] |> NaiveDateTime.from_iso8601!() |> DateTime.from_naive!("Etc/UTC"), lastBuildDate: last_updated |> DateTime.from_unix!(:second), author: metadata["creator"], language: ISO639.to_iso639_1(metadata["language"]), image: %{ url: fetch_cover(token), title: metadata["title"], - link: Map.get(metadata, "op_link") || link, + link: Map.get(metadata, "op_link") || link }, link: Map.get(metadata, "op_link") || link, category: Map.get(metadata, "op_category", ""), - explicit: Map.get(metadata, "op_explicit", "no"), + explicit: Map.get(metadata, "op_explicit", "no") } end @@ -74,41 +85,52 @@ defmodule Openpod.Provider.Archive.Parser do 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]) + + {:ok, 200, _headers, client_ref} = + :hackney.get(metadata_url, [], "", + follow_redirect: true, + connect_timeout: 30_000, + recv_timeout: 30_000 + ) + {:ok, metadata_json} = :hackney.body(client_ref) metadata_json |> Jason.decode!() end defp filter_audio_files(files) do - files |> Enum.filter(fn f -> Map.get(f, "format") =~ ~r/MP3/i end) #FIXME:! mp3, ogg, boh + # FIXME:! mp3, ogg, boh + files |> Enum.filter(fn f -> Map.get(f, "format") =~ ~r/MP3/i end) end defp to_feed_item(file, identifier, _files) do filename = Map.get(file, "name") + %{ title: file["title"], description: "", - pubDate: file |> Map.get("mtime") |> Integer.parse() |> elem(0) |> DateTime.from_unix!(:second), + pubDate: + file |> Map.get("mtime") |> Integer.parse() |> elem(0) |> DateTime.from_unix!(:second), link: download_url(identifier, filename), - length: (file |> Map.get("length") |> Float.parse() |> elem(0)) |> trunc(), + length: file |> Map.get("length") |> Float.parse() |> elem(0) |> trunc(), size: file |> Map.get("size"), summary: "", # image: download_url(identifier, fetch_image_of_audio(filename, files)), image: nil, keywords: file |> Map.take(["album", "artist", "genre"]) |> Map.values(), - explicit: "no", + explicit: "no" } end defp fetch_cover(%{identifier: identifier, archive_metadata: %{"files" => files}}) do - filename = files - |> Enum.filter(fn f -> f["source"] == "original" end) - |> Enum.filter(fn f -> f["format"] =~ ~r/JPG|JPEG|PNG|GIF|Item Image/i end) - |> List.first() - |> case do - nil -> nil - file -> Map.get(file, "name") - end + filename = + files + |> Enum.filter(fn f -> f["source"] == "original" end) + |> Enum.filter(fn f -> f["format"] =~ ~r/JPG|JPEG|PNG|GIF|Item Image/i end) + |> List.first() + |> case do + nil -> nil + file -> Map.get(file, "name") + end download_url(identifier, filename) end @@ -128,6 +150,7 @@ defmodule Openpod.Provider.Archive.Parser do # defp fetch_image_of_audio(image_file), do: image_file |> Map.get("name", nil) defp download_url(_identifier, nil), do: nil + defp download_url(identifier, filename) do Format.compile(@download_url, identifier: identifier, filename: filename) |> URI.encode() end diff --git a/lib/openpod_web.ex b/lib/openpod_web.ex index f53a809..7b0d4a7 100644 --- a/lib/openpod_web.ex +++ b/lib/openpod_web.ex @@ -62,6 +62,7 @@ defmodule OpenpodWeb do quote do # Use all HTML functionality (forms, tags, etc) use Phoenix.HTML + use PhoenixHtmlSanitizer, :basic_html # Import basic rendering functionality (render, render_layout, etc) import Phoenix.View diff --git a/lib/openpod_web/controllers/page_controller.ex b/lib/openpod_web/controllers/page_controller.ex index 210ec31..763d619 100644 --- a/lib/openpod_web/controllers/page_controller.ex +++ b/lib/openpod_web/controllers/page_controller.ex @@ -1,6 +1,17 @@ defmodule OpenpodWeb.PageController do use OpenpodWeb, :controller + Application.ensure_all_started(:hackney) + + @base_url Application.get_env(:openpod, :base_url) + + @podders Application.get_env(:openpod, :podders) + |> Enum.map(fn podcast -> + Openpod.Provider.Archive.Parser.by_identifier(podcast) + |> Map.get(:podcast) + |> Map.put(:podcast_url, "#{@base_url}/podcast/#{podcast}") + end) + def index(conn, _params) do render(conn, "index.html") end @@ -10,39 +21,6 @@ defmodule OpenpodWeb.PageController do end def chi(conn, _params) do - render(conn, "chi.html", - podders: [ - %{ - cover: "https://ia801504.us.archive.org/0/items/uau-pod/logo.jpg?cnt=0", - podcast_url: "https://openpod.abbiamoundominio.org/podcast/uau-pod", - name: "UAU POD", - description: """ - Il podcast di Un'ambigua utopia anticipa l'uscita del numero speciale, il numero 10, dell'omonima rivista. - Archivio digitale ed altri materiali all'indirizzo http://archivio-uau.online/ - """ - }, - %{ - cover: "https://ia803204.us.archive.org/24/items/fuori-fase/fuori_fase_cover.jpg?cnt=0", - podcast_url: "https://openpod.abbiamoundominio.org/podcast/fuori-fase", - name: "Fuori Fase", - description: """ - Come è stata gestita l’emergenza nei suoi diversi aspetti? Quali sono state le conseguenze della pandemia, a livello economico e sociale? - Con oggi lanciamo il primo di una serie di contributi audio, frutto degli incontri e degli scambi realizzati lungo la quarantena e i lunghi mesi di lockdown, - per riflettere sui cambiamenti che l’epidemia – intesa come fenomeno sociale – ha imposto su una serie di aspetti strutturali del nostro tempo. - “Fuori Fase” lo abbiamo chiamato: appunti per riscrivere il crono-programma dell’emergenza e del dopo-Covid da qui ai prossimi mesi. - https://offtopiclab.org/ - """ - }, - %{ - cover: - "https://ia801905.us.archive.org/15/items/incontri-a-piano-terra/tracce.jpg?cnt=0", - podcast_url: "https://openpod.abbiamoundominio.org/podcast/incontri-a-piano-terra", - name: "APE podcast", - description: """ - Qualche registrazione delle attività sociali che promuoviamo al Piano Terra di Milano. http://ape-alveare.it - """ - } - ] - ) + render(conn, "chi.html", podders: @podders) end end diff --git a/lib/openpod_web/templates/page/chi.html.eex b/lib/openpod_web/templates/page/chi.html.eex index 3c56bb0..c0fbf71 100644 --- a/lib/openpod_web/templates/page/chi.html.eex +++ b/lib/openpod_web/templates/page/chi.html.eex @@ -22,16 +22,17 @@