Skip to content

Commit

Permalink
#136 use cover image also for podlove player
Browse files Browse the repository at this point in the history
  • Loading branch information
ephes committed May 9, 2024
1 parent efff9a3 commit b863692
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
19 changes: 11 additions & 8 deletions cast/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ class Meta:
model = Audio
fields = ("version", "show", "title", "subtitle", "audio", "duration", "chapters", "link")

def get_show(self, instance: Audio) -> dict:
def get_show(self, _instance: Audio) -> dict:
post = self.context.get("post") # Get the Post object from the context
if post is None:
return {}
blog = post.blog.specific
episode = post.specific
podcast = post.blog.specific
metadata = {
"title": blog.title,
"subtitle": blog.description,
# "summary": "Ein bisschen Beschreibungstext", # FIXME not implemented
"link": blog.full_url,
"title": podcast.title,
"subtitle": podcast.description,
"summary": podcast.search_description, # FIXME is this correct?
"link": podcast.full_url,
}
if hasattr(blog, "itunes_artwork") and blog.itunes_artwork is not None:
metadata["poster"] = blog.itunes_artwork.original.url
context = self.context.copy()
if episode.cover_image is not None:
context["cover_image_url"] = episode.cover_image.file.url
metadata["poster"] = episode.get_cover_image_url(context, podcast)
return metadata

@staticmethod
Expand Down
15 changes: 11 additions & 4 deletions tests/api_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from datetime import timedelta
from datetime import datetime, timedelta

import pytest
from django.urls import reverse
from django.utils import timezone

from cast.api.serializers import AudioPodloveSerializer
from cast.api.views import (
AudioPodloveDetailView,
FilteredPagesAPIViewSet,
Expand Down Expand Up @@ -167,9 +168,15 @@ def test_podlove_podlove_detail_endpoint_show_metadata_without_artwork(self, api
assert "show" in podlove_data
assert podlove_data["show"]["title"] == podcast.title
assert podlove_data["show"]["subtitle"] == podcast.description
assert "poster" not in podlove_data["show"]
assert podlove_data["show"]["poster"] == ""
assert podlove_data["show"]["link"] == podcast.full_url

def test_podlove_podlove_detail_endpoint_show_metadata_with_cover_image(self, image, episode):
serializer = AudioPodloveSerializer(context={"post": episode})
episode.cover_image = image
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):
"""Test whether the podlove detail endpoint includes show metadata."""
episode = episode_with_artwork
Expand Down Expand Up @@ -221,9 +228,9 @@ def test_get_comment_training_data_with_authentication(self, api_client):
@pytest.mark.parametrize(
"date, post_filter, len_result",
[
(timezone.datetime(2022, 8, 22), "true", 0), # wrong date facet -> not found
(datetime(2022, 8, 22), "true", 0), # wrong date facet -> not found
(timezone.now(), "true", 1), # correct date facet -> found
(timezone.datetime(2022, 8, 22), "false", 1), # wrong date facet and no post filter -> found
(datetime(2022, 8, 22), "false", 1), # wrong date facet and no post filter -> found
],
)
def test_wagtail_pages_api_with_post_filter(date, post_filter, len_result, rf, blog, post):
Expand Down

0 comments on commit b863692

Please sign in to comment.