Display RSS episode descriptions based on the <content:encoded> RSS tags

The previously used <description> tag often only contains plain text,
whereas <content:encoded> is typically HTML-encoded and hence better
suited for display.

Closes #1405
This commit is contained in:
Tony Wasserka 2021-04-11 14:47:59 +02:00 committed by Georg Krause
parent 369122b32b
commit 906bbb34bb
2 changed files with 22 additions and 1 deletions

View File

@ -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,6 +793,15 @@ class RssFeedItemSerializer(serializers.Serializer):
if tags:
tags_models.set_tags(track, *tags)
# "content" refers to the <content:encoded> node in the RSS feed,
# whereas "summary_detail" refers to the <description> node.
# <description> is intended to be used as a short summary and is often
# encoded merely as plain text, whereas <content:encoded> 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)

View File

@ -0,0 +1 @@
Improve formatting of RSS episode descriptions (#1405)