From 94ed3778432a31066e84c69cb407367a1d28e77b Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:02:45 +0800 Subject: [PATCH 1/4] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E6=95=B4=E7=90=86?= =?UTF-8?q?=E5=8E=9F=E7=9B=98=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20-=20=E6=B7=BB=E5=8A=A0=E7=B1=BB=E5=9E=8B=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 8a7983768..c50776fdf 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -194,7 +194,9 @@ def __do_transfer(self, fileitem: FileItem, transfers: Dict[Tuple, TransferInfo] = {} # 待整理文件列表 - file_items = [] + file_items: List[FileItem] = [] + # 蓝光目录列表 + bluray: List[FileItem] = [] # 汇总错误信息 err_msgs: List[str] = [] # 已处理数量 @@ -225,9 +227,13 @@ def __do_transfer(self, fileitem: FileItem, if (trans_item.type == "dir" and not (trans_item.storage == "local" and SystemUtils.is_bluray_dir(item_path))): # 遍历获取下载目录所有文件(递归) - file_items = self.storagechain.list_files(trans_item, recursion=True) - if file_items: - file_items.extend(trans_items) + files = self.storagechain.list_files(trans_item, recursion=True) + if files: + file_items.extend(files) + elif (trans_item.storage == "local" and SystemUtils.is_bluray_dir(item_path)): + # 计算目录下文件总大小 + trans_item.size = sum(file.stat().st_size for file in item_path.rglob('*') if file.is_file()) + bluray.append(trans_item) else: # 文件或蓝光目录 file_items.append(trans_item) @@ -240,7 +246,8 @@ def __do_transfer(self, fileitem: FileItem, file_items = [f for f in file_items if f.extension and (f".{f.extension.lower()}" in self.all_exts and (not min_filesize or f.size > min_filesize * 1024 * 1024))] - + # BDMV 跳过过滤 + file_items.extend(bluray) if not file_items: logger.warn(f"{fileitem.path} 没有找到可整理的媒体文件") return False, f"{fileitem.name} 没有找到可整理的媒体文件" From ab78b102871a7edb9d7a319ddb0e3bae9c5f1b5e Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:28:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=B0=86=E5=88=A4=E6=96=AD=E7=A7=BB?= =?UTF-8?q?=E5=87=BA,=20=E5=87=8F=E5=B0=91`is=5Fbluray=5Fdir`=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index c50776fdf..aa8a7f9c6 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -223,14 +223,16 @@ def __do_transfer(self, fileitem: FileItem, # 处理所有待整理目录或文件,默认一个整理路径或文件只有一个媒体信息 for trans_item in trans_items: item_path = Path(trans_item.path) + # 是否是蓝光路径 + bluray_dir = trans_item.storage == "local" and SystemUtils.is_bluray_dir(item_path) # 如果是目录且不是⼀蓝光原盘,获取所有文件并整理 - if (trans_item.type == "dir" - and not (trans_item.storage == "local" and SystemUtils.is_bluray_dir(item_path))): + if trans_item.type == "dir" and not bluray_dir: # 遍历获取下载目录所有文件(递归) - files = self.storagechain.list_files(trans_item, recursion=True) - if files: - file_items.extend(files) - elif (trans_item.storage == "local" and SystemUtils.is_bluray_dir(item_path)): + if (files := self.storagechain.list_files(trans_item, recursion=True)): file_items.extend(files) + # files = self.storagechain.list_files(trans_item, recursion=True) + # if files: + # file_items.extend(files) + elif bluray_dir: # 计算目录下文件总大小 trans_item.size = sum(file.stat().st_size for file in item_path.rglob('*') if file.is_file()) bluray.append(trans_item) From 8add8ed631d75bbd7c7d9c11d49ae4f8c4365d3a Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Sun, 27 Oct 2024 23:32:15 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index aa8a7f9c6..29fade83c 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -229,9 +229,7 @@ def __do_transfer(self, fileitem: FileItem, if trans_item.type == "dir" and not bluray_dir: # 遍历获取下载目录所有文件(递归) if (files := self.storagechain.list_files(trans_item, recursion=True)): file_items.extend(files) - # files = self.storagechain.list_files(trans_item, recursion=True) - # if files: - # file_items.extend(files) + # 如果是蓝光目录,计算⼤⼩ elif bluray_dir: # 计算目录下文件总大小 trans_item.size = sum(file.stat().st_size for file in item_path.rglob('*') if file.is_file()) From 4d6ed7d5521857fc1f15a5c79528f1997ab26e11 Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Mon, 28 Oct 2024 08:31:32 +0800 Subject: [PATCH 4/4] =?UTF-8?q?-=20=E5=B0=86=E8=AE=A1=E7=AE=97=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=B8=AD=E6=89=80=E6=9C=89=E6=96=87=E4=BB=B6=E6=80=BB?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E7=A7=BB=E5=8A=A8=E5=88=B0=20`modules.filema?= =?UTF-8?q?nager`=20=E6=A8=A1=E5=9D=97=E4=B8=AD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 6 ++---- app/modules/filemanager/__init__.py | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 29fade83c..2a0c3cbb0 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -223,7 +223,7 @@ def __do_transfer(self, fileitem: FileItem, # 处理所有待整理目录或文件,默认一个整理路径或文件只有一个媒体信息 for trans_item in trans_items: item_path = Path(trans_item.path) - # 是否是蓝光路径 + # 是否蓝光路径 bluray_dir = trans_item.storage == "local" and SystemUtils.is_bluray_dir(item_path) # 如果是目录且不是⼀蓝光原盘,获取所有文件并整理 if trans_item.type == "dir" and not bluray_dir: @@ -231,11 +231,9 @@ def __do_transfer(self, fileitem: FileItem, if (files := self.storagechain.list_files(trans_item, recursion=True)): file_items.extend(files) # 如果是蓝光目录,计算⼤⼩ elif bluray_dir: - # 计算目录下文件总大小 - trans_item.size = sum(file.stat().st_size for file in item_path.rglob('*') if file.is_file()) bluray.append(trans_item) + # 单个文件 else: - # 文件或蓝光目录 file_items.append(trans_item) if formaterHandler: diff --git a/app/modules/filemanager/__init__.py b/app/modules/filemanager/__init__.py index 4b80f2699..dd5157754 100644 --- a/app/modules/filemanager/__init__.py +++ b/app/modules/filemanager/__init__.py @@ -884,12 +884,14 @@ def transfer_media(self, need_notify=need_notify) logger.info(f"文件夹 {fileitem.path} 整理成功") + # 计算目录下所有文件大小 + total_size = sum(file.stat().st_size for file in Path(fileitem.path).rglob('*') if file.is_file()) # 返回整理后的路径 return TransferInfo(success=True, fileitem=fileitem, target_item=new_diritem, target_diritem=new_diritem, - total_size=fileitem.size, + total_size=total_size, need_scrape=need_scrape, transfer_type=transfer_type) else: