diff --git a/README.md b/README.md index 2f3fcf51..16879235 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,8 @@ MoviePilot需要配套下载器和媒体服务器配合使用。 - **BIG_MEMORY_MODE:** 大内存模式,默认为`false`,开启后会占用更多的内存,但响应速度会更快 +- **OVERWRITE_MODE:** 转移覆盖模式,默认为`nerver`,支持`nerver`/`size`/`always`,分别表示`不覆盖`/`根据文件大小覆盖(大覆盖小)`/`总是覆盖` + - **MOVIE_RENAME_FORMAT:** 电影重命名格式 `MOVIE_RENAME_FORMAT`支持的配置项: diff --git a/app/core/config.py b/app/core/config.py index 4f657ffc..f5f2cbf5 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -204,6 +204,8 @@ class Settings(BaseSettings): "/Season {{season}}" \ "/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}" \ "{{fileExt}}" + # 转移时覆盖模式 + OVERWRITE_MODE: str = "nerver" # 大内存模式 BIG_MEMORY_MODE: bool = False diff --git a/app/modules/filetransfer/__init__.py b/app/modules/filetransfer/__init__.py index c94bac0b..21c05fe3 100644 --- a/app/modules/filetransfer/__init__.py +++ b/app/modules/filetransfer/__init__.py @@ -468,9 +468,25 @@ class FileTransferModule(_ModuleBase): # 判断是否要覆盖 overflag = False if new_file.exists(): - if new_file.stat().st_size < in_path.stat().st_size: - logger.info(f"目标文件已存在,但文件大小更小,将覆盖:{new_file}") - overflag = True + # 目标文件已存在 + logger.info(f"目标文件已存在,转移覆盖模式:{settings.OVERWRITE_MODE}") + match settings.OVERWRITE_MODE: + case 'always': + overflag = True + case 'size': + if new_file.stat().st_size < in_path.stat().st_size: + logger.info(f"目标文件文件大小更小,将被覆盖:{new_file}") + overflag = True + case 'never': + pass + case _: + pass + if not overflag: + return TransferInfo(success=False, + message=f"目标文件已存在,转移覆盖模式:{settings.OVERWRITE_MODE}", + path=in_path, + target_path=new_file, + fail_list=[str(in_path)]) # 原文件大小 file_size = in_path.stat().st_size # 转移文件