Skip to content

Commit

Permalink
#136 do not use iTunes artwork as a cover image - better to be explic…
Browse files Browse the repository at this point in the history
…it here
  • Loading branch information
ephes committed Jun 26, 2024
1 parent 5f87a35 commit 57c07d2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 31 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ repos:
- Pygments
- python-slugify
- setuptools
- types-pytz
- wagtail
- wagtail_srcset
- types-python-slugify
9 changes: 0 additions & 9 deletions cast/models/index_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,6 @@ def itunes_categories_parsed(self) -> dict[str, list[str]]:
except json.decoder.JSONDecodeError:
return {}

def get_cover_image_context(self) -> dict[str, str]:
context = super().get_cover_image_context()
if context["cover_image_url"] == "":
# fallback to itunes artwork
if self.itunes_artwork is not None:
context["cover_image_url"] = self.itunes_artwork.original.url
context["cover_alt_text"] = "iTunes Artwork"
return context

def get_context(self, request: HtmxHttpRequest, *args, **kwargs) -> ContextDict:
context = super().get_context(request, *args, **kwargs)
context["podcast"] = self # conveniece
Expand Down
5 changes: 2 additions & 3 deletions docs/episode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ In addition to the effect setting a cover image for a post has, setting a
cover image for an episode will also be used as the episode's artwork in the
podcast feed and in the Podlove Web Player.

If no cover image is set for the episode, the blog’s cover image will be used.
If the :ref:`blog <blog_overview>` does not have a cover image, the podcast’s
iTunes artwork will be used as the episode’s cover image.
If no cover image is set for the episode, the :ref:`blog <blog_overview>`’s cover
image will be used.

Podcast Audio
=============
Expand Down
12 changes: 7 additions & 5 deletions tests/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,23 @@ def test_podlove_podlove_detail_endpoint_show_metadata_with_cover_image(self, im
metadata = serializer.get_show(episode.podcast_audio)
assert metadata["poster"] == image.file.url

def test_podlove_podlove_detail_endpoint_show_metadata(self, api_client, episode_with_artwork):
def test_podlove_podlove_detail_endpoint_show_metadata(
self, api_client, image, episode_with_podcast_with_cover_image
):
"""Test whether the podlove detail endpoint includes show metadata."""
episode = episode_with_artwork
episode = episode_with_podcast_with_cover_image
audio = episode.podcast_audio
podlove_detail_url = reverse("cast:api:audio_podlove_detail", kwargs={"pk": audio.pk, "post_id": episode.pk})
podcast = episode.blog.specific

podlove_detail_url = reverse("cast:api:audio_podlove_detail", kwargs={"pk": audio.pk, "post_id": episode.pk})
r = api_client.get(podlove_detail_url, format="json")
assert r.status_code == 200

podlove_data = r.json()
podcast = episode.blog.specific
assert "show" in podlove_data
assert podlove_data["show"]["title"] == podcast.title
assert podlove_data["show"]["subtitle"] == podcast.description
assert podlove_data["show"]["poster"] == podcast.itunes_artwork.original.url
assert podlove_data["show"]["poster"] == podcast.cover_image.file.url
assert podlove_data["show"]["link"] == podcast.full_url

def test_podlove_player_config(self, api_client):
Expand Down
20 changes: 20 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ def podcast(user, site):
return PodcastFactory(owner=user, title="test podcast", slug="test_podcast", parent=site.root_page)


@pytest.fixture()
def podcast_with_cover_image(user, site, image):
return PodcastFactory(
owner=user, title="test podcast", slug="test_podcast", parent=site.root_page, cover_image=image
)


@pytest.fixture()
def podcast_with_artwork(user, itunes_artwork, site):
return PodcastFactory(
Expand Down Expand Up @@ -493,6 +500,19 @@ def episode_with_artwork(podcast_with_artwork, audio, body):
)


@pytest.fixture()
def episode_with_podcast_with_cover_image(podcast_with_cover_image, audio, body):
podcast = podcast_with_cover_image
return EpisodeFactory(
owner=podcast.owner,
parent=podcast,
title="test podcast episode",
slug="test-podcast-entry",
podcast_audio=audio,
body=body,
)


@pytest.fixture()
def podcast_episode_with_same_audio(blog, audio, body):
return EpisodeFactory(
Expand Down
21 changes: 7 additions & 14 deletions tests/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from cast import appsettings
from cast.models import Blog, Podcast
from cast.models.itunes import ItunesArtWork
from cast.models.pages import CustomEpisodeForm, Episode, HomePage, HtmlField, Post
from cast.models.repository import BlogIndexRepository
from cast.models.video import Video
Expand Down Expand Up @@ -164,6 +163,13 @@ def test_cover_image_from_super(self, mocker):
"cover_alt_text": "",
}

def test_podcast_get_context(self, rf, mocker):
mocker.patch("cast.models.Blog.get_context", return_value={})
request = rf.get("/")
podcast = Podcast(id=1)
context = podcast.get_context(request)
assert context["podcast"] == podcast


class TestPostModel:
pytestmark = pytest.mark.django_db
Expand Down Expand Up @@ -391,19 +397,6 @@ def test_get_cover_image_context(self):
cover_image_url = context["cover_image_url"]
assert cover_image_url == "https://example.org/cover.jpg"

# get cover image from iTunes artwork
class Original:
url = "https://example.org/itunes.jpg"
width = 600
height = 200

artwork = ItunesArtWork(original=Original())
podcast = Podcast(id=1, itunes_artwork=artwork)

context = post.get_cover_image_context({}, podcast)
cover_image_url = context["cover_image_url"]
assert cover_image_url == "https://example.org/itunes.jpg"

def test_get_cached_media_lookup(self):
post = Post(id=1)
post._media_lookup = "foobar"
Expand Down

0 comments on commit 57c07d2

Please sign in to comment.