Skip to content

Commit

Permalink
fix #118
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Aug 15, 2023
1 parent 71c3dbc commit 3bebc22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/api/endpoints/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from app.db import get_db
from app.db.models.downloadhistory import DownloadHistory
from app.db.models.transferhistory import TransferHistory
from app.schemas import MediaType

router = APIRouter()

Expand Down Expand Up @@ -81,13 +82,14 @@ def delete_transfer_history(history_in: schemas.TransferHistory,

@router.post("/transfer", summary="历史记录重新转移", response_model=schemas.Response)
def redo_transfer_history(history_in: schemas.TransferHistory,
mtype: str,
new_tmdbid: int,
_: schemas.TokenPayload = Depends(verify_token)) -> Any:
"""
历史记录重新转移
"""
hash_str = history_in.download_hash
result = TransferChain().process(f"{hash_str} {new_tmdbid}")
result = TransferChain().process(f"{hash_str} {new_tmdbid}|{mtype}")
if result:
return schemas.Response(success=True)
else:
Expand Down
15 changes: 11 additions & 4 deletions app/chain/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self):
def process(self, arg_str: str = None, channel: MessageChannel = None, userid: Union[str, int] = None) -> bool:
"""
获取下载器中的种子列表,并执行转移
:param arg_str: 传入的参数 (种子hash和TMDB ID)
:param arg_str: 传入的参数 (种子hash和TMDBID|类型)
:param channel: 消息通道
:param userid: 用户ID
"""
Expand All @@ -59,6 +59,13 @@ def extract_hash_and_number(string: str):
with lock:
if arg_str:
logger.info(f"开始转移下载器文件,参数:{arg_str}")
# 解析中附带的类型
args = arg_str.split('|')
if len(args) > 1:
mtype = MediaType(args[-1])
arg_str = args[0]
else:
mtype = None
# 解析中种子hash,TMDB ID
torrent_hash, tmdbid = extract_hash_and_number(arg_str)
if not hash or not tmdbid:
Expand All @@ -67,10 +74,10 @@ def extract_hash_and_number(string: str):
# 获取种子
torrents: Optional[List[TransferTorrent]] = self.list_torrents(hashs=torrent_hash)
if not torrents:
logger.error(f"没有获取到种子,参数:{arg_str}")
logger.error(f"没有获取到种子,参数:{torrent_hash}")
return False
# 查询媒体信息
arg_mediainfo = self.recognize_media(tmdbid=tmdbid)
arg_mediainfo = self.recognize_media(mtype=mtype, tmdbid=tmdbid)
else:
arg_mediainfo = None
logger.info("开始执行下载器文件转移 ...")
Expand Down Expand Up @@ -123,7 +130,7 @@ def extract_hash_and_number(string: str):
channel=channel,
mtype=NotificationType.Manual,
title=f"{torrent.title} 未识别到媒体信息,无法入库!\n"
f"回复:```\n/transfer {torrent.hash} [tmdbid]\n``` 手动识别转移。",
f"回复:```\n/transfer {torrent.hash} [tmdbid]|[类型]\n``` 手动识别转移。",
userid=userid))
# 新增转移失败历史记录
self.transferhis.add(
Expand Down

0 comments on commit 3bebc22

Please sign in to comment.