fix #743 支持Rclone

This commit is contained in:
jxxghp
2023-10-11 12:16:41 +08:00
parent 5778e86260
commit 0e35cec6e2
7 changed files with 61 additions and 5 deletions

View File

@ -80,6 +80,12 @@ class FileTransferModule(_ModuleBase):
elif transfer_type == 'move':
# 移动
retcode, retmsg = SystemUtils.move(file_item, target_file)
elif transfer_type == 'rclone_move':
# Rclone 移动
retcode, retmsg = SystemUtils.rclone_move(file_item, target_file)
elif transfer_type == 'rclone_copy':
# Rclone 复制
retcode, retmsg = SystemUtils.rclone_copy(file_item, target_file)
else:
# 复制
retcode, retmsg = SystemUtils.copy(file_item, target_file)

View File

@ -619,9 +619,9 @@ class DirMonitor(_PluginBase):
'rows': 5,
'placeholder': '每一行一个目录,支持三种配置方式:\n'
'监控目录\n'
'监控目录#转移方式move|copy|link|softlink\n'
'监控目录#转移方式move|copy|link|softlink|rclone_copy|rclone_move\n'
'监控目录:转移目的目录(需同时在媒体库目录中配置该目的目录)\n'
'监控目录:转移目的目录#转移方式move|copy|link|softlink'
'监控目录:转移目的目录#转移方式move|copy|link|softlink|rclone_copy|rclone_move'
}
}
]

View File

@ -56,7 +56,7 @@ class TransferHistory(BaseModel):
src: Optional[str] = None
# 目的目录
dest: Optional[str] = None
# 转移模式link/copy/move/softlink
# 转移模式
mode: Optional[str] = None
# 类型:电影、电视剧
type: Optional[str] = None

View File

@ -3,6 +3,7 @@ import os
import platform
import re
import shutil
import subprocess
import sys
from pathlib import Path
from typing import List, Union, Tuple
@ -118,6 +119,54 @@ class SystemUtils:
print(str(err))
return -1, str(err)
@staticmethod
def rclone_move(src: Path, dest: Path):
"""
Rclone移动
"""
try:
retcode = subprocess.run(
[
'rclone', 'moveto',
str(src),
f'MP:{dest}'
],
startupinfo=SystemUtils.__get_hidden_shell()
).returncode
return retcode, ""
except Exception as err:
print(str(err))
return -1, str(err)
@staticmethod
def rclone_copy(src: Path, dest: Path):
"""
Rclone复制
"""
try:
retcode = subprocess.run(
[
'rclone', 'copyto',
str(src),
f'MP:{dest}'
],
startupinfo=SystemUtils.__get_hidden_shell()
).returncode
return retcode, ""
except Exception as err:
print(str(err))
return -1, str(err)
@staticmethod
def __get_hidden_shell():
if SystemUtils.is_windows():
st = subprocess.STARTUPINFO()
st.dwFlags = subprocess.STARTF_USESHOWWINDOW
st.wShowWindow = subprocess.SW_HIDE
return st
else:
return None
@staticmethod
def list_files(directory: Path, extensions: list, min_filesize: int = 0) -> List[Path]:
"""