2023-01-12 01:04:47 +00:00
|
|
|
# Support for the iTunes format
|
2023-04-13 07:04:58 +00:00
|
|
|
# Copyright 2010-2023 Kurt McKee <contactme@kurtmckee.org>
|
2023-01-12 01:04:47 +00:00
|
|
|
# Copyright 2002-2008 Mark Pilgrim
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This file is a part of feedparser.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions and the following disclaimer in the documentation
|
|
|
|
# and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
from ..util import FeedParserDict
|
|
|
|
|
|
|
|
|
2023-04-13 07:04:58 +00:00
|
|
|
class Namespace:
|
2023-01-12 01:04:47 +00:00
|
|
|
supported_namespaces = {
|
|
|
|
# Canonical namespace
|
2023-04-13 07:04:58 +00:00
|
|
|
"http://www.itunes.com/DTDs/PodCast-1.0.dtd": "itunes",
|
2023-01-12 01:04:47 +00:00
|
|
|
# Extra namespace
|
2023-04-13 07:04:58 +00:00
|
|
|
"http://example.com/DTDs/PodCast-1.0.dtd": "itunes",
|
2023-01-12 01:04:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _start_itunes_author(self, attrs_d):
|
|
|
|
self._start_author(attrs_d)
|
|
|
|
|
|
|
|
def _end_itunes_author(self):
|
|
|
|
self._end_author()
|
|
|
|
|
|
|
|
def _end_itunes_category(self):
|
|
|
|
self._end_category()
|
|
|
|
|
|
|
|
def _start_itunes_name(self, attrs_d):
|
|
|
|
self._start_name(attrs_d)
|
|
|
|
|
|
|
|
def _end_itunes_name(self):
|
|
|
|
self._end_name()
|
|
|
|
|
|
|
|
def _start_itunes_email(self, attrs_d):
|
|
|
|
self._start_email(attrs_d)
|
|
|
|
|
|
|
|
def _end_itunes_email(self):
|
|
|
|
self._end_email()
|
|
|
|
|
|
|
|
def _start_itunes_subtitle(self, attrs_d):
|
|
|
|
self._start_subtitle(attrs_d)
|
|
|
|
|
|
|
|
def _end_itunes_subtitle(self):
|
|
|
|
self._end_subtitle()
|
|
|
|
|
|
|
|
def _start_itunes_summary(self, attrs_d):
|
|
|
|
self._start_summary(attrs_d)
|
|
|
|
|
|
|
|
def _end_itunes_summary(self):
|
|
|
|
self._end_summary()
|
|
|
|
|
|
|
|
def _start_itunes_owner(self, attrs_d):
|
|
|
|
self.inpublisher = 1
|
2023-04-13 07:04:58 +00:00
|
|
|
self.push("publisher", 0)
|
2023-01-12 01:04:47 +00:00
|
|
|
|
|
|
|
def _end_itunes_owner(self):
|
2023-04-13 07:04:58 +00:00
|
|
|
self.pop("publisher")
|
2023-01-12 01:04:47 +00:00
|
|
|
self.inpublisher = 0
|
2023-04-13 07:04:58 +00:00
|
|
|
self._sync_author_detail("publisher")
|
2023-01-12 01:04:47 +00:00
|
|
|
|
|
|
|
def _end_itunes_keywords(self):
|
2023-04-13 07:04:58 +00:00
|
|
|
for term in self.pop("itunes_keywords").split(","):
|
2023-01-12 01:04:47 +00:00
|
|
|
if term.strip():
|
2023-04-13 07:04:58 +00:00
|
|
|
self._add_tag(term.strip(), "http://www.itunes.com/", None)
|
2023-01-12 01:04:47 +00:00
|
|
|
|
|
|
|
def _start_itunes_category(self, attrs_d):
|
2023-04-13 07:04:58 +00:00
|
|
|
self._add_tag(attrs_d.get("text"), "http://www.itunes.com/", None)
|
|
|
|
self.push("category", 1)
|
2023-01-12 01:04:47 +00:00
|
|
|
|
|
|
|
def _start_itunes_image(self, attrs_d):
|
2023-04-13 07:04:58 +00:00
|
|
|
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")})
|
|
|
|
|
2023-01-12 01:04:47 +00:00
|
|
|
_start_itunes_link = _start_itunes_image
|
|
|
|
|
|
|
|
def _end_itunes_block(self):
|
2023-04-13 07:04:58 +00:00
|
|
|
value = self.pop("itunes_block", 0)
|
|
|
|
self._get_context()["itunes_block"] = (
|
|
|
|
(value == "yes" or value == "Yes") and 1 or 0
|
|
|
|
)
|
2023-01-12 01:04:47 +00:00
|
|
|
|
|
|
|
def _end_itunes_explicit(self):
|
2023-04-13 07:04:58 +00:00
|
|
|
value = self.pop("itunes_explicit", 0)
|
2023-01-12 01:04:47 +00:00
|
|
|
# Convert 'yes' -> True, 'clean' to False, and any other value to None
|
|
|
|
# False and None both evaluate as False, so the difference can be ignored
|
|
|
|
# by applications that only need to know if the content is explicit.
|
2023-04-13 07:04:58 +00:00
|
|
|
self._get_context()["itunes_explicit"] = (None, False, True)[
|
|
|
|
(value == "yes" and 2) or value == "clean" or 0
|
|
|
|
]
|