From 906bbb34bbb61984d9bfc9116cfbfe80e1523760 Mon Sep 17 00:00:00 2001 From: Tony Wasserka <918-neobrain@users.noreply.dev.funkwhale.audio> Date: Sun, 11 Apr 2021 14:47:59 +0200 Subject: [PATCH] Display RSS episode descriptions based on the RSS tags The previously used tag often only contains plain text, whereas is typically HTML-encoded and hence better suited for display. Closes #1405 --- api/funkwhale_api/audio/serializers.py | 22 +++++++++++++++++++++- changes/changelog.d/1405.bugfix | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changes/changelog.d/1405.bugfix diff --git a/api/funkwhale_api/audio/serializers.py b/api/funkwhale_api/audio/serializers.py index e15325d8c..0bd8e6c4a 100644 --- a/api/funkwhale_api/audio/serializers.py +++ b/api/funkwhale_api/audio/serializers.py @@ -636,6 +636,7 @@ class RssFeedItemSerializer(serializers.Serializer): links = serializers.ListField() tags = serializers.ListField(required=False) summary_detail = serializers.DictField(required=False) + content = serializers.ListField(required=False) published_parsed = DummyField(required=False) image = serializers.DictField(required=False) @@ -648,6 +649,16 @@ class RssFeedItemSerializer(serializers.Serializer): "text": content, } + def validate_content(self, v): + # TODO: Are there RSS feeds that use more than one content item? + content = v[0].get("value") + if not content: + return + return { + "content_type": v[0].get("type", "text/plain"), + "text": content, + } + def validate_image(self, v): url = v.get("href") if url: @@ -782,7 +793,16 @@ class RssFeedItemSerializer(serializers.Serializer): if tags: tags_models.set_tags(track, *tags) - summary = validated_data.get("summary_detail") + # "content" refers to the node in the RSS feed, + # whereas "summary_detail" refers to the node. + # is intended to be used as a short summary and is often + # encoded merely as plain text, whereas contains + # the full episode description and is generally encoded as HTML. + # + # For details, see https://www.rssboard.org/rss-profile#element-channel-item-description + summary = validated_data.get("content") + if not summary: + summary = validated_data.get("summary_detail") if summary: common_utils.attach_content(track, "description", summary) diff --git a/changes/changelog.d/1405.bugfix b/changes/changelog.d/1405.bugfix new file mode 100644 index 000000000..6c3ed5752 --- /dev/null +++ b/changes/changelog.d/1405.bugfix @@ -0,0 +1 @@ +Improve formatting of RSS episode descriptions (#1405)