mirror of
https://github.com/Cp0204/quark-auto-save.git
synced 2026-01-13 07:40:45 +08:00
新增手动刷新 Plex 媒体库和 AList 目录功能,修复 AList Strm Gen 插件无法生成 STRM 文件的问题
Merge pull request #26 from x1ao4/dev
This commit is contained in:
commit
48fac7faa9
58
app/run.py
58
app/run.py
@ -319,6 +319,64 @@ def run_script_now():
|
||||
)
|
||||
|
||||
|
||||
# 刷新Plex媒体库
|
||||
@app.route("/refresh_plex_library", methods=["POST"])
|
||||
def refresh_plex_library():
|
||||
if not is_login():
|
||||
return jsonify({"success": False, "message": "未登录"})
|
||||
|
||||
task_index = request.json.get("task_index")
|
||||
if task_index is None:
|
||||
return jsonify({"success": False, "message": "缺少任务索引"})
|
||||
|
||||
# 获取任务信息
|
||||
task = config_data["tasklist"][task_index]
|
||||
if not task.get("savepath"):
|
||||
return jsonify({"success": False, "message": "任务没有保存路径"})
|
||||
|
||||
# 导入Plex插件
|
||||
from plugins.plex import Plex
|
||||
|
||||
# 初始化Plex插件
|
||||
plex = Plex(**config_data["plugins"]["plex"])
|
||||
if not plex.is_active:
|
||||
return jsonify({"success": False, "message": "Plex 插件未正确配置"})
|
||||
|
||||
# 执行刷新
|
||||
plex.run(task)
|
||||
|
||||
return jsonify({"success": True, "message": "成功刷新 Plex 媒体库"})
|
||||
|
||||
|
||||
# 刷新AList目录
|
||||
@app.route("/refresh_alist_directory", methods=["POST"])
|
||||
def refresh_alist_directory():
|
||||
if not is_login():
|
||||
return jsonify({"success": False, "message": "未登录"})
|
||||
|
||||
task_index = request.json.get("task_index")
|
||||
if task_index is None:
|
||||
return jsonify({"success": False, "message": "缺少任务索引"})
|
||||
|
||||
# 获取任务信息
|
||||
task = config_data["tasklist"][task_index]
|
||||
if not task.get("savepath"):
|
||||
return jsonify({"success": False, "message": "任务没有保存路径"})
|
||||
|
||||
# 导入AList插件
|
||||
from plugins.alist import Alist
|
||||
|
||||
# 初始化AList插件
|
||||
alist = Alist(**config_data["plugins"]["alist"])
|
||||
if not alist.is_active:
|
||||
return jsonify({"success": False, "message": "AList 插件未正确配置"})
|
||||
|
||||
# 执行刷新
|
||||
alist.run(task)
|
||||
|
||||
return jsonify({"success": True, "message": "成功刷新 AList 目录"})
|
||||
|
||||
|
||||
@app.route("/task_suggestions")
|
||||
def get_task_suggestions():
|
||||
if not is_login():
|
||||
|
||||
9
app/static/Plex.svg
Normal file
9
app/static/Plex.svg
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 24.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.1" id="plex-logo" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 28.3 41.4" style="enable-background:new 0 0 28.3 41.4;" xml:space="preserve">
|
||||
<style type="text/css">
|
||||
.st0{fill:#EBAF00;}
|
||||
</style>
|
||||
<polygon class="st0" points="14.4,41.1 0.2,41.1 14,20.8 0.2,0.4 14.4,0.4 28.1,20.8 "/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 503 B |
@ -2311,6 +2311,8 @@ main .table th {
|
||||
.task .btn-outline-primary,
|
||||
.task .btn-outline-danger,
|
||||
.task .btn-warning,
|
||||
.task .btn-outline-plex,
|
||||
.task .btn-outline-alist,
|
||||
.row .btn-outline-primary {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
@ -2318,6 +2320,7 @@ main .table th {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 6px !important;
|
||||
}
|
||||
|
||||
/* 播放按钮样式 */
|
||||
@ -2422,6 +2425,7 @@ body {
|
||||
/* 任务列表页面中的任务标题颜色 */
|
||||
.task .btn.btn-block.text-left {
|
||||
color: var(--dark-text-color);
|
||||
transition: color 0.2s ease-in-out;
|
||||
}
|
||||
|
||||
/* 历史记录页面的文本和表格内容 */
|
||||
@ -3921,3 +3925,177 @@ table.selectable-records .expand-button:hover {
|
||||
#fileSelectModal .table tr.selected-file:hover {
|
||||
background-color: var(--button-gray-background-color);
|
||||
}
|
||||
|
||||
/* Plex按钮样式 */
|
||||
.btn-outline-plex {
|
||||
border-color: #EBAF00;
|
||||
color: #EBAF00;
|
||||
}
|
||||
|
||||
.btn-outline-plex:hover {
|
||||
background-color: #EBAF00;
|
||||
border-color: #EBAF00;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-outline-plex:hover .plex-icon {
|
||||
filter: brightness(0) invert(1);
|
||||
}
|
||||
|
||||
/* AList按钮样式 */
|
||||
.btn-outline-alist {
|
||||
border-color: #70C6BE;
|
||||
color: #70C6BE;
|
||||
}
|
||||
|
||||
.btn-outline-alist:hover {
|
||||
background-color: #70C6BE;
|
||||
border-color: #70C6BE;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-outline-alist:hover .alist-icon {
|
||||
filter: brightness(0) invert(1);
|
||||
}
|
||||
|
||||
/* Plex图标样式 */
|
||||
.plex-icon {
|
||||
width: 10.4px;
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* AList图标样式 */
|
||||
.alist-icon {
|
||||
width: 17.8px;
|
||||
height: auto;
|
||||
object-fit: contain;
|
||||
position: relative;
|
||||
top: -0.5px;
|
||||
}
|
||||
|
||||
/* 任务按钮悬停显示样式 */
|
||||
.task-buttons .hover-only {
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
/* 修改悬停触发范围到整个任务单元 */
|
||||
.task:hover .task-buttons .hover-only {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
position: static;
|
||||
}
|
||||
|
||||
/* 确保按钮容器在悬停时保持宽度 */
|
||||
.task-buttons {
|
||||
position: relative;
|
||||
min-width: 160px; /* 根据按钮数量和间距调整 */
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-right: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
/* 确保按钮在悬停时可见 */
|
||||
.task:hover .task-buttons {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* 移动模式下的任务按钮容器样式 */
|
||||
@media (max-width: 767.98px) {
|
||||
.task .col-auto.task-buttons {
|
||||
padding-right: 15px; /* 与添加任务按钮的右边距保持一致 */
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 992px) {
|
||||
.display-setting-row > .col-lg-3 {
|
||||
padding-left: 4px !important;
|
||||
padding-right: 4px !important;
|
||||
}
|
||||
.display-setting-row {
|
||||
margin-left: -4px !important;
|
||||
margin-right: -4px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.display-setting-row > [class*='col-'] {
|
||||
padding-left: 4px !important;
|
||||
padding-right: 4px !important;
|
||||
}
|
||||
.display-setting-row {
|
||||
margin-left: -4px !important;
|
||||
margin-right: -4px !important;
|
||||
}
|
||||
|
||||
/* 任务单元基础样式 */
|
||||
.task {
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 任务展开后的配置区域使用默认指针 */
|
||||
.task .collapse {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* 任务按钮悬停显示样式 */
|
||||
.task-buttons .hover-only {
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease-in-out;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
/* 修改悬停触发范围到整个任务单元 */
|
||||
.task:hover .task-buttons .hover-only {
|
||||
opacity: 1;
|
||||
visibility: visible;
|
||||
position: static;
|
||||
}
|
||||
|
||||
/* 确保按钮容器在悬停时保持宽度 */
|
||||
.task-buttons {
|
||||
position: relative;
|
||||
min-width: 160px; /* 根据按钮数量和间距调整 */
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding-right: 0;
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
/* 确保按钮在悬停时可见 */
|
||||
.task:hover .task-buttons {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* 添加伪元素扩展整个任务单元的可点击区域 */
|
||||
.task::before,
|
||||
.task::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 8px;
|
||||
background: transparent;
|
||||
z-index: 0;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.task::before {
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.task::after {
|
||||
bottom: -8px;
|
||||
}
|
||||
|
||||
/* 当鼠标悬停在任务单元上时,任务标题变为蓝色 */
|
||||
.task:hover .btn.btn-block.text-left {
|
||||
color: var(--focus-border-color);
|
||||
}
|
||||
|
||||
@ -440,6 +440,63 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row title" title="设置任务列表页面的任务按钮的显示方式,刷新Plex媒体库和刷新AList目录按钮仅在配置了对应插件的前提下才支持显示">
|
||||
<div class="col">
|
||||
<h2 style="display: inline-block; font-size: 1.5rem;">显示设置</h2>
|
||||
<span class="badge badge-pill badge-light">
|
||||
<a href="#"><i class="bi bi-question-circle"></i></a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-2 display-setting-row">
|
||||
<div class="col-lg-3 col-md-6 mb-2">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">运行此任务</span>
|
||||
</div>
|
||||
<select class="form-control" v-model="formData.button_display.run_task">
|
||||
<option value="always">始终显示</option>
|
||||
<option value="hover">悬停显示</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mb-2">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">删除此任务</span>
|
||||
</div>
|
||||
<select class="form-control" v-model="formData.button_display.delete_task">
|
||||
<option value="always">始终显示</option>
|
||||
<option value="hover">悬停显示</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mb-2">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">刷新 Plex 媒体库</span>
|
||||
</div>
|
||||
<select class="form-control" v-model="formData.button_display.refresh_plex">
|
||||
<option value="always">始终显示</option>
|
||||
<option value="hover">悬停显示</option>
|
||||
<option value="disabled">禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-6 mb-2">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">刷新 AList 目录</span>
|
||||
</div>
|
||||
<select class="form-control" v-model="formData.button_display.refresh_alist">
|
||||
<option value="always">始终显示</option>
|
||||
<option value="hover">悬停显示</option>
|
||||
<option value="disabled">禁用</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div v-if="activeTab === 'tasklist'">
|
||||
@ -483,10 +540,12 @@
|
||||
<i class="bi bi-caret-right-fill"></i> #<span v-html="`${String(index+1).padStart(2, '0')} ${task.taskname}`"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
<div class="col-auto task-buttons">
|
||||
<button type="button" class="btn btn-outline-plex" v-if="formData.plugins && formData.plugins.plex && formData.plugins.plex.url && formData.plugins.plex.token && formData.plugins.plex.quark_root_path && formData.button_display.refresh_plex !== 'disabled'" :class="{'hover-only': formData.button_display.refresh_plex === 'hover'}" @click="refreshPlexLibrary(index)" title="刷新Plex媒体库"><img src="./static/Plex.svg" class="plex-icon"></button>
|
||||
<button type="button" class="btn btn-outline-alist" v-if="formData.plugins && formData.plugins.alist && formData.plugins.alist.url && formData.plugins.alist.token && formData.plugins.alist.storage_id && formData.button_display.refresh_alist !== 'disabled'" :class="{'hover-only': formData.button_display.refresh_alist === 'hover'}" @click="refreshAlistDirectory(index)" title="刷新AList目录"><img src="https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg" class="alist-icon"></button>
|
||||
<button class="btn btn-warning" v-if="task.shareurl_ban" :title="formatShareUrlBanMessage(task.shareurl_ban)" disabled><i class="bi bi-exclamation-circle"></i></button>
|
||||
<button type="button" class="btn btn-outline-primary" @click="runScriptNow(index)" title="运行此任务" v-else><i class="bi bi-caret-right"></i></button>
|
||||
<button type="button" class="btn btn-outline-danger" @click="removeTask(index)" title="删除此任务"><i class="bi bi-trash3"></i></button>
|
||||
<button type="button" class="btn btn-outline-primary" @click="runScriptNow(index)" title="运行此任务" v-if="!task.shareurl_ban" :class="{'hover-only': formData.button_display.run_task === 'hover'}"><i class="bi bi-caret-right"></i></button>
|
||||
<button type="button" class="btn btn-outline-danger" @click="removeTask(index)" title="删除此任务" :class="{'hover-only': formData.button_display.delete_task === 'hover'}"><i class="bi bi-trash3"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="collapse ml-3" :id="'collapse_'+index">
|
||||
@ -1006,6 +1065,12 @@
|
||||
webui: {
|
||||
username: "",
|
||||
password: ""
|
||||
},
|
||||
button_display: {
|
||||
run_task: "always",
|
||||
delete_task: "always",
|
||||
refresh_plex: "always",
|
||||
refresh_alist: "always"
|
||||
}
|
||||
},
|
||||
userInfoList: [], // 用户信息列表
|
||||
@ -1524,6 +1589,15 @@
|
||||
if (!config_data.episode_patterns) {
|
||||
config_data.episode_patterns = [];
|
||||
}
|
||||
// 确保按钮显示配置存在
|
||||
if (!config_data.button_display) {
|
||||
config_data.button_display = {
|
||||
run_task: "always",
|
||||
delete_task: "always",
|
||||
refresh_plex: "always",
|
||||
refresh_alist: "always"
|
||||
};
|
||||
}
|
||||
this.formData = config_data;
|
||||
setTimeout(() => {
|
||||
this.configModified = false;
|
||||
@ -3584,6 +3658,32 @@
|
||||
});
|
||||
}
|
||||
},
|
||||
refreshPlexLibrary(index) {
|
||||
axios.post('/refresh_plex_library', { task_index: index })
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.showToast(response.data.message);
|
||||
} else {
|
||||
alert(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert("刷新 Plex 媒体库失败: " + (error.response?.data?.message || error.message || "未知错误"));
|
||||
});
|
||||
},
|
||||
refreshAlistDirectory(index) {
|
||||
axios.post('/refresh_alist_directory', { task_index: index })
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.showToast(response.data.message);
|
||||
} else {
|
||||
alert(response.data.message);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert("刷新 AList 目录失败: " + (error.response?.data?.message || error.message || "未知错误"));
|
||||
});
|
||||
},
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -2,7 +2,7 @@ import re
|
||||
import requests
|
||||
|
||||
"""
|
||||
配合 Alist-Strm 项目,触发特定配置运行
|
||||
配合 AList-Strm 项目,触发特定配置运行
|
||||
https://github.com/tefuirZ/alist-strm
|
||||
"""
|
||||
|
||||
@ -47,12 +47,12 @@ class Alist_strm:
|
||||
for item in matchs
|
||||
if item[0] in config_id_str.split(",")
|
||||
]
|
||||
print(f"Alist-Strm 配置运行: {config_name}")
|
||||
print(f"AList-Strm 配置运行: {config_name}")
|
||||
return True
|
||||
else:
|
||||
print(f"Alist-Strm 配置运行: 匹配失败 ❌ 请检查网络连通和cookie有效性")
|
||||
print(f"AList-Strm 配置运行: 匹配失败 ❌ 请检查网络连通和 Cookie 有效性")
|
||||
except Exception as e:
|
||||
print(f"获取 Alist-Strm 配置信息出错: {e}")
|
||||
print(f"获取 AList-Strm 配置信息出错 ❌ {e}")
|
||||
return False
|
||||
|
||||
def run_selected_configs(self, selected_configs_str):
|
||||
@ -61,7 +61,7 @@ class Alist_strm:
|
||||
try:
|
||||
selected_configs = [int(x.strip()) for x in selected_configs_str.split(",")]
|
||||
except ValueError:
|
||||
print("🔗 Alist-Strm 配置运行: 出错 ❌ ID 应以 , 分割")
|
||||
print("🔗 AList-Strm 配置运行: 出错 ❌ ID 应以 , 分割")
|
||||
return False
|
||||
data = [("selected_configs", config_id) for config_id in selected_configs]
|
||||
data.append(("action", "run_selected"))
|
||||
@ -73,10 +73,10 @@ class Alist_strm:
|
||||
match = re.search(r'role="alert">\s*([^<]+)\s*<button', html_content)
|
||||
if match:
|
||||
alert = match.group(1).strip()
|
||||
print(f"🔗 Alist-Strm 配置运行: {alert} ✅")
|
||||
print(f"🔗 AList-Strm 配置运行: {alert} ✅")
|
||||
return True
|
||||
else:
|
||||
print(f"🔗 Alist-Strm 配置运行: 失败 ❌")
|
||||
print(f"🔗 AList-Strm 配置运行: 失败 ❌")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
return False
|
||||
|
||||
@ -2,16 +2,15 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
"""
|
||||
@File : alist_strm_gen.py
|
||||
@Desc : Alist 生成 strm 文件简化版
|
||||
@Version : v1.1
|
||||
@Time : 2024/11/16
|
||||
@Author : xiaoQQya
|
||||
@Contact : xiaoQQya@126.com
|
||||
@Desc : AList 生成 STRM 文件简化版
|
||||
@Time : 2025/05/30
|
||||
@Author : xiaoQQya, x1ao4
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
import requests
|
||||
from quark_auto_save import sort_file_by_name
|
||||
|
||||
|
||||
class Alist_strm_gen:
|
||||
@ -32,47 +31,97 @@ class Alist_strm_gen:
|
||||
storage_mount_path = None
|
||||
quark_root_dir = None
|
||||
strm_server = None
|
||||
# 缓存生成的文件列表
|
||||
generated_files = []
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.plugin_name = self.__class__.__name__.lower()
|
||||
if kwargs:
|
||||
for key, _ in self.default_config.items():
|
||||
if key in kwargs:
|
||||
setattr(self, key, kwargs[key])
|
||||
|
||||
# 检查必要配置
|
||||
missing_configs = []
|
||||
for key, _ in self.default_config.items():
|
||||
if key in kwargs:
|
||||
setattr(self, key, kwargs[key])
|
||||
else:
|
||||
missing_configs.append(key)
|
||||
|
||||
if missing_configs:
|
||||
print(f"{self.plugin_name} 模块缺少必要参数: {', '.join(missing_configs)}")
|
||||
return
|
||||
|
||||
if not self.url or not self.token or not self.storage_id:
|
||||
print(f"{self.plugin_name} 模块配置不完整,请检查配置")
|
||||
return
|
||||
|
||||
# 检查 strm_save_dir 是否存在
|
||||
if not os.path.exists(self.strm_save_dir):
|
||||
try:
|
||||
os.makedirs(self.strm_save_dir)
|
||||
except Exception as e:
|
||||
print(f"创建 STRM 保存目录失败 ❌ {e}")
|
||||
return
|
||||
|
||||
success, result = self.storage_id_to_path(self.storage_id)
|
||||
if success:
|
||||
self.is_active = True
|
||||
# 存储挂载路径, 夸克根文件夹
|
||||
self.storage_mount_path, self.quark_root_dir = result
|
||||
# 替换strm文件内链接的主机地址
|
||||
self.strm_replace_host = self.strm_replace_host.strip()
|
||||
if self.strm_replace_host:
|
||||
if self.strm_replace_host.startswith("http"):
|
||||
self.strm_server = f"{self.strm_replace_host}/d"
|
||||
else:
|
||||
print(f"{self.plugin_name} 模块缺少必要参数: {key}")
|
||||
if self.url and self.token and self.storage_id:
|
||||
success, result = self.storage_id_to_path(self.storage_id)
|
||||
if success:
|
||||
self.is_active = True
|
||||
# 存储挂载路径, 夸克根文件夹
|
||||
self.storage_mount_path, self.quark_root_dir = result
|
||||
# 替换strm文件内链接的主机地址
|
||||
self.strm_replace_host = self.strm_replace_host.strip()
|
||||
if self.strm_replace_host:
|
||||
if self.strm_replace_host.startswith("http"):
|
||||
self.strm_server = f"{self.strm_replace_host}/d"
|
||||
else:
|
||||
self.strm_server = f"http://{self.strm_replace_host}/d"
|
||||
else:
|
||||
self.strm_server = f"{self.url.strip()}/d"
|
||||
self.strm_server = f"http://{self.strm_replace_host}/d"
|
||||
else:
|
||||
self.strm_server = f"{self.url.strip()}/d"
|
||||
else:
|
||||
pass
|
||||
|
||||
def run(self, task, **kwargs):
|
||||
if not self.is_active:
|
||||
return
|
||||
|
||||
task_config = task.get("addition", {}).get(
|
||||
self.plugin_name, self.default_task_config
|
||||
)
|
||||
|
||||
if not task_config.get("auto_gen"):
|
||||
return
|
||||
if task.get("savepath") and task.get("savepath").startswith(
|
||||
self.quark_root_dir
|
||||
):
|
||||
alist_path = os.path.normpath(
|
||||
os.path.join(
|
||||
self.storage_mount_path,
|
||||
task["savepath"].replace(self.quark_root_dir, "", 1).lstrip("/"),
|
||||
)
|
||||
).replace("\\", "/")
|
||||
self.check_dir(alist_path)
|
||||
|
||||
if not task.get("savepath"):
|
||||
return
|
||||
|
||||
# 标准化路径
|
||||
savepath = os.path.normpath(task["savepath"]).replace("\\", "/")
|
||||
quark_root = os.path.normpath(self.quark_root_dir).replace("\\", "/")
|
||||
|
||||
# 确保路径以 / 开头
|
||||
if not savepath.startswith("/"):
|
||||
savepath = "/" + savepath
|
||||
if not quark_root.startswith("/"):
|
||||
quark_root = "/" + quark_root
|
||||
|
||||
if not savepath.startswith(quark_root):
|
||||
print(f"{self.plugin_name} 任务的保存路径不在配置的夸克根目录内,跳过处理")
|
||||
return
|
||||
|
||||
alist_path = os.path.normpath(
|
||||
os.path.join(
|
||||
self.storage_mount_path,
|
||||
savepath.replace(quark_root, "", 1).lstrip("/"),
|
||||
)
|
||||
).replace("\\", "/")
|
||||
|
||||
# 清空生成的文件列表
|
||||
self.generated_files = []
|
||||
self.check_dir(alist_path)
|
||||
|
||||
# 按顺序显示生成的文件
|
||||
if self.generated_files:
|
||||
sorted_files = sorted(self.generated_files, key=sort_file_by_name)
|
||||
for file_path in sorted_files:
|
||||
print(f"🌐 生成 STRM 文件: {file_path} 成功 ✅")
|
||||
|
||||
def storage_id_to_path(self, storage_id):
|
||||
storage_mount_path, quark_root_dir = None, None
|
||||
@ -82,7 +131,7 @@ class Alist_strm_gen:
|
||||
storage_mount_path, quark_root_dir = match.group(1), match.group(2)
|
||||
file_list = self.get_file_list(storage_mount_path)
|
||||
if file_list.get("code") != 200:
|
||||
print(f"Alist-Strm 生成: 获取挂载路径失败 ❌ {file_list.get('message')}")
|
||||
print(f"AList-Strm 生成: 获取挂载路径失败 ❌ {file_list.get('message')}")
|
||||
return False, (None, None)
|
||||
# 2. 检查是否数字,调用 Alist API 获取存储信息
|
||||
elif re.match(r"^\d+$", storage_id):
|
||||
@ -97,15 +146,15 @@ class Alist_strm_gen:
|
||||
)
|
||||
elif storage_info["driver"] == "QuarkTV":
|
||||
print(
|
||||
f"Alist-Strm 生成: [QuarkTV] 驱动 ⚠️ storage_id 请手动填入 /Alist挂载路径:/Quark目录路径"
|
||||
f"AList-Strm 生成: [QuarkTV] 驱动 ⚠️ storage_id 请手动填入 /Alist挂载路径:/Quark目录路径"
|
||||
)
|
||||
else:
|
||||
print(f"Alist-Strm 生成: 不支持 [{storage_info['driver']}] 驱动 ❌")
|
||||
print(f"AList-Strm 生成: 不支持 [{storage_info['driver']}] 驱动 ❌")
|
||||
else:
|
||||
print(f"Alist-Strm 生成: storage_id [{storage_id}] 格式错误❌")
|
||||
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}]")
|
||||
print(f"AList-Strm 生成: [{storage_mount_path}:{quark_root_dir}]")
|
||||
return True, (storage_mount_path, quark_root_dir)
|
||||
else:
|
||||
return False, (None, None)
|
||||
@ -121,15 +170,15 @@ class Alist_strm_gen:
|
||||
if data.get("code") == 200:
|
||||
return data.get("data", [])
|
||||
else:
|
||||
print(f"Alist-Strm 生成: 获取存储失败 ❌ {data.get('message')}")
|
||||
print(f"AList-Strm 生成: 获取存储失败 ❌ {data.get('message')}")
|
||||
except Exception as e:
|
||||
print(f"Alist-Strm 生成: 获取存储出错 {e}")
|
||||
print(f"AList-Strm 生成: 获取存储出错 ❌ {e}")
|
||||
return []
|
||||
|
||||
def check_dir(self, path):
|
||||
data = self.get_file_list(path)
|
||||
if data.get("code") != 200:
|
||||
print(f"📺 Alist-Strm 生成: 获取文件列表失败 ❌ {data.get('message')}")
|
||||
print(f"🌐 AList-Strm 生成: 获取文件列表失败 ❌ {data.get('message')}")
|
||||
return
|
||||
elif files := data.get("data", {}).get("content"):
|
||||
for item in files:
|
||||
@ -154,7 +203,7 @@ class Alist_strm_gen:
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
print(f"📺 Alist-Strm 生成: 获取文件列表出错 ❌ {e}")
|
||||
print(f"🌐 AList-Strm 生成: 获取文件列表出错 ❌ {e}")
|
||||
return {}
|
||||
|
||||
def generate_strm(self, file_path):
|
||||
@ -168,10 +217,18 @@ class Alist_strm_gen:
|
||||
if os.path.exists(strm_path):
|
||||
return
|
||||
if not os.path.exists(os.path.dirname(strm_path)):
|
||||
os.makedirs(os.path.dirname(strm_path))
|
||||
with open(strm_path, "w", encoding="utf-8") as strm_file:
|
||||
strm_file.write(f"{self.strm_server}{file_path}")
|
||||
print(f"📺 生成 STRM 文件 {strm_path} 成功 ✅")
|
||||
try:
|
||||
os.makedirs(os.path.dirname(strm_path))
|
||||
except Exception as e:
|
||||
print(f"🌐 创建目录失败: {os.path.dirname(strm_path)} ❌ {e}")
|
||||
return
|
||||
try:
|
||||
with open(strm_path, "w", encoding="utf-8") as strm_file:
|
||||
strm_file.write(f"{self.strm_server}{file_path}")
|
||||
# 将生成的文件添加到列表中,稍后统一显示
|
||||
self.generated_files.append(strm_path)
|
||||
except Exception as e:
|
||||
print(f"🌐 生成 STRM 文件: {strm_path} 失败 ❌ {e}")
|
||||
|
||||
def get_root_folder_full_path(self, cookie, pdir_fid):
|
||||
if pdir_fid == "0":
|
||||
@ -203,5 +260,5 @@ class Alist_strm_gen:
|
||||
path = f"{path}/{item['file_name']}"
|
||||
return path
|
||||
except Exception as e:
|
||||
print(f"Alist-Strm 生成: 获取 Quark 路径出错 {e}")
|
||||
print(f"AList-Strm 生成: 获取 Quark 路径出错 ❌ {e}")
|
||||
return ""
|
||||
|
||||
@ -151,7 +151,7 @@ class Aria2:
|
||||
download_return, cookie = account.download(file_fids)
|
||||
|
||||
if not download_return.get("data"):
|
||||
print("📝 Aria2: 获取下载链接失败")
|
||||
print("📝 Aria2: 获取下载链接失败 ❌")
|
||||
return
|
||||
|
||||
# 准备要下载的文件信息
|
||||
@ -186,7 +186,7 @@ class Aria2:
|
||||
# print(f"📥 Aria2下载: {file_path} (已存在,跳过)")
|
||||
continue
|
||||
|
||||
print(f"📥 Aria2 下载: {file_path}")
|
||||
print(f"📥 添加 Aria2 下载任务: {file_path} 成功 ✅")
|
||||
|
||||
# 确保目录存在
|
||||
os.makedirs(os.path.dirname(local_path), exist_ok=True)
|
||||
@ -210,7 +210,7 @@ class Aria2:
|
||||
if idx >= 0 and idx < len(file_info):
|
||||
downloaded_files.append(file_info[idx])
|
||||
except Exception as e:
|
||||
print(f"📥 Aria2 添加下载任务失败: {e}")
|
||||
print(f"📥 添加 Aria2 下载任务失败 ❌ {e}")
|
||||
|
||||
# 如果配置了自动删除且有成功添加下载任务的文件,则删除夸克网盘中的文件
|
||||
if task_config.get("auto_delete_quark_files") and downloaded_files:
|
||||
@ -225,7 +225,7 @@ class Aria2:
|
||||
if files_to_delete:
|
||||
account.delete(files_to_delete)
|
||||
except Exception as e:
|
||||
print(f"📝 Aria2: 删除夸克网盘文件失败: {e}")
|
||||
print(f"📝 Aria2: 删除夸克网盘文件失败 ❌ {e}")
|
||||
else:
|
||||
if not task_config.get("auto_delete_quark_files"):
|
||||
# 未启用自动删除,不需要输出信息
|
||||
@ -249,7 +249,7 @@ class Aria2:
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except Exception as e:
|
||||
print(f"Aria2 下载: 错误{e}")
|
||||
print(f"Aria2 下载: 错误 ❌ {e}")
|
||||
return {}
|
||||
|
||||
def get_version(self):
|
||||
@ -259,7 +259,7 @@ class Aria2:
|
||||
print(f"Aria2 下载: v{response['result']['version']}")
|
||||
return True
|
||||
else:
|
||||
print(f"Aria2 下载: 连接失败{response.get('error')}")
|
||||
print(f"Aria2 下载: 连接失败 ❌ {response.get('error')}")
|
||||
return False
|
||||
|
||||
def add_uri(self, params=None):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user