[WIP] Moar refactoring
This commit is contained in:
parent
9fd061918e
commit
24e6b2e868
3 changed files with 20 additions and 21 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 <description>
|
||||
# - Serve proper images instead of the placeholders
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0"
|
||||
|
|
@ -29,7 +26,7 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
|
|||
<channel>
|
||||
<title>#{source.custom_name}</title>
|
||||
<link>#{source.original_url}</link>
|
||||
<description>#{source.custom_name}</description>
|
||||
<description>#{source.description}</description>
|
||||
<category>TV & Film</category>
|
||||
<generator>Generated by Pinchflat</generator>
|
||||
<language>en-us</language>
|
||||
|
|
@ -39,14 +36,14 @@ defmodule Pinchflat.Podcasts.RssFeedBuilder do
|
|||
<podcast:locked>yes</podcast:locked>
|
||||
<podcast:guid>#{source.uuid}</podcast:guid>
|
||||
<image>
|
||||
<url>#{feed_image_path(source)}</url>
|
||||
<url>#{feed_image_path(source, media_items)}</url>
|
||||
<title>#{source.custom_name}</title>
|
||||
<link>#{source.original_url}</link>
|
||||
</image>
|
||||
<itunes:author>#{source.custom_name}</itunes:author>
|
||||
<itunes:subtitle>#{source.custom_name}</itunes:subtitle>
|
||||
<itunes:block>yes</itunes:block>
|
||||
<itunes:image href="#{feed_image_path(source)}"></itunes:image>
|
||||
<itunes:image href="#{feed_image_path(source, media_items)}"></itunes:image>
|
||||
<itunes:explicit>false</itunes:explicit>
|
||||
<itunes:category text="TV & Film"></itunes:category>
|
||||
|
||||
|
|
@ -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 ->
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue