mirror of
https://github.com/thsrite/MoviePilot-Plugins.git
synced 2026-03-27 10:05:57 +00:00
fix 修复同步下载器种子
This commit is contained in:
@@ -198,7 +198,7 @@
|
||||
"author": "thsrite",
|
||||
"level": 1,
|
||||
"history": {
|
||||
"v1.1.4": "修复同步下载器种子",
|
||||
"v1.1.5": "修复同步下载器种子",
|
||||
"v1.1.3": "支持v2",
|
||||
"v1.1.1": "修复时区问题导致的上次同步后8h内的种子不同步的问题"
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
# 插件图标
|
||||
plugin_icon = "Youtube-dl_A.png"
|
||||
# 插件版本
|
||||
plugin_version = "1.1.4"
|
||||
plugin_version = "1.1.5"
|
||||
# 插件作者
|
||||
plugin_author = "thsrite"
|
||||
# 作者主页
|
||||
@@ -113,19 +113,20 @@ class SyncDownloadFiles(_PluginBase):
|
||||
continue
|
||||
|
||||
# 把种子按照名称和种子大小分组,获取添加时间最早的一个,认定为是源种子,其余为辅种
|
||||
torrents = self.__get_origin_torrents(torrents, downloader)
|
||||
downloader_config = self.__get_downloader_config(downloader)
|
||||
torrents = self.__get_origin_torrents(torrents, downloader_config.type)
|
||||
logger.info(f"下载器 {downloader} 去除辅种,获取到源种子数:{len(torrents)}")
|
||||
|
||||
for torrent in torrents:
|
||||
# 返回false,标识后续种子已被同步
|
||||
sync_flag = self.__compare_time(torrent, downloader, last_sync_time)
|
||||
sync_flag = self.__compare_time(torrent, downloader_config.type, last_sync_time)
|
||||
|
||||
if not sync_flag:
|
||||
logger.info(f"最后同步时间{last_sync_time}, 之前种子已被同步,结束当前下载器 {downloader} 任务")
|
||||
break
|
||||
|
||||
# 获取种子hash
|
||||
hash_str = self.__get_hash(torrent, downloader)
|
||||
hash_str = self.__get_hash(torrent, downloader_config.type)
|
||||
|
||||
# 判断是否是mp下载,判断download_hash是否在downloadhistory表中,是则不处理
|
||||
downloadhis = self.downloadhis.get_by_hash(hash_str)
|
||||
@@ -136,7 +137,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
continue
|
||||
|
||||
# 获取种子download_dir
|
||||
download_dir = self.__get_download_dir(torrent, downloader)
|
||||
download_dir = self.__get_download_dir(torrent, downloader_config.type)
|
||||
|
||||
# 处理路径映射
|
||||
if self._dirs:
|
||||
@@ -146,20 +147,20 @@ class SyncDownloadFiles(_PluginBase):
|
||||
download_dir = download_dir.replace(sub_paths[0], sub_paths[1]).replace('\\', '/')
|
||||
|
||||
# 获取种子name
|
||||
torrent_name = self.__get_torrent_name(torrent, downloader)
|
||||
torrent_name = self.__get_torrent_name(torrent, downloader_config.type)
|
||||
# 种子保存目录
|
||||
save_path = Path(download_dir).joinpath(torrent_name)
|
||||
# 获取种子文件
|
||||
torrent_files = self.__get_torrent_files(torrent, downloader, downloader_obj)
|
||||
torrent_files = self.__get_torrent_files(torrent, downloader_config.type, downloader_obj)
|
||||
logger.info(f"开始同步种子 {hash_str}, 文件数 {len(torrent_files)}")
|
||||
|
||||
download_files = []
|
||||
for file in torrent_files:
|
||||
# 过滤掉没下载的文件
|
||||
if not self.__is_download(file, downloader):
|
||||
if not self.__is_download(file, downloader_config.type):
|
||||
continue
|
||||
# 种子文件路径
|
||||
file_path_str = self.__get_file_path(file, downloader)
|
||||
file_path_str = self.__get_file_path(file, downloader_config.type)
|
||||
file_path = Path(file_path_str)
|
||||
# 只处理视频格式
|
||||
if not file_path.suffix \
|
||||
@@ -224,7 +225,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
grouped_data = {}
|
||||
|
||||
# 排序种子,根据种子添加时间倒序
|
||||
if dl_tpe == "Qbittorrent":
|
||||
if dl_tpe == "qbittorrent":
|
||||
torrents = sorted(torrents, key=lambda x: x.get("added_on"), reverse=True)
|
||||
# 遍历原始数组,按照size和name进行分组
|
||||
for torrent in torrents:
|
||||
@@ -262,7 +263,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
def __compare_time(torrent: Any, dl_tpe: str, last_sync_time: str = None):
|
||||
if last_sync_time:
|
||||
# 获取种子时间
|
||||
if dl_tpe == "Qbittorrent":
|
||||
if dl_tpe == "qbittorrent":
|
||||
torrent_date = time.localtime(torrent.get("added_on")) # 将时间戳转换为时间元组
|
||||
torrent_date = time.strftime("%Y-%m-%d %H:%M:%S", torrent_date) # 格式化时间
|
||||
else:
|
||||
@@ -280,7 +281,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
判断文件是否被下载
|
||||
"""
|
||||
try:
|
||||
if dl_type == "Qbittorrent":
|
||||
if dl_type == "qbittorrent":
|
||||
return True
|
||||
else:
|
||||
return file.completed and file.completed > 0
|
||||
@@ -294,7 +295,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
获取文件路径
|
||||
"""
|
||||
try:
|
||||
return file.get("name") if dl_type == "Qbittorrent" else file.name
|
||||
return file.get("name") if dl_type == "qbittorrent" else file.name
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return ""
|
||||
@@ -305,7 +306,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
获取种子文件
|
||||
"""
|
||||
try:
|
||||
return torrent.files if dl_type == "Qbittorrent" else downloader_obj.get_files(tid=torrent.id)
|
||||
return torrent.files if dl_type == "qbittorrent" else downloader_obj.get_files(tid=torrent.id)
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return ""
|
||||
@@ -316,7 +317,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
获取种子name
|
||||
"""
|
||||
try:
|
||||
return torrent.get("name") if dl_type == "Qbittorrent" else torrent.name
|
||||
return torrent.get("name") if dl_type == "qbittorrent" else torrent.name
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return ""
|
||||
@@ -327,7 +328,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
获取种子download_dir
|
||||
"""
|
||||
try:
|
||||
return torrent.get("save_path") if dl_type == "Qbittorrent" else torrent.download_dir
|
||||
return torrent.get("save_path") if dl_type == "qbittorrent" else torrent.download_dir
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return ""
|
||||
@@ -338,7 +339,7 @@ class SyncDownloadFiles(_PluginBase):
|
||||
获取种子hash
|
||||
"""
|
||||
try:
|
||||
return torrent.get("hash") if dl_type == "Qbittorrent" else torrent.hashString
|
||||
return torrent.get("hash") if dl_type == "qbittorrent" else torrent.hashString
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user