diff --git a/catalog/sites/rss.py b/catalog/sites/rss.py index 1dbb97c1..2fbae897 100644 --- a/catalog/sites/rss.py +++ b/catalog/sites/rss.py @@ -10,6 +10,12 @@ from django.utils.timezone import make_aware import bleach from django.core.validators import URLValidator from django.core.exceptions import ValidationError +from catalog.common.downloaders import ( + get_mock_file, + get_mock_mode, + _local_response_path, +) +import pickle _logger = logging.getLogger(__name__) @@ -28,12 +34,20 @@ class RSS(AbstractSite): feed = cache.get(url) if feed: return feed - req = urllib.request.Request(url) - req.add_header("User-Agent", "NeoDB/0.5") - try: - feed = podcastparser.parse(url, urllib.request.urlopen(req, timeout=3)) - except: - return None + if get_mock_mode(): + feed = pickle.load(open(_local_response_path + get_mock_file(url), "rb")) + else: + req = urllib.request.Request(url) + req.add_header("User-Agent", "NeoDB/0.5") + try: + feed = podcastparser.parse(url, urllib.request.urlopen(req, timeout=3)) + except: + return None + if settings.DOWNLOADER_SAVEDIR: + pickle.dump( + feed, + open(settings.DOWNLOADER_SAVEDIR + "/" + get_mock_file(url), "wb"), + ) cache.set(url, feed, timeout=300) return feed diff --git a/test_data/https___anchor_fm_s_64d6bbe0_podcast_rss b/test_data/https___anchor_fm_s_64d6bbe0_podcast_rss new file mode 100644 index 00000000..ef0f195e Binary files /dev/null and b/test_data/https___anchor_fm_s_64d6bbe0_podcast_rss differ diff --git a/test_data/https___podcasts_files_bbci_co_uk_b006qykl_rss b/test_data/https___podcasts_files_bbci_co_uk_b006qykl_rss new file mode 100644 index 00000000..2d062c22 Binary files /dev/null and b/test_data/https___podcasts_files_bbci_co_uk_b006qykl_rss differ diff --git a/test_data/https___rsshub_app_ximalaya_album_51101122_0_shownote b/test_data/https___rsshub_app_ximalaya_album_51101122_0_shownote new file mode 100644 index 00000000..02d63865 Binary files /dev/null and b/test_data/https___rsshub_app_ximalaya_album_51101122_0_shownote differ diff --git a/test_data/https___tiaodao_typlog_io_feed_xml b/test_data/https___tiaodao_typlog_io_feed_xml new file mode 100644 index 00000000..6b6f0433 Binary files /dev/null and b/test_data/https___tiaodao_typlog_io_feed_xml differ diff --git a/test_data/https___www_digforfire_net_digforfire_radio_feed_xml b/test_data/https___www_digforfire_net_digforfire_radio_feed_xml new file mode 100644 index 00000000..4b5455c0 Binary files /dev/null and b/test_data/https___www_digforfire_net_digforfire_radio_feed_xml differ