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:
continue
torrent_episodes = self.torrent.get_torrent_episodes(torrent_files)
if 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)},不是完整合集")
logger.info(f"{meta.org_string} 解析文件集数为 {torrent_episodes}")
if not torrent_episodes:
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:
# 下载
download_id = self.download_single(context, save_path=save_path, userid=userid)
@ -481,11 +479,13 @@ class DownloadChain(ChainBase):
continue
# 种子全部集
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))
if not selected_episodes:
logger.info(f"{torrent.site_name} - {torrent.title} 没有需要的集,跳过...")
continue
logger.info(f"{torrent.site_name} - {torrent.title} 选中集数:{selected_episodes}")
# 添加下载
download_id = self.download_single(context=context,
torrent_file=torrent_path,

View File

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

View File

@ -1,19 +1,17 @@
import os
import time
from datetime import datetime
from pathlib import Path
from typing import Any, List, Dict, Tuple, Optional
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.cron import CronTrigger
from app.core.config import settings
from app.db.downloadhistory_oper import DownloadHistoryOper
from app.db.transferhistory_oper import TransferHistoryOper
from app.log import logger
from app.modules.qbittorrent import Qbittorrent
from app.modules.transmission import Transmission
from app.plugins import _PluginBase
from typing import Any, List, Dict, Tuple, Optional
from app.log import logger
class SyncDownloadFiles(_PluginBase):
@ -153,6 +151,8 @@ class SyncDownloadFiles(_PluginBase):
download_dir = self.__get_download_dir(torrent, downloader)
# 获取种子name
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)
logger.info(f"开始同步种子 {hash_str}, 文件数 {len(torrent_files)}")
@ -166,12 +166,26 @@ class SyncDownloadFiles(_PluginBase):
download_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:
transferhis = self.transferhis.get_by_src(str(full_path))
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,
download_hash=hash_str)
@ -181,8 +195,8 @@ class SyncDownloadFiles(_PluginBase):
"download_hash": hash_str,
"downloader": downloader,
"fullpath": str(full_path),
"savepath": str(Path(download_dir).joinpath(torrent_name)),
"filepath": file_name,
"savepath": str(save_path),
"filepath": rel_path,
"torrentname": torrent_name,
}
)
@ -268,12 +282,12 @@ class SyncDownloadFiles(_PluginBase):
return True
@staticmethod
def __get_file_name(file: Any, dl_type: str):
def __get_file_path(file: Any, dl_type: str):
"""
获取文件
获取文件路径
"""
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:
print(str(e))
return ""