This commit is contained in:
jxxghp
2023-09-05 08:39:23 +08:00
parent bedc885232
commit bb729bf976
3 changed files with 61 additions and 37 deletions

View File

@ -339,27 +339,25 @@ class DownloadChain(ChainBase):
if not torrent_path: if not torrent_path:
continue continue
torrent_episodes = self.torrent.get_torrent_episodes(torrent_files) torrent_episodes = self.torrent.get_torrent_episodes(torrent_files)
if torrent_episodes: logger.info(f"{meta.org_string} 解析文件集数为 {torrent_episodes}")
# 总集数 if not torrent_episodes:
need_total = __get_season_episodes(need_tmdbid, torrent_season[0])
if len(torrent_episodes) < need_total:
# 更新集数范围
begin_ep = min(torrent_episodes)
end_ep = max(torrent_episodes)
meta.set_episodes(begin=begin_ep, end=end_ep)
logger.info(
f"{meta.org_string} 解析文件集数为 [{begin_ep}-{end_ep}],不是完整合集")
continue
else:
# 下载
download_id = self.download_single(context=context,
torrent_file=torrent_path,
save_path=save_path,
userid=userid)
else:
logger.info(
f"{meta.org_string} 解析文件集数为 {len(torrent_episodes)},不是完整合集")
continue continue
# 总集数
need_total = __get_season_episodes(need_tmdbid, torrent_season[0])
if len(torrent_episodes) < need_total:
# 更新集数范围
begin_ep = min(torrent_episodes)
end_ep = max(torrent_episodes)
meta.set_episodes(begin=begin_ep, end=end_ep)
logger.info(
f"{meta.org_string} 解析文件集数发现不是完整合集")
continue
else:
# 下载
download_id = self.download_single(context=context,
torrent_file=torrent_path,
save_path=save_path,
userid=userid)
else: else:
# 下载 # 下载
download_id = self.download_single(context, save_path=save_path, userid=userid) download_id = self.download_single(context, save_path=save_path, userid=userid)
@ -481,11 +479,13 @@ class DownloadChain(ChainBase):
continue continue
# 种子全部集 # 种子全部集
torrent_episodes = self.torrent.get_torrent_episodes(torrent_files) torrent_episodes = self.torrent.get_torrent_episodes(torrent_files)
logger.info(f"{torrent.site_name} - {meta.org_string} 解析文件集数:{torrent_episodes}")
# 选中的集 # 选中的集
selected_episodes = set(torrent_episodes).intersection(set(need_episodes)) selected_episodes = set(torrent_episodes).intersection(set(need_episodes))
if not selected_episodes: if not selected_episodes:
logger.info(f"{torrent.site_name} - {torrent.title} 没有需要的集,跳过...") logger.info(f"{torrent.site_name} - {torrent.title} 没有需要的集,跳过...")
continue continue
logger.info(f"{torrent.site_name} - {torrent.title} 选中集数:{selected_episodes}")
# 添加下载 # 添加下载
download_id = self.download_single(context=context, download_id = self.download_single(context=context,
torrent_file=torrent_path, torrent_file=torrent_path,

View File

@ -147,9 +147,17 @@ class TorrentHelper:
else: else:
# 目录名 # 目录名
folder_name = torrentinfo.name folder_name = torrentinfo.name
# 文件清单 # 文件清单,如果一级目录与种子名相同则去掉
file_list = [fileinfo.name for fileinfo in torrentinfo.files] file_list = []
logger.debug(f"{torrent_path.stem} -> 目录:{folder_name},文件清单:{file_list}") for fileinfo in torrentinfo.files:
file_path = Path(fileinfo.name)
# 根路径
root_path = file_path.parts[0]
if root_path == folder_name:
file_list.append(str(file_path.relative_to(root_path)))
else:
file_list.append(fileinfo.name)
logger.info(f"解析种子:{torrent_path.name} => 目录:{folder_name},文件清单:{file_list}")
return folder_name, file_list return folder_name, file_list
except Exception as err: except Exception as err:
logger.error(f"种子文件解析失败:{err}") logger.error(f"种子文件解析失败:{err}")
@ -259,9 +267,11 @@ class TorrentHelper:
for file in files: for file in files:
if not file: if not file:
continue continue
if Path(file).suffix not in settings.RMT_MEDIAEXT: file_path = Path(file)
if file_path.suffix not in settings.RMT_MEDIAEXT:
continue continue
meta = MetaInfo(file) # 只使用文件名识别
meta = MetaInfo(file_path.stem)
if not meta.begin_episode: if not meta.begin_episode:
continue continue
episodes = list(set(episodes).union(set(meta.episode_list))) episodes = list(set(episodes).union(set(meta.episode_list)))

View File

@ -1,19 +1,17 @@
import os
import time import time
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import Any, List, Dict, Tuple, Optional
from apscheduler.schedulers.background import BackgroundScheduler from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
from app.core.config import settings from app.core.config import settings
from app.db.downloadhistory_oper import DownloadHistoryOper from app.db.downloadhistory_oper import DownloadHistoryOper
from app.db.transferhistory_oper import TransferHistoryOper from app.db.transferhistory_oper import TransferHistoryOper
from app.log import logger
from app.modules.qbittorrent import Qbittorrent from app.modules.qbittorrent import Qbittorrent
from app.modules.transmission import Transmission from app.modules.transmission import Transmission
from app.plugins import _PluginBase from app.plugins import _PluginBase
from typing import Any, List, Dict, Tuple, Optional
from app.log import logger
class SyncDownloadFiles(_PluginBase): class SyncDownloadFiles(_PluginBase):
@ -153,6 +151,8 @@ class SyncDownloadFiles(_PluginBase):
download_dir = self.__get_download_dir(torrent, downloader) download_dir = self.__get_download_dir(torrent, downloader)
# 获取种子name # 获取种子name
torrent_name = self.__get_torrent_name(torrent, downloader) torrent_name = self.__get_torrent_name(torrent, downloader)
# 种子保存目录
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, downloader_obj)
logger.info(f"开始同步种子 {hash_str}, 文件数 {len(torrent_files)}") logger.info(f"开始同步种子 {hash_str}, 文件数 {len(torrent_files)}")
@ -166,12 +166,26 @@ class SyncDownloadFiles(_PluginBase):
download_files = [] download_files = []
for file in torrent_files: for file in torrent_files:
file_name = self.__get_file_name(file, downloader) # 种子文件路径
full_path = Path(download_dir).joinpath(torrent_name, file_name) file_path_str = self.__get_file_path(file, downloader)
file_path = Path(file_path_str)
# 只处理视频格式
if not file_path.suffix \
or file_path.suffix not in settings.RMT_MEDIAEXT:
continue
# 种子文件根路程
root_path = file_path.parts[0]
# 不含种子名称的种子文件相对路径
if root_path == torrent_name:
rel_path = str(file_path.relative_to(root_path))
else:
rel_path = str(file_path)
# 完整路径
full_path = save_path.joinpath(rel_path)
if self._history: if self._history:
transferhis = self.transferhis.get_by_src(str(full_path)) transferhis = self.transferhis.get_by_src(str(full_path))
if transferhis and not transferhis.download_hash: if transferhis and not transferhis.download_hash:
logger.info(f"开始补充转移记录 {transferhis.id} download_hash {hash_str}") logger.info(f"开始补充转移记录{transferhis.id} download_hash {hash_str}")
self.transferhis.update_download_hash(historyid=transferhis.id, self.transferhis.update_download_hash(historyid=transferhis.id,
download_hash=hash_str) download_hash=hash_str)
@ -181,8 +195,8 @@ class SyncDownloadFiles(_PluginBase):
"download_hash": hash_str, "download_hash": hash_str,
"downloader": downloader, "downloader": downloader,
"fullpath": str(full_path), "fullpath": str(full_path),
"savepath": str(Path(download_dir).joinpath(torrent_name)), "savepath": str(save_path),
"filepath": file_name, "filepath": rel_path,
"torrentname": torrent_name, "torrentname": torrent_name,
} }
) )
@ -268,12 +282,12 @@ class SyncDownloadFiles(_PluginBase):
return True return True
@staticmethod @staticmethod
def __get_file_name(file: Any, dl_type: str): def __get_file_path(file: Any, dl_type: str):
""" """
获取文件 获取文件路径
""" """
try: try:
return os.path.basename(file.get("name")) if dl_type == "qbittorrent" else os.path.basename(file.name) return file.get("name") if dl_type == "qbittorrent" else file.name
except Exception as e: except Exception as e:
print(str(e)) print(str(e))
return "" return ""