mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-17 18:30:43 +08:00
Compare commits
5 Commits
92df9239af
...
60cb9ba152
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60cb9ba152 | ||
|
|
a56565e187 | ||
|
|
925144ea79 | ||
|
|
0a47d48c60 | ||
|
|
749d1b7039 |
@ -288,8 +288,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bottom-buttons">
|
<div class="bottom-buttons">
|
||||||
<button class="btn btn-success"><i class="bi bi-save"></i> 保存</button>
|
<button class="btn btn-success" title="CTRL+S"><i class="bi bi-save"></i> 保存</button>
|
||||||
<button type="button" class="btn btn-primary" @click="runScriptNow()"><i class="bi bi-play-fill"></i> 运行</button>
|
<button type="button" class="btn btn-primary" title="CTRL+R" @click="runScriptNow()"><i class="bi bi-play-fill"></i> 运行</button>
|
||||||
<button type="button" class="btn btn-info" @click="scrollToX(0)" @dblclick="scrollToX()" data-toggle="tooltip" data-placement="top" title="单击回顶,双击到底"><i class="bi bi-chevron-bar-up"></i> 回顶</button>
|
<button type="button" class="btn btn-info" @click="scrollToX(0)" @dblclick="scrollToX()" data-toggle="tooltip" data-placement="top" title="单击回顶,双击到底"><i class="bi bi-chevron-bar-up"></i> 回顶</button>
|
||||||
<a class="btn btn-danger" href="/logout"><i class="bi bi-box-arrow-right"></i> 退出</a>
|
<a class="btn btn-danger" href="/logout"><i class="bi bi-box-arrow-right"></i> 退出</a>
|
||||||
</div>
|
</div>
|
||||||
@ -432,7 +432,8 @@
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.fetchData();
|
this.fetchData();
|
||||||
this.checkNewVersion();
|
this.checkNewVersion();
|
||||||
$('[data-toggle="tooltip"]').tooltip()
|
$('[data-toggle="tooltip"]').tooltip();
|
||||||
|
document.addEventListener('keydown', this.handleKeyDown);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
checkNewVersion() {
|
checkNewVersion() {
|
||||||
@ -475,6 +476,17 @@
|
|||||||
console.error('Error fetching data:', error);
|
console.error('Error fetching data:', error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
handleKeyDown(event) {
|
||||||
|
if (event.ctrlKey || event.metaKey) {
|
||||||
|
if (event.keyCode === 83 || event.key === 's') {
|
||||||
|
event.preventDefault();
|
||||||
|
this.saveConfig();
|
||||||
|
} else if (event.keyCode === 82 || event.key === 'r') {
|
||||||
|
event.preventDefault();
|
||||||
|
this.runScriptNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
saveConfig() {
|
saveConfig() {
|
||||||
axios.post('/update', this.formData)
|
axios.post('/update', this.formData)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
|||||||
@ -62,25 +62,39 @@ class Alist:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def storage_id_to_path(self, storage_id):
|
def storage_id_to_path(self, storage_id):
|
||||||
|
storage_mount_path, quark_root_dir = None, None
|
||||||
# 1. 检查是否符合 /aaa:/bbb 格式
|
# 1. 检查是否符合 /aaa:/bbb 格式
|
||||||
match = re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id)
|
if match := re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id):
|
||||||
if match:
|
# 存储挂载路径, 夸克根文件夹
|
||||||
return True, (match.group(1), match.group(2))
|
storage_mount_path, quark_root_dir = match.group(1), match.group(2)
|
||||||
# 2. 调用 Alist API 获取存储信息
|
file_list = self.get_file_list(storage_mount_path)
|
||||||
storage_info = self.get_storage_info(storage_id)
|
if file_list.get("code") != 200:
|
||||||
if storage_info:
|
print(f"Alist刷新: 获取挂载路径失败❌ {file_list.get('message')}")
|
||||||
if storage_info["driver"] == "Quark":
|
return False, (None, None)
|
||||||
addition = json.loads(storage_info["addition"])
|
# 2. 检查是否数字,调用 Alist API 获取存储信息
|
||||||
# 存储挂载路径
|
elif re.match(r"^\d+$", storage_id):
|
||||||
storage_mount_path = storage_info["mount_path"]
|
if storage_info := self.get_storage_info(storage_id):
|
||||||
# 夸克根文件夹
|
if storage_info["driver"] == "Quark":
|
||||||
quark_root_dir = self.get_root_folder_full_path(
|
addition = json.loads(storage_info["addition"])
|
||||||
addition["cookie"], addition["root_folder_id"]
|
# 存储挂载路径
|
||||||
)
|
storage_mount_path = storage_info["mount_path"]
|
||||||
if storage_mount_path and quark_root_dir:
|
# 夸克根文件夹
|
||||||
return True, (storage_mount_path, quark_root_dir)
|
quark_root_dir = self.get_root_folder_full_path(
|
||||||
else:
|
addition["cookie"], addition["root_folder_id"]
|
||||||
print(f"Alist刷新: 不支持[{storage_info['driver']}]驱动 ❌")
|
)
|
||||||
|
elif storage_info["driver"] == "QuarkTV":
|
||||||
|
print(
|
||||||
|
f"Alist刷新: [QuarkTV]驱动⚠️ storage_id请手动填入 /Alist挂载路径:/Quark目录路径"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(f"Alist刷新: 不支持[{storage_info['driver']}]驱动 ❌")
|
||||||
|
else:
|
||||||
|
print(f"Alist刷新: storage_id[{storage_id}]格式错误❌")
|
||||||
|
# 返回结果
|
||||||
|
if storage_mount_path and quark_root_dir:
|
||||||
|
return True, (storage_mount_path, quark_root_dir)
|
||||||
|
else:
|
||||||
|
return False, (None, None)
|
||||||
|
|
||||||
def get_storage_info(self, storage_id):
|
def get_storage_info(self, storage_id):
|
||||||
url = f"{self.url}/api/admin/storage/get"
|
url = f"{self.url}/api/admin/storage/get"
|
||||||
@ -96,9 +110,27 @@ class Alist:
|
|||||||
print(f"Alist刷新: 存储{storage_id}连接失败❌ {data.get('message')}")
|
print(f"Alist刷新: 存储{storage_id}连接失败❌ {data.get('message')}")
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Alist刷新: 获取Alist存储出错 {e}")
|
print(f"Alist刷新: 获取Alist存储出错 {e}")
|
||||||
return False
|
return []
|
||||||
|
|
||||||
def refresh(self, path, force_refresh=True):
|
def refresh(self, path):
|
||||||
|
data = self.get_file_list(path, True)
|
||||||
|
if data.get("code") == 200:
|
||||||
|
print(f"📁 Alist刷新:目录[{path}] 成功✅")
|
||||||
|
return data.get("data")
|
||||||
|
elif "object not found" in data.get("message", ""):
|
||||||
|
# 如果是根目录就不再往上查找
|
||||||
|
if path == "/" or path == self.storage_mount_path:
|
||||||
|
print(f"📁 Alist刷新:根目录不存在,请检查 Alist 配置")
|
||||||
|
return False
|
||||||
|
# 获取父目录
|
||||||
|
parent_path = os.path.dirname(path)
|
||||||
|
print(f"📁 Alist刷新:[{path}] 不存在,转父目录 [{parent_path}]")
|
||||||
|
# 递归刷新父目录
|
||||||
|
return self.refresh(parent_path)
|
||||||
|
else:
|
||||||
|
print(f"📁 Alist刷新:失败❌ {data.get('message')}")
|
||||||
|
|
||||||
|
def get_file_list(self, path, force_refresh=False):
|
||||||
url = f"{self.url}/api/fs/list"
|
url = f"{self.url}/api/fs/list"
|
||||||
headers = {"Authorization": self.token}
|
headers = {"Authorization": self.token}
|
||||||
payload = {
|
payload = {
|
||||||
@ -111,25 +143,10 @@ class Alist:
|
|||||||
try:
|
try:
|
||||||
response = requests.request("POST", url, headers=headers, json=payload)
|
response = requests.request("POST", url, headers=headers, json=payload)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
return response.json()
|
||||||
if data.get("code") == 200:
|
except Exception as e:
|
||||||
print(f"📁 Alist刷新:目录[{path}] 成功✅")
|
print(f"📁 Alist刷新: 获取文件列表出错❌ {e}")
|
||||||
return data.get("data")
|
return {}
|
||||||
elif "object not found" in data.get("message", ""):
|
|
||||||
# 如果是根目录就不再往上查找
|
|
||||||
if path == "/" or path == self.storage_mount_path:
|
|
||||||
print(f"📁 Alist刷新:根目录不存在,请检查 Alist 配置")
|
|
||||||
return False
|
|
||||||
# 获取父目录
|
|
||||||
parent_path = os.path.dirname(path)
|
|
||||||
print(f"📁 Alist刷新:[{path}] 不存在,转父目录 [{parent_path}]")
|
|
||||||
# 递归刷新父目录
|
|
||||||
return self.refresh(parent_path)
|
|
||||||
else:
|
|
||||||
print(f"📁 Alist刷新:失败❌ {data.get('message')}")
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
print(f"Alist刷新目录出错: {e}")
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_root_folder_full_path(self, cookie, pdir_fid):
|
def get_root_folder_full_path(self, cookie, pdir_fid):
|
||||||
if pdir_fid == "0":
|
if pdir_fid == "0":
|
||||||
@ -162,4 +179,4 @@ class Alist:
|
|||||||
return "/".join(file_names)
|
return "/".join(file_names)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Alist刷新: 获取Quark路径出错 {e}")
|
print(f"Alist刷新: 获取Quark路径出错 {e}")
|
||||||
return False
|
return ""
|
||||||
|
|||||||
@ -61,8 +61,8 @@ class Alist_strm:
|
|||||||
try:
|
try:
|
||||||
selected_configs = [int(x.strip()) for x in selected_configs_str.split(",")]
|
selected_configs = [int(x.strip()) for x in selected_configs_str.split(",")]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Error: 运行alist-strm配置错误,id应以,分割")
|
print("🔗 alist-strm配置运行: 出错❌ id应以,分割")
|
||||||
return None
|
return False
|
||||||
data = [("selected_configs", config_id) for config_id in selected_configs]
|
data = [("selected_configs", config_id) for config_id in selected_configs]
|
||||||
data.append(("action", "run_selected"))
|
data.append(("action", "run_selected"))
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -72,28 +72,43 @@ class Alist_strm_gen:
|
|||||||
task["savepath"].replace(self.quark_root_dir, "", 1).lstrip("/"),
|
task["savepath"].replace(self.quark_root_dir, "", 1).lstrip("/"),
|
||||||
)
|
)
|
||||||
).replace("\\", "/")
|
).replace("\\", "/")
|
||||||
self.refresh(alist_path)
|
self.check_dir(alist_path)
|
||||||
|
|
||||||
def storage_id_to_path(self, storage_id):
|
def storage_id_to_path(self, storage_id):
|
||||||
|
storage_mount_path, quark_root_dir = None, None
|
||||||
# 1. 检查是否符合 /aaa:/bbb 格式
|
# 1. 检查是否符合 /aaa:/bbb 格式
|
||||||
match = re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id)
|
if match := re.match(r"^(\/[^:]*):(\/[^:]*)$", storage_id):
|
||||||
if match:
|
# 存储挂载路径, 夸克根文件夹
|
||||||
return True, (match.group(1), match.group(2))
|
storage_mount_path, quark_root_dir = match.group(1), match.group(2)
|
||||||
# 2. 调用 Alist API 获取存储信息
|
file_list = self.get_file_list(storage_mount_path)
|
||||||
storage_info = self.get_storage_info(storage_id)
|
if file_list.get("code") != 200:
|
||||||
if storage_info:
|
print(f"Alist-Strm生成: 获取挂载路径失败❌ {file_list.get('message')}")
|
||||||
if storage_info["driver"] == "Quark":
|
return False, (None, None)
|
||||||
addition = json.loads(storage_info["addition"])
|
# 2. 检查是否数字,调用 Alist API 获取存储信息
|
||||||
# 存储挂载路径
|
elif re.match(r"^\d+$", storage_id):
|
||||||
storage_mount_path = storage_info["mount_path"]
|
if storage_info := self.get_storage_info(storage_id):
|
||||||
# 夸克根文件夹
|
if storage_info["driver"] == "Quark":
|
||||||
quark_root_dir = self.get_root_folder_full_path(
|
addition = json.loads(storage_info["addition"])
|
||||||
addition["cookie"], addition["root_folder_id"]
|
# 存储挂载路径
|
||||||
)
|
storage_mount_path = storage_info["mount_path"]
|
||||||
if storage_mount_path and quark_root_dir:
|
# 夸克根文件夹
|
||||||
return True, (storage_mount_path, quark_root_dir)
|
quark_root_dir = self.get_root_folder_full_path(
|
||||||
else:
|
addition["cookie"], addition["root_folder_id"]
|
||||||
print(f"Alist刷新: 不支持[{storage_info['driver']}]驱动 ❌")
|
)
|
||||||
|
elif storage_info["driver"] == "QuarkTV":
|
||||||
|
print(
|
||||||
|
f"Alist-Strm生成: [QuarkTV]驱动⚠️ storage_id请手动填入 /Alist挂载路径:/Quark目录路径"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(f"Alist-Strm生成: 不支持[{storage_info['driver']}]驱动 ❌")
|
||||||
|
else:
|
||||||
|
print(f"Alist-Strm生成: storage_id[{storage_id}]格式错误❌")
|
||||||
|
# 返回结果
|
||||||
|
if storage_mount_path and quark_root_dir:
|
||||||
|
print(f"Alist-Strm生成: [{storage_mount_path}:{quark_root_dir}]")
|
||||||
|
return True, (storage_mount_path, quark_root_dir)
|
||||||
|
else:
|
||||||
|
return False, (None, None)
|
||||||
|
|
||||||
def get_storage_info(self, storage_id):
|
def get_storage_info(self, storage_id):
|
||||||
url = f"{self.url}/api/admin/storage/get"
|
url = f"{self.url}/api/admin/storage/get"
|
||||||
@ -104,46 +119,43 @@ class Alist_strm_gen:
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data.get("code") == 200:
|
if data.get("code") == 200:
|
||||||
print(
|
|
||||||
f"Alist-Strm生成: {data['data']['driver']}[{data['data']['mount_path']}]"
|
|
||||||
)
|
|
||||||
return data.get("data", [])
|
return data.get("data", [])
|
||||||
else:
|
else:
|
||||||
print(f"Alist-Strm生成: 连接失败❌ {response.get('message')}")
|
print(f"Alist-Strm生成: 获取存储失败❌ {data.get('message')}")
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Alist-Strm生成: 获取Alist存储出错 {e}")
|
print(f"Alist-Strm生成: 获取存储出错 {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def refresh(self, path):
|
def check_dir(self, path):
|
||||||
try:
|
data = self.get_file_list(path)
|
||||||
response = self.get_file_list(path)
|
if data.get("code") != 200:
|
||||||
if response.get("code") != 200:
|
print(f"📺 Alist-Strm生成: 获取文件列表失败❌{data.get('message')}")
|
||||||
print(f"📺 生成 STRM 文件失败❌ {response.get('message')}")
|
return
|
||||||
return
|
elif files := data.get("data", {}).get("content"):
|
||||||
else:
|
for item in files:
|
||||||
files = response.get("data").get("content")
|
item_path = f"{path}/{item.get('name')}".replace("//", "/")
|
||||||
for item in files:
|
if item.get("is_dir"):
|
||||||
item_path = f"{path}/{item.get('name')}".replace("//", "/")
|
self.check_dir(item_path)
|
||||||
if item.get("is_dir"):
|
else:
|
||||||
self.refresh(item_path)
|
self.generate_strm(item_path)
|
||||||
else:
|
|
||||||
self.generate_strm(item_path)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"📺 获取 Alist 文件列表失败❌ {e}")
|
|
||||||
|
|
||||||
def get_file_list(self, path):
|
def get_file_list(self, path, force_refresh=False):
|
||||||
url = f"{self.url}/api/fs/list"
|
url = f"{self.url}/api/fs/list"
|
||||||
headers = {"Authorization": self.token}
|
headers = {"Authorization": self.token}
|
||||||
payload = {
|
payload = {
|
||||||
"path": path,
|
"path": path,
|
||||||
"refresh": False,
|
"refresh": force_refresh,
|
||||||
"password": "",
|
"password": "",
|
||||||
"page": 1,
|
"page": 1,
|
||||||
"per_page": 0,
|
"per_page": 0,
|
||||||
}
|
}
|
||||||
response = requests.request("POST", url, headers=headers, json=payload)
|
try:
|
||||||
response.raise_for_status()
|
response = requests.request("POST", url, headers=headers, json=payload)
|
||||||
return response.json()
|
response.raise_for_status()
|
||||||
|
return response.json()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"📺 Alist-Strm生成: 获取文件列表出错❌ {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
def generate_strm(self, file_path):
|
def generate_strm(self, file_path):
|
||||||
ext = file_path.split(".")[-1]
|
ext = file_path.split(".")[-1]
|
||||||
|
|||||||
@ -76,7 +76,7 @@ class Aria2:
|
|||||||
return response.json()
|
return response.json()
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"Aria2下载: 错误{e}")
|
print(f"Aria2下载: 错误{e}")
|
||||||
return None
|
return {}
|
||||||
|
|
||||||
def get_version(self):
|
def get_version(self):
|
||||||
"""检查与 Aria2 的连接."""
|
"""检查与 Aria2 的连接."""
|
||||||
@ -91,4 +91,4 @@ class Aria2:
|
|||||||
def add_uri(self, params=None):
|
def add_uri(self, params=None):
|
||||||
"""添加 URI 下载任务."""
|
"""添加 URI 下载任务."""
|
||||||
response = self._make_rpc_request("aria2.addUri", params)
|
response = self._make_rpc_request("aria2.addUri", params)
|
||||||
return response.get("result") if response else None
|
return response.get("result") if response else {}
|
||||||
|
|||||||
@ -84,7 +84,7 @@ class Emby:
|
|||||||
|
|
||||||
def search(self, media_name):
|
def search(self, media_name):
|
||||||
if not media_name:
|
if not media_name:
|
||||||
return False
|
return ""
|
||||||
url = f"{self.url}/emby/Items"
|
url = f"{self.url}/emby/Items"
|
||||||
headers = {"X-Emby-Token": self.token}
|
headers = {"X-Emby-Token": self.token}
|
||||||
querystring = {
|
querystring = {
|
||||||
@ -113,4 +113,4 @@ class Emby:
|
|||||||
print(f"🎞️ 搜索Emby媒体库:{response.text}❌")
|
print(f"🎞️ 搜索Emby媒体库:{response.text}❌")
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print(f"搜索Emby媒体库出错: {e}")
|
print(f"搜索Emby媒体库出错: {e}")
|
||||||
return False
|
return ""
|
||||||
|
|||||||
@ -90,7 +90,6 @@ class Plex:
|
|||||||
return libraries
|
return libraries
|
||||||
else:
|
else:
|
||||||
print(f"🎞️ 获取Plex媒体库信息失败❌ 状态码:{response.status_code}")
|
print(f"🎞️ 获取Plex媒体库信息失败❌ 状态码:{response.status_code}")
|
||||||
return None
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"获取Plex媒体库信息出错: {e}")
|
print(f"获取Plex媒体库信息出错: {e}")
|
||||||
return None
|
return []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user