From 0a86bab7c913ff682da7cb8d26e26d8dc09724bc Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Thu, 23 Jun 2022 14:00:26 +0200 Subject: [PATCH] don't overwrite image title and link when itunes:image is present --- CONTRIBUTORS.rst | 1 + feedparser/namespaces/itunes.py | 10 ++++++---- tests/entities/image_and_itunes_image.xml | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/entities/image_and_itunes_image.xml diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 7c9077f3d..e2cef8a4b 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -28,3 +28,4 @@ bug report! * `Aaron Swartz `_ * `Jakub Wilk `_ * `Nestor Rodriguez `_ +* `Niko Abeler `_ diff --git a/feedparser/namespaces/itunes.py b/feedparser/namespaces/itunes.py index a50a0ea89..20001ebe5 100644 --- a/feedparser/namespaces/itunes.py +++ b/feedparser/namespaces/itunes.py @@ -91,10 +91,12 @@ def _start_itunes_category(self, attrs_d): def _start_itunes_image(self, attrs_d): self.push('itunes_image', 0) - if attrs_d.get('href'): - self._get_context()['image'] = FeedParserDict({'href': attrs_d.get('href')}) - elif attrs_d.get('url'): - self._get_context()['image'] = FeedParserDict({'href': attrs_d.get('url')}) + href = attrs_d.get('href', attrs_d.get('url', None)) + if href: + if "image" not in self._get_context(): + self._get_context()['image'] = FeedParserDict({'href': href}) + else: + self._get_context()['image']['href'] = href _start_itunes_link = _start_itunes_image def _end_itunes_block(self): diff --git a/tests/entities/image_and_itunes_image.xml b/tests/entities/image_and_itunes_image.xml new file mode 100644 index 000000000..32452b630 --- /dev/null +++ b/tests/entities/image_and_itunes_image.xml @@ -0,0 +1,14 @@ + + + + + https://example.com/image.png + Image Test + https://example.com + + + + \ No newline at end of file