This commit is contained in:
jxxghp 2023-07-09 18:56:04 +08:00
parent 812dc991e3
commit 3f6bb2b381
5 changed files with 18 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import json import json
import json import json
import time import time
from typing import Any, List from typing import Any, List, Union
from fastapi import APIRouter, HTTPException, Depends from fastapi import APIRouter, HTTPException, Depends
from fastapi.responses import StreamingResponse from fastapi.responses import StreamingResponse
@ -48,7 +48,8 @@ def get_setting(key: str, _: schemas.TokenPayload = Depends(verify_token)):
@router.post("/setting/{key}", summary="更新系统设置") @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)):
""" """
更新系统设置 更新系统设置
""" """

View File

@ -33,6 +33,7 @@ class MessageChain(ChainBase):
self.medtachain = MediaChain() self.medtachain = MediaChain()
self.torrent = TorrentHelper() self.torrent = TorrentHelper()
self.eventmanager = EventManager() self.eventmanager = EventManager()
self.torrenthelper = TorrentHelper()
def process(self, body: Any, form: Any, args: Any) -> None: def process(self, body: Any, form: Any, args: Any) -> None:
""" """
@ -111,7 +112,7 @@ class MessageChain(ChainBase):
userid=userid) userid=userid)
return return
# 搜索结果排序 # 搜索结果排序
contexts = TorrentHelper.sort_torrents(contexts) contexts = self.torrenthelper.sort_torrents(contexts)
# 更新缓存 # 更新缓存
self._user_cache[userid] = { self._user_cache[userid] = {
"type": "Torrent", "type": "Torrent",

View File

@ -29,6 +29,7 @@ class SearchChain(ChainBase):
self.siteshelper = SitesHelper() self.siteshelper = SitesHelper()
self.progress = ProgressHelper() self.progress = ProgressHelper()
self.systemconfig = SystemConfigOper() self.systemconfig = SystemConfigOper()
self.torrenthelper = TorrentHelper()
def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None) -> Optional[List[Context]]: def search_by_tmdbid(self, tmdbid: int, mtype: MediaType = None) -> Optional[List[Context]]:
""" """
@ -188,7 +189,7 @@ class SearchChain(ChainBase):
media_info=mediainfo, media_info=mediainfo,
torrent_info=torrent) for torrent in _match_torrents] torrent_info=torrent) for torrent in _match_torrents]
# 排序 # 排序
contexts = TorrentHelper.sort_torrents(contexts) contexts = self.torrenthelper.sort_torrents(contexts)
# 返回 # 返回
return contexts return contexts

View File

@ -10,9 +10,10 @@ from torrentool.api import Torrent
from app.core.config import settings from app.core.config import settings
from app.core.context import Context from app.core.context import Context
from app.core.metainfo import MetaInfo from app.core.metainfo import MetaInfo
from app.db.systemconfig_oper import SystemConfigOper
from app.log import logger from app.log import logger
from app.utils.http import RequestUtils from app.utils.http import RequestUtils
from app.schemas.types import MediaType from app.schemas.types import MediaType, SystemConfigKey
class TorrentHelper: class TorrentHelper:
@ -20,6 +21,9 @@ class TorrentHelper:
种子帮助类 种子帮助类
""" """
def __init__(self):
self.system_config = SystemConfigOper()
def download_torrent(self, url: str, def download_torrent(self, url: str,
cookie: str = None, cookie: str = None,
ua: str = None, ua: str = None,
@ -165,8 +169,7 @@ class TorrentHelper:
file_name = str(datetime.datetime.now()) file_name = str(datetime.datetime.now())
return file_name return file_name
@staticmethod def sort_torrents(self, torrent_list: List[Context]) -> List[Context]:
def sort_torrents(torrent_list: List[Context]) -> List[Context]:
""" """
对种子对行排序 对种子对行排序
""" """
@ -185,7 +188,9 @@ class TorrentHelper:
_season_len = str(len(_meta.season_list)).rjust(2, '0') _season_len = str(len(_meta.season_list)).rjust(2, '0')
# 集数 # 集数
_episode_len = str(9999 - len(_meta.episode_list)).rjust(4, '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, ' '), return "%s%s%s%s" % (str(_torrent.title).ljust(100, ' '),
str(_torrent.pri_order).rjust(3, '0'), str(_torrent.pri_order).rjust(3, '0'),

View File

@ -38,6 +38,8 @@ class SystemConfigKey(Enum):
SearchResults = "SearchResults" SearchResults = "SearchResults"
# 索引站点范围 # 索引站点范围
IndexerSites = "IndexerSites" IndexerSites = "IndexerSites"
# 种子优先级规则
TorrentsPriority = "TorrentsPriority"
# 站点框架 # 站点框架