From 7a5d21016731fc1bd9e9d81699598d4f169e0ac3 Mon Sep 17 00:00:00 2001 From: thsrite Date: Tue, 19 Sep 2023 09:17:48 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix=20#553=20=E4=BF=AE=E5=A4=8Dunraid?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=B5=84=E6=BA=90=E6=85=A2=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index e31cefc6..d6becbe0 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -1,3 +1,4 @@ +import glob import re import shutil import threading @@ -601,8 +602,10 @@ class TransferChain(ChainBase): if not path.exists(): return if path.is_file(): - # 删除文件 - path.unlink() + # 删除文件、nfo、jpg + files = glob.glob(f"{Path(path.parent).joinpath(str(path.name).split('.')[0])}*") + for file in files: + Path(file).unlink() logger.warn(f"文件 {path} 已删除") # 需要删除父目录 elif str(path.parent) == str(path.root): @@ -615,11 +618,25 @@ class TransferChain(ChainBase): # 删除目录 logger.warn(f"目录 {path} 已删除") # 需要删除父目录 - # 判断父目录是否为空, 为空则删除 - for parent_path in path.parents: - if str(parent_path.parent) != str(path.root): - # 父目录非根目录,才删除父目录 - files = SystemUtils.list_files(parent_path, settings.RMT_MEDIAEXT) - if not files: - shutil.rmtree(parent_path) - logger.warn(f"目录 {parent_path} 已删除") + + # 判断当前媒体父路径下是否有媒体文件,如有则无需遍历父级 + files = SystemUtils.list_files(path.parent, settings.RMT_MEDIAEXT) + if not files: + # 媒体库二级分类根路径 + library_root_names = [ + settings.LIBRARY_MOVIE_NAME or '电影', + settings.LIBRARY_TV_NAME or '电视剧', + settings.LIBRARY_ANIME_NAME or '动漫', + ] + + # 判断父目录是否为空, 为空则删除 + for parent_path in path.parents: + # 遍历父目录到媒体库二级分类根路径 + if str(parent_path.name) in library_root_names: + break + if str(parent_path.parent) != str(path.root): + # 父目录非根目录,才删除父目录 + files = SystemUtils.list_files(parent_path, settings.RMT_MEDIAEXT) + if not files: + shutil.rmtree(parent_path) + logger.warn(f"目录 {parent_path} 已删除") From c147d36cb213d401dc60f7800022d9c18cb45ad5 Mon Sep 17 00:00:00 2001 From: thsrite Date: Tue, 19 Sep 2023 11:15:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix=20=E8=B5=84=E6=BA=90=E4=B8=8B=E8=BD=BDm?= =?UTF-8?q?sg=E5=A2=9E=E5=8A=A0=E4=B8=8B=E8=BD=BD=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/chain/download.py b/app/chain/download.py index 3ae393ea..cda85569 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -225,7 +225,7 @@ class DownloadChain(ChainBase): self.downloadhis.add_files(files_to_add) # 发送消息 - self.post_download_message(meta=_meta, mediainfo=_media, torrent=_torrent, channel=channel) + self.post_download_message(meta=_meta, mediainfo=_media, torrent=_torrent, channel=channel, userid=userid) # 下载成功后处理 self.download_added(context=context, download_dir=download_dir, torrent_path=torrent_file) # 广播事件 From dac718edc8e491f9043feffbbf8695ac74bb6022 Mon Sep 17 00:00:00 2001 From: thsrite Date: Tue, 19 Sep 2023 16:15:05 +0800 Subject: [PATCH 3/4] fix 7a5d2101 --- app/chain/transfer.py | 5 ++--- app/utils/system.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index d6becbe0..f7d8f470 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -603,7 +603,7 @@ class TransferChain(ChainBase): return if path.is_file(): # 删除文件、nfo、jpg - files = glob.glob(f"{Path(path.parent).joinpath(str(path.name).split('.')[0])}*") + files = glob.glob(f"{Path(path.parent).joinpath(path.stem)}*") for file in files: Path(file).unlink() logger.warn(f"文件 {path} 已删除") @@ -620,8 +620,7 @@ class TransferChain(ChainBase): # 需要删除父目录 # 判断当前媒体父路径下是否有媒体文件,如有则无需遍历父级 - files = SystemUtils.list_files(path.parent, settings.RMT_MEDIAEXT) - if not files: + if not SystemUtils.exits_files(path.parent, settings.RMT_MEDIAEXT): # 媒体库二级分类根路径 library_root_names = [ settings.LIBRARY_MOVIE_NAME or '电影', diff --git a/app/utils/system.py b/app/utils/system.py index 36b553bd..2776ccf3 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -106,7 +106,7 @@ class SystemUtils: if directory.is_file(): return [directory] - + if not min_filesize: min_filesize = 0 @@ -122,6 +122,36 @@ class SystemUtils: return files + @staticmethod + def exits_files(directory: Path, extensions: list, min_filesize: int = 0) -> bool: + """ + 判断目录下是否存在指定扩展名的文件 + :return True存在 False不存在 + """ + + if not min_filesize: + min_filesize = 0 + + if not directory.exists(): + return False + + if directory.is_file(): + return True + + if not min_filesize: + min_filesize = 0 + + pattern = r".*(" + "|".join(extensions) + ")$" + + # 遍历目录及子目录 + for path in directory.rglob('**/*'): + if path.is_file() \ + and re.match(pattern, path.name, re.IGNORECASE) \ + and path.stat().st_size >= min_filesize * 1024 * 1024: + return True + + return False + @staticmethod def list_sub_files(directory: Path, extensions: list) -> List[Path]: """ From d097ef45ebba751e6b219aa93d54c6bb7cb65c2a Mon Sep 17 00:00:00 2001 From: thsrite Date: Tue, 19 Sep 2023 16:44:20 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix=20=E5=BD=93=E5=89=8D=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E4=B8=8B=E6=B2=A1=E6=9C=89=E5=AA=92=E4=BD=93=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=99=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index f7d8f470..12236fee 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -635,7 +635,7 @@ class TransferChain(ChainBase): break if str(parent_path.parent) != str(path.root): # 父目录非根目录,才删除父目录 - files = SystemUtils.list_files(parent_path, settings.RMT_MEDIAEXT) - if not files: + if not SystemUtils.exits_files(path.parent, settings.RMT_MEDIAEXT): + # 当前路径下没有媒体文件则删除 shutil.rmtree(parent_path) logger.warn(f"目录 {parent_path} 已删除")