From 250270d97cafa5d739fb29bca83ec2297c803b10 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 22 Aug 2026 20:13:28 +0800 Subject: [PATCH] refactor: migrate torrent helper configuration --- app/application/torrent.py | 12 +++++++----- .../architecture/configuration-debt-baseline.json | 3 +-- tests/fixtures/architecture/dependency-baseline.json | 5 ++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/application/torrent.py b/app/application/torrent.py index c2069ee02..ae4698953 100644 --- a/app/application/torrent.py +++ b/app/application/torrent.py @@ -8,7 +8,7 @@ from urllib.parse import unquote from torrentool.api import Torrent from app.runtime.cache import TTLCache, FileCache -from app.runtime.config import settings +from app.application.configuration import get_chain_runtime_config_snapshot from app.domain.context import Context, TorrentInfo, MediaInfo from app.domain.meta.metabase import MetaBase from app.domain.meta.metamusic import audio_quality_tier, normalize_audio_format, parse_audio_quality @@ -126,11 +126,12 @@ class TorrentHelper: except Exception as err: logger.error(f"处理缓存的种子文件 {cache_path} 时出错: {err},将重新下载") # 下载种子文件 + config = get_chain_runtime_config_snapshot() req = RequestUtils( ua=ua, cookies=cookie, referer=referer, - proxies=settings.PROXY if proxy else None + proxies=config.proxy if proxy else None ).get_res(url=url, allow_redirects=False) while req and req.status_code in [301, 302]: url = req.headers['Location'] @@ -140,7 +141,7 @@ class TorrentHelper: ua=ua, cookies=cookie, referer=referer, - proxies=settings.PROXY if proxy else None + proxies=config.proxy if proxy else None ).get_res(url=url, allow_redirects=False) if req and req.status_code == 200: if not req.content: @@ -169,7 +170,7 @@ class TorrentHelper: ua=ua, cookies=cookie, referer=referer, - proxies=settings.PROXY if proxy else None + proxies=config.proxy if proxy else None ).post_res(url=action, data=data) if req and req.status_code == 200: # 检查是不是种子文件,如果不是抛出异常 @@ -401,11 +402,12 @@ class TorrentHelper: :return: 识别到的全部集数 """ episodes = [] + config = get_chain_runtime_config_snapshot() for file in files: if not file: continue file_path = Path(file) - if not file_path.suffix or file_path.suffix.lower() not in settings.RMT_MEDIAEXT: + if not file_path.suffix or file_path.suffix.lower() not in config.video_extensions: continue # 只使用文件名识别 meta = MetaInfo(file_path.name, custom_words=custom_words) diff --git a/tests/fixtures/architecture/configuration-debt-baseline.json b/tests/fixtures/architecture/configuration-debt-baseline.json index e424599d4..bc3f30ed0 100644 --- a/tests/fixtures/architecture/configuration-debt-baseline.json +++ b/tests/fixtures/architecture/configuration-debt-baseline.json @@ -9,7 +9,7 @@ "root": "app" }, "settings_imports": { - "count": 135, + "count": 134, "files": [ "app/adapters/cache/backends.py", "app/adapters/cache/redis.py", @@ -53,7 +53,6 @@ "app/application/security/passkey.py", "app/application/security/token.py", "app/application/security/url.py", - "app/application/torrent.py", "app/cli.py", "app/db/base.py", "app/db/engine.py", diff --git a/tests/fixtures/architecture/dependency-baseline.json b/tests/fixtures/architecture/dependency-baseline.json index 8fa59fb8e..b91532d9a 100644 --- a/tests/fixtures/architecture/dependency-baseline.json +++ b/tests/fixtures/architecture/dependency-baseline.json @@ -13,8 +13,8 @@ "runtime_to_db": [], "workflow_to_db": [] }, - "edge_count": 6397, - "edge_sha256": "801b80e33c626aecf70e5320a2c1c81db401549faa652e718be7386bac593f43", + "edge_count": 6396, + "edge_sha256": "343715ec8f599f096a45de0dd279d493e7eea7bcde70079f0df0446019578073", "edges": [ "app -> app.runtime", "app -> app.runtime.compat", @@ -2787,7 +2787,6 @@ "app.application.torrent -> app.foundation.text", "app.application.torrent -> app.runtime", "app.application.torrent -> app.runtime.cache", - "app.application.torrent -> app.runtime.config", "app.application.torrent -> app.runtime.log", "app.application.torrent -> app.schemas", "app.application.torrent -> app.schemas.media",