Adds thumbnails as episode-level images for podcasts (#201)
This commit is contained in:
@@ -137,6 +137,34 @@ defmodule Pinchflat.Podcasts.RssFeedBuilderTest do
|
||||
assert String.contains?(item_xml, ~s(length="1234"))
|
||||
assert String.contains?(item_xml, ~s(type="video/mp4"))
|
||||
end
|
||||
|
||||
test "returns image tags if the media has a thumbnail", %{source: source} do
|
||||
media_item = media_item_with_attachments(%{source_id: source.id, media_size_bytes: 1234})
|
||||
|
||||
res = RssFeedBuilder.build(source)
|
||||
[_before, item_xml, _after] = String.split(res, ~r(</?item>))
|
||||
|
||||
assert String.contains?(
|
||||
item_xml,
|
||||
~s(<itunes:image href="http://localhost:8945/media/#{media_item.uuid}/episode_image.jpg"></itunes:image>)
|
||||
)
|
||||
|
||||
assert String.contains?(
|
||||
item_xml,
|
||||
~s(<podcast:images srcset="http://localhost:8945/media/#{media_item.uuid}/episode_image.jpg" />)
|
||||
)
|
||||
end
|
||||
|
||||
test "does not return image tags if the media does not have a thumbnail", %{source: source} do
|
||||
media_item = media_item_with_attachments(%{source_id: source.id})
|
||||
File.rm!(media_item.thumbnail_filepath)
|
||||
|
||||
res = RssFeedBuilder.build(source)
|
||||
[_before, item_xml, _after] = String.split(res, ~r(</?item>))
|
||||
|
||||
refute String.contains?(item_xml, ~s(itunes:image))
|
||||
refute String.contains?(item_xml, ~s(podcast:images))
|
||||
end
|
||||
end
|
||||
|
||||
defp format_date(date) do
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
defmodule PinchflatWeb.PodcastControllerTest do
|
||||
use PinchflatWeb.ConnCase
|
||||
|
||||
import Pinchflat.MediaFixtures
|
||||
import Pinchflat.SourcesFixtures
|
||||
|
||||
describe "rss_feed" do
|
||||
@@ -35,4 +36,25 @@ defmodule PinchflatWeb.PodcastControllerTest do
|
||||
assert conn.resp_body == "Image not found"
|
||||
end
|
||||
end
|
||||
|
||||
describe "episode_image" do
|
||||
test "returns an episode image if one can be found", %{conn: conn} do
|
||||
media_item = media_item_with_attachments()
|
||||
|
||||
conn = get(conn, ~p"/media/#{media_item.uuid}/episode_image" <> ".jpg")
|
||||
|
||||
assert conn.status == 200
|
||||
assert {"content-type", "image/jpeg; charset=utf-8"} in conn.resp_headers
|
||||
assert conn.resp_body == File.read!(media_item.thumbnail_filepath)
|
||||
end
|
||||
|
||||
test "returns 404 if an image cannot be found", %{conn: conn} do
|
||||
media_item = media_item_fixture()
|
||||
|
||||
conn = get(conn, ~p"/media/#{media_item.uuid}/episode_image" <> ".jpg")
|
||||
|
||||
assert conn.status == 404
|
||||
assert conn.resp_body == "Image not found"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,16 +67,24 @@ defmodule Pinchflat.MediaFixtures do
|
||||
end
|
||||
|
||||
def media_item_with_attachments(attrs \\ %{}) do
|
||||
stored_media_filepath =
|
||||
base_dir =
|
||||
Path.join([
|
||||
Application.get_env(:pinchflat, :media_directory),
|
||||
"#{:rand.uniform(1_000_000)}",
|
||||
"#{:rand.uniform(1_000_000)}_media.mp4"
|
||||
"#{:rand.uniform(1_000_000)}"
|
||||
])
|
||||
|
||||
stored_media_filepath = Path.join(base_dir, "#media.mp4")
|
||||
thumbnail_filepath = Path.join(base_dir, "thumbnail.jpg")
|
||||
|
||||
FilesystemUtils.cp_p!(media_filepath_fixture(), stored_media_filepath)
|
||||
FilesystemUtils.cp_p!(thumbnail_filepath_fixture(), thumbnail_filepath)
|
||||
|
||||
merged_attrs =
|
||||
Map.merge(attrs, %{
|
||||
media_filepath: stored_media_filepath,
|
||||
thumbnail_filepath: thumbnail_filepath
|
||||
})
|
||||
|
||||
merged_attrs = Map.merge(attrs, %{media_filepath: stored_media_filepath})
|
||||
media_item_fixture(merged_attrs)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user