This commit is contained in:
jxxghp 2023-08-13 08:42:36 +08:00
parent 51b30e8e63
commit 9c0c7e8497
7 changed files with 149 additions and 153 deletions

View File

@ -2,11 +2,12 @@ import gc
import pickle import pickle
import traceback import traceback
from abc import ABCMeta from abc import ABCMeta
from msilib.schema import File
from pathlib import Path from pathlib import Path
from typing import Optional, Any, Tuple, List, Set, Union, Dict from typing import Optional, Any, Tuple, List, Set, Union, Dict
from qbittorrentapi import TorrentFilesList
from ruamel.yaml import CommentedMap from ruamel.yaml import CommentedMap
from transmission_rpc import File
from app.core.config import settings from app.core.config import settings
from app.core.context import Context from app.core.context import Context
@ -308,7 +309,7 @@ class ChainBase(metaclass=ABCMeta):
""" """
return self.run_module("stop_torrents", hashs=hashs) return self.run_module("stop_torrents", hashs=hashs)
def torrent_files(self, tid: str) -> Optional[List[File]]: def torrent_files(self, tid: str) -> Optional[Union[TorrentFilesList, List[File]]]:
""" """
根据种子文件选择并添加下载任务 根据种子文件选择并添加下载任务
:param tid: 种子Hash :param tid: 种子Hash

View File

@ -1,5 +1,4 @@
import re import re
from msilib.schema import File
from pathlib import Path from pathlib import Path
from typing import List, Optional, Tuple, Set, Dict, Union from typing import List, Optional, Tuple, Set, Dict, Union
@ -624,13 +623,3 @@ class DownloadChain(ChainBase):
删除下载任务 删除下载任务
""" """
return self.remove_torrents(hashs=[hash_str]) return self.remove_torrents(hashs=[hash_str])
def get_files(self, tid: str) -> Optional[List[File]]:
"""
获取种子文件清单
"""
try:
return self.torrent_files(tid=tid)
except Exception as err:
logger.error(f"获取种子文件列表出错:{err}")
return None

View File

@ -1,6 +1,7 @@
import json import json
import re import re
import shutil import shutil
import threading
from pathlib import Path from pathlib import Path
from typing import List, Optional, Union from typing import List, Optional, Union
@ -19,6 +20,8 @@ from app.schemas.types import TorrentStatus, EventType, MediaType, ProgressKey,
from app.utils.string import StringUtils from app.utils.string import StringUtils
from app.utils.system import SystemUtils from app.utils.system import SystemUtils
lock = threading.Lock()
class TransferChain(ChainBase): class TransferChain(ChainBase):
""" """
@ -52,6 +55,8 @@ class TransferChain(ChainBase):
else: else:
return None, None return None, None
# 全局锁,避免重复处理
with lock:
if arg_str: if arg_str:
logger.info(f"开始转移下载器文件,参数:{arg_str}") logger.info(f"开始转移下载器文件,参数:{arg_str}")
# 解析中种子hashTMDB ID # 解析中种子hashTMDB ID

View File

@ -1,7 +1,8 @@
from msilib.schema import File
from pathlib import Path from pathlib import Path
from typing import Set, Tuple, Optional, Union, List from typing import Set, Tuple, Optional, Union, List
from qbittorrentapi import TorrentFilesList
from app import schemas from app import schemas
from app.core.config import settings from app.core.config import settings
from app.core.metainfo import MetaInfo from app.core.metainfo import MetaInfo
@ -188,7 +189,7 @@ class QbittorrentModule(_ModuleBase):
""" """
return self.qbittorrent.start_torrents(ids=hashs) return self.qbittorrent.start_torrents(ids=hashs)
def torrent_files(self, tid: str) -> Optional[List[File]]: def torrent_files(self, tid: str) -> Optional[TorrentFilesList]:
""" """
获取种子文件列表 获取种子文件列表
""" """

View File

@ -1,9 +1,8 @@
import time import time
from msilib.schema import File
from typing import Optional, Union, Tuple, List from typing import Optional, Union, Tuple, List
import qbittorrentapi import qbittorrentapi
from qbittorrentapi import TorrentDictionary from qbittorrentapi import TorrentDictionary, TorrentFilesList
from qbittorrentapi.client import Client from qbittorrentapi.client import Client
from qbittorrentapi.transfer import TransferInfoDictionary from qbittorrentapi.transfer import TransferInfoDictionary
@ -266,7 +265,7 @@ class Qbittorrent(metaclass=Singleton):
logger.error(f"删除种子出错:{err}") logger.error(f"删除种子出错:{err}")
return False return False
def get_files(self, tid: str) -> Optional[List[File]]: def get_files(self, tid: str) -> Optional[TorrentFilesList]:
""" """
获取种子文件清单 获取种子文件清单
""" """

View File

@ -1,7 +1,8 @@
from msilib.schema import File
from pathlib import Path from pathlib import Path
from typing import Set, Tuple, Optional, Union, List from typing import Set, Tuple, Optional, Union, List
from transmission_rpc import File
from app import schemas from app import schemas
from app.core.config import settings from app.core.config import settings
from app.core.metainfo import MetaInfo from app.core.metainfo import MetaInfo

View File

@ -715,7 +715,7 @@ class MediaSyncDel(_PluginBase):
logger.info(f"{history_key} 转种时未删除源下载任务,开始删除源下载任务…") logger.info(f"{history_key} 转种时未删除源下载任务,开始删除源下载任务…")
try: try:
dl_files = self.chain.get_files(tid=torrent_hash) dl_files = self.chain.torrent_files(tid=torrent_hash)
if not dl_files: if not dl_files:
logger.info(f"未获取到 {settings.DOWNLOADER} - {torrent_hash} 种子文件,种子已被删除") logger.info(f"未获取到 {settings.DOWNLOADER} - {torrent_hash} 种子文件,种子已被删除")
else: else:
@ -736,7 +736,7 @@ class MediaSyncDel(_PluginBase):
# 如果是False则说明种子文件没有完全被删除暂停种子暂不处理 # 如果是False则说明种子文件没有完全被删除暂停种子暂不处理
if delete_flag: if delete_flag:
try: try:
dl_files = self.chain.get_files(tid=download_id) dl_files = self.chain.torrent_files(tid=download_id)
if not dl_files: if not dl_files:
logger.info(f"未获取到 {download} - {download_id} 种子文件,种子已被删除") logger.info(f"未获取到 {download} - {download_id} 种子文件,种子已被删除")
else: else: