fix 自定义文件保留时长,大于该值会被转移

This commit is contained in:
thsrite
2024-07-17 09:37:15 +08:00
parent 440c7d596f
commit 7b5c1a597c
3 changed files with 36 additions and 9 deletions

View File

@@ -11,6 +11,7 @@
"return_mode": "softlink",
"monitor_dirs": [
{
"retention_time": 0,
"monitor_mode": "fast",
/* 监控模式 compatibility/ */
"dest_path": "/series/link",
@@ -132,6 +133,7 @@ cd2方式上传--strm回本地暂时移除
- return_mode: 云盘文件回本地模式softlink/strm
- return_pathMoviePilot中软链接/strm生成路径
- retention_time: 本地文件保留时长(小时) 当前日期与文件创建日期的时间差(小时),大于此值的文件将被转移
- monitor_mode监控模式 compatibility/fast
- tranfer_type转移类型可选值copy/move
- dest_path: MoviePilot本地刮削好的文件路径MoviePilot媒体库目录

View File

@@ -542,12 +542,13 @@
"name": "云盘助手",
"description": "本地文件定时转移到云盘,软连接/strm回本地定时清理无效软连接。",
"labels": "云盘",
"version": "2.1.3",
"version": "2.1.4",
"icon": "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudassistant.png",
"author": "thsrite",
"level": 99,
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlgN7RtXlPNXoFE9B67ye\ny2mog/hDDrhBAIJogdvfAgBMZ1qVzIPcBfdjENPJ9kV/F+zOoh0CzEaDufM54ERT\nykK1pQw7yj7quRZDbv5byxVNqI8bJg8zQo8Q66SQ8SP+aftmpFrADKClQ8VcVYzZ\nJ+YDu9H9q+TcvBqVtLyKfAH5T9WAxn0bXEh4OgkJn7oO5eI5+Fsi6Aq9suVN/HyK\nz2bDr237GmXJT4YPn9s7kj4Rypzg2ldiuBwtVnaTw+xjZRlCRr4Gs0eFUIMUqnoQ\nip4Px8Mrq5cqHl0HrJ/av/pJLCN1icCgegYW63b2gjjJwmps9NGGOydRzgoFkqj0\nDwIDAQAB",
"history": {
"v2.1.4": "自定义文件保留时长,大于该值会被转移",
"v2.1.3": "修复消息通知",
"v2.1.2": "修复清理无效软连接",
"v2.1.1": "修复清理无效软连接",

View File

@@ -64,7 +64,7 @@ class CloudAssistant(_PluginBase):
# 插件图标
plugin_icon = "https://raw.githubusercontent.com/thsrite/MoviePilot-Plugins/main/icons/cloudassistant.png"
# 插件版本
plugin_version = "2.1.3"
plugin_version = "2.1.4"
# 插件作者
plugin_author = "thsrite"
# 作者主页
@@ -110,6 +110,7 @@ class CloudAssistant(_PluginBase):
"return_mode": "softlink",
"monitor_dirs": [
{
"retention_time": 0,
"monitor_mode": "模式 compatibility/fast",
"dest_path": "/mnt/media/movies",
"mount_path": "/mnt/cloud/115/media/movies",
@@ -401,13 +402,6 @@ class CloudAssistant(_PluginBase):
logger.info(f"{event_path} 命中整理屏蔽词 {keyword},不处理")
return
# 判断是不是蓝光目录
if re.search(r"BDMV[/\\]STREAM", event_path, re.IGNORECASE):
# 截取BDMV前面的路径
blurray_dir = event_path[:event_path.find("BDMV")]
file_path = Path(blurray_dir)
logger.info(f"{event_path} 是蓝光目录,更正文件路径为:{str(file_path)}")
# 查询转移配置
monitor_dir = self._dirconf.get(mon_path)
mount_path = monitor_dir.get("mount_path")
@@ -422,6 +416,24 @@ class CloudAssistant(_PluginBase):
dest_preserve_hierarchy = monitor_dir.get("dest_preserve_hierarchy") or 0
src_paths = monitor_dir.get("src_paths") or ""
src_preserve_hierarchy = monitor_dir.get("src_preserve_hierarchy") or 0
# 本地文件保留时间 (小时)
retention_time = monitor_dir.get("retention_time") or 0
if retention_time > 0:
creation_time = self.__get_file_creation_time(file_path)
creation_datetime = datetime.datetime.fromtimestamp(creation_time)
current_datetime = datetime.datetime.now()
time_difference = (current_datetime - creation_datetime).total_seconds()
if time_difference < (int(retention_time) * 3600):
logger.warning(
f"{file_path} 创建 {time_difference / 3600} 小时,小于保留时间 {retention_time} 小时,暂不处理")
return
# 判断是不是蓝光目录
if re.search(r"BDMV[/\\]STREAM", event_path, re.IGNORECASE):
# 截取BDMV前面的路径
blurray_dir = event_path[:event_path.find("BDMV")]
file_path = Path(blurray_dir)
logger.info(f"{event_path} 是蓝光目录,更正文件路径为:{str(file_path)}")
# 1、转移到云盘挂载路径 上传到cd2
# 挂载的路径
@@ -628,6 +640,18 @@ class CloudAssistant(_PluginBase):
logger.warn(f"删除源文件空目录:{file_dir}")
shutil.rmtree(file_dir, ignore_errors=True)
@staticmethod
def __get_file_creation_time(file_path):
"""获取文件的创建时间"""
if os.name == 'nt': # Windows系统
return os.path.getctime(file_path)
else: # Unix系统
stat = os.stat(file_path)
try:
return stat.st_birthtime
except AttributeError:
return stat.st_mtime
def __msg_handler(self, transferhis):
"""
组织消息发送数据