diff --git a/app/api/endpoints/system.py b/app/api/endpoints/system.py index 18c84ca3..8f39271d 100644 --- a/app/api/endpoints/system.py +++ b/app/api/endpoints/system.py @@ -1,7 +1,7 @@ import json import json import time -from typing import Any, List +from typing import Any, List, Union from fastapi import APIRouter, HTTPException, Depends from fastapi.responses import StreamingResponse @@ -48,7 +48,8 @@ def get_setting(key: str, _: schemas.TokenPayload = Depends(verify_token)): @router.post("/setting/{key}", summary="更新系统设置") -def set_setting(key: str, value: List[int], _: schemas.TokenPayload = Depends(verify_token)): +def set_setting(key: str, value: Union[list, dict, str, int], + _: schemas.TokenPayload = Depends(verify_token)): """ 更新系统设置 """ diff --git a/app/chain/message.py b/app/chain/message.py index a5119599..5c481d24 100644 --- a/app/chain/message.py +++ b/app/chain/message.py @@ -33,6 +33,7 @@ class MessageChain(ChainBase): self.medtachain = MediaChain() self.torrent = TorrentHelper() self.eventmanager = EventManager() + self.torrenthelper = TorrentHelper() def process(self, body: Any, form: Any, args: Any) -> None: """ @@ -111,7 +112,7 @@ class MessageChain(ChainBase): userid=userid) return # 搜索结果排序 - contexts = TorrentHelper.sort_torrents(contexts) + contexts = self.torrenthelper.sort_torrents(contexts) # 更新缓存 self._user_cache[userid] = { "type": "Torrent", diff --git a/app/chain/search.py b/app/chain/search.py index d449686c..c8647311 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -29,6 +29,7 @@ class SearchChain(ChainBase): self.siteshelper = SitesHelper() self.progress = ProgressHelper() self.systemconfig = SystemConfigOper() + self.torrenthelper = TorrentHelper() def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None) -> Optional[List[Context]]: """ @@ -188,7 +189,7 @@ class SearchChain(ChainBase): media_info=mediainfo, torrent_info=torrent) for torrent in _match_torrents] # 排序 - contexts = TorrentHelper.sort_torrents(contexts) + contexts = self.torrenthelper.sort_torrents(contexts) # 返回 return contexts diff --git a/app/helper/torrent.py b/app/helper/torrent.py index a9578936..d0f931ee 100644 --- a/app/helper/torrent.py +++ b/app/helper/torrent.py @@ -10,9 +10,10 @@ from torrentool.api import Torrent from app.core.config import settings from app.core.context import Context from app.core.metainfo import MetaInfo +from app.db.systemconfig_oper import SystemConfigOper from app.log import logger from app.utils.http import RequestUtils -from app.schemas.types import MediaType +from app.schemas.types import MediaType, SystemConfigKey class TorrentHelper: @@ -20,6 +21,9 @@ class TorrentHelper: 种子帮助类 """ + def __init__(self): + self.system_config = SystemConfigOper() + def download_torrent(self, url: str, cookie: str = None, ua: str = None, @@ -165,8 +169,7 @@ class TorrentHelper: file_name = str(datetime.datetime.now()) return file_name - @staticmethod - def sort_torrents(torrent_list: List[Context]) -> List[Context]: + def sort_torrents(self, torrent_list: List[Context]) -> List[Context]: """ 对种子对行排序 """ @@ -185,7 +188,9 @@ class TorrentHelper: _season_len = str(len(_meta.season_list)).rjust(2, '0') # 集数 _episode_len = str(9999 - len(_meta.episode_list)).rjust(4, '0') - if settings.TORRENT_PRI != "site": + # 优先规则 + priority = self.system_config.get(SystemConfigKey.TorrentsPriority) + if priority != "site": # 排序:标题、资源类型、做种、季集 return "%s%s%s%s" % (str(_torrent.title).ljust(100, ' '), str(_torrent.pri_order).rjust(3, '0'), diff --git a/app/schemas/types.py b/app/schemas/types.py index 99fec6c3..7f844efd 100644 --- a/app/schemas/types.py +++ b/app/schemas/types.py @@ -38,6 +38,8 @@ class SystemConfigKey(Enum): SearchResults = "SearchResults" # 索引站点范围 IndexerSites = "IndexerSites" + # 种子优先级规则 + TorrentsPriority = "TorrentsPriority" # 站点框架