diff --git a/lib/pinchflat/podcasts/podcast_helpers.ex b/lib/pinchflat/podcasts/podcast_helpers.ex index d67482a..a999dd1 100644 --- a/lib/pinchflat/podcasts/podcast_helpers.ex +++ b/lib/pinchflat/podcasts/podcast_helpers.ex @@ -1,4 +1,4 @@ -defmodule Pinchflat.Podcasts.PostcastHelpers do +defmodule Pinchflat.Podcasts.PodcastHelpers do alias Pinchflat.Repo alias Pinchflat.Media @@ -13,11 +13,8 @@ defmodule Pinchflat.Podcasts.PostcastHelpers do # TODO: test # Returns string or nil - def select_cover_image(source) do + def select_cover_image(source, media_items) do source_with_preloads = Repo.preload(source, :metadata) - # Since we're looking for the metadata image, _any_ downloaded media - # items should be fine - media_items = Media.list_downloaded_media_items_for(source, limit: 1) source_with_preloads |> get_images_by_preference(media_items) diff --git a/lib/pinchflat/podcasts/rss_feed_builder.ex b/lib/pinchflat/podcasts/rss_feed_builder.ex index 0e6b260..0733ca1 100644 --- a/lib/pinchflat/podcasts/rss_feed_builder.ex +++ b/lib/pinchflat/podcasts/rss_feed_builder.ex @@ -1,25 +1,22 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do @datetime_format "%a, %d %b %Y %H:%M:%S %z" - alias Pinchflat.Podcasts.PostcastHelpers + alias Pinchflat.Podcasts.PodcastHelpers alias PinchflatWeb.Router.Helpers, as: Routes # TODO: test # TODO: only MIs that are confirmed to exist on-disk should be provided def build(source, media_items) do - media_item_xml = Enum.map(media_items, &build_media_item_xml(source, &1)) - - build_source_xml(source, media_item_xml) + build_source_xml(source, media_items) end - defp build_source_xml(source, media_item_xml) do + defp build_source_xml(source, media_items) do + media_item_xml = Enum.map(media_items, &build_media_item_xml(source, &1)) + # Useful: resources: # - https://validator.w3.org/feed/#validate_by_input # - https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md # - https://podba.se/validate - # - # - Add real - # - Serve proper images instead of the placeholders """ #{source.custom_name} #{source.original_url} - #{source.custom_name} + #{source.description} TV & Film Generated by Pinchflat en-us @@ -39,14 +36,14 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do yes #{source.uuid} - #{feed_image_path(source)} + #{feed_image_path(source, media_items)} #{source.custom_name} #{source.original_url} #{source.custom_name} #{source.custom_name} yes - + false @@ -88,8 +85,8 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do Path.join(url_base(), "#{media_route(:stream, media_item.uuid)}#{extension}") end - defp feed_image_path(source) do - image_path_on_disk = PostcastHelpers.select_cover_image(source) + defp feed_image_path(source, media_items) do + image_path_on_disk = PodcastHelpers.select_cover_image(source, media_items) case image_path_on_disk do nil -> diff --git a/lib/pinchflat_web/controllers/podcasts/podcast_controller.ex b/lib/pinchflat_web/controllers/podcasts/podcast_controller.ex index b5e2c36..ac4760b 100644 --- a/lib/pinchflat_web/controllers/podcasts/podcast_controller.ex +++ b/lib/pinchflat_web/controllers/podcasts/podcast_controller.ex @@ -2,14 +2,15 @@ defmodule PinchflatWeb.Podcasts.PodcastController do use PinchflatWeb, :controller alias Pinchflat.Repo + alias Pinchflat.Media alias Pinchflat.Podcasts.RssFeedBuilder - alias Pinchflat.Podcasts.PostcastHelpers + alias Pinchflat.Podcasts.PodcastHelpers # TODO: test def rss_feed(conn, %{"uuid" => uuid}) do # TODO: change this to UUID source = Repo.get_by!(Source, id: uuid) - media_items = PostcastHelpers.persisted_media_items_for(source) + media_items = PodcastHelpers.persisted_media_items_for(source) xml = RssFeedBuilder.build(source, media_items) conn @@ -21,7 +22,11 @@ defmodule PinchflatWeb.Podcasts.PodcastController do # TODO: test def feed_image(conn, %{"uuid" => uuid}) do source = Repo.get_by!(Source, uuid: uuid) - filepath = PostcastHelpers.select_cover_image(source) + # This provides a fallback image if the source has none. + # We only need one since we're using the internal metadata image which + # we know exists. + media_items = Media.list_downloaded_media_items_for(source, limit: 1) + filepath = PodcastHelpers.select_cover_image(source, media_items) if filepath && File.exists?(filepath) do conn