diff --git a/app/modules/indexer/spider/hddolby.py b/app/modules/indexer/spider/hddolby.py index acca30046..8db2ee69f 100644 --- a/app/modules/indexer/spider/hddolby.py +++ b/app/modules/indexer/spider/hddolby.py @@ -8,6 +8,7 @@ from urllib.parse import urlparse from app.adapters.network.http import AsyncRequestUtils, RequestUtils from app.application.configuration import get_configured_system_config from app.domain import site as site_rules +from app.foundation import text as text_tools from app.runtime.log import logger from app.runtime.settings import get_runtime_setting from app.schemas.types import MediaType @@ -196,6 +197,7 @@ class HddolbySpider: 'freedate': result.get('promotion_until'), 'page_url': self._pageurl % result.get('id') if self._pageurl else '', 'labels': torrentLabels, + 'hit_and_run': text_tools.parse_bool(result.get('hr')), 'category': category } torrents.append(torrent) diff --git a/tests/test_hddolby_spider.py b/tests/test_hddolby_spider.py index 304878830..a7ae36909 100644 --- a/tests/test_hddolby_spider.py +++ b/tests/test_hddolby_spider.py @@ -76,6 +76,20 @@ def test_parse_result_marks_music_torrents(hddolby_spider): ] +def test_parse_result_maps_hit_and_run(hddolby_spider): + """ + hr 标记应映射为 hit_and_run,兼容数值、字符串和缺失字段。 + """ + results = hddolby_spider._HddolbySpider__parse_result([ + {"id": 1, "name": "The Odyssey 2026 2160p", "category": 401, "size": 1024, "hr": 1}, + {"id": 2, "name": "Example Movie 1080p", "category": 401, "size": 1024, "hr": 0}, + {"id": 3, "name": "Example TV 1080p", "category": 402, "size": 1024, "hr": "1"}, + {"id": 4, "name": "Example TV 2160p", "category": 402, "size": 1024}, + ]) + + assert [torrent["hit_and_run"] for torrent in results] == [True, False, True, False] + + @pytest.mark.parametrize("asynchronous", [False, True]) @pytest.mark.parametrize( ("domain", "api_url", "expected_url"),