Skip to content

Commit df81760

Browse files
authored
Parse boolean itunes:explicit values (true/false/no) (#567)
2 parents 0fc1e95 + 25c94a3 commit df81760

8 files changed

Lines changed: 21 additions & 12 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Fixed
2+
-----
3+
4+
* Map ``<itunes:explicit>`` values ``true`` and ``yes`` to ``True``
5+
and ``false``, ``no``, and ``clean`` to ``False``. Previously only
6+
``yes`` and ``clean`` were recognized, so the boolean values defined
7+
by the current Apple Podcasts spec were parsed as ``None``. (#524)

feedparser/namespaces/itunes.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ def _end_itunes_block(self):
105105

106106
def _end_itunes_explicit(self):
107107
value = self.pop("itunes_explicit", 0)
108-
# Convert 'yes' -> True, 'clean' to False, and any other value to None
109-
# False and None both evaluate as False, so the difference can be ignored
110-
# by applications that only need to know if the content is explicit.
111-
self._get_context()["itunes_explicit"] = (None, False, True)[
112-
(value == "yes" and 2) or value == "clean" or 0
113-
]
108+
# Modern Apple spec uses true/false; yes/no/clean are legacy values.
109+
if value in ("yes", "true"):
110+
explicit = True
111+
elif value in ("no", "false", "clean"):
112+
explicit = False
113+
else:
114+
explicit = None
115+
self._get_context()["itunes_explicit"] = explicit

tests/wellformed/itunes/itunes_channel_explicit_false.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Description: iTunes explicit="false"
3-
Expect: not bozo and feed['itunes_explicit'] is None
3+
Expect: not bozo and feed['itunes_explicit'] is False
44
-->
55
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd">
66
<channel>

tests/wellformed/itunes/itunes_channel_explicit_no.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Description: iTunes explicit='no'
3-
Expect: not bozo and feed['itunes_explicit'] is None
3+
Expect: not bozo and feed['itunes_explicit'] is False
44
-->
55
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd">
66
<channel>

tests/wellformed/itunes/itunes_channel_explicit_true.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Description: iTunes explicit="true"
3-
Expect: not bozo and feed['itunes_explicit'] is None
3+
Expect: not bozo and feed['itunes_explicit'] is True
44
-->
55
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd">
66
<channel>

tests/wellformed/itunes/itunes_item_explicit_false.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Description: iTunes explicit="false"
3-
Expect: not bozo and entries[0]['itunes_explicit'] is None
3+
Expect: not bozo and entries[0]['itunes_explicit'] is False
44
-->
55
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd">
66
<channel>

tests/wellformed/itunes/itunes_item_explicit_no.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Description: iTunes explicit='no'
3-
Expect: not bozo and entries[0]['itunes_explicit'] is None
3+
Expect: not bozo and entries[0]['itunes_explicit'] is False
44
-->
55
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd">
66
<channel>

tests/wellformed/itunes/itunes_item_explicit_true.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
Description: iTunes explicit="true"
3-
Expect: not bozo and entries[0]['itunes_explicit'] is None
3+
Expect: not bozo and entries[0]['itunes_explicit'] is True
44
-->
55
<rss xmlns:itunes="http://www.itunes.com/DTDs/Podcast-1.0.dtd">
66
<channel>

0 commit comments

Comments
 (0)