Delete quark_auto_save.py
Browse files- quark_auto_save.py +0 -1304
quark_auto_save.py
DELETED
|
@@ -1,1304 +0,0 @@
|
|
| 1 |
-
# !/usr/bin/env python3
|
| 2 |
-
# -*- coding: utf-8 -*-
|
| 3 |
-
# Modify: 2026-02-04
|
| 4 |
-
# Repo: https://github.com/Cp0204/quark_auto_save
|
| 5 |
-
# ConfigFile: quark_config.json
|
| 6 |
-
"""
|
| 7 |
-
new Env('夸克自动追更');
|
| 8 |
-
0 8,18,20 * * * quark_auto_save.py
|
| 9 |
-
"""
|
| 10 |
-
import os
|
| 11 |
-
import re
|
| 12 |
-
import sys
|
| 13 |
-
import json
|
| 14 |
-
import time
|
| 15 |
-
import random
|
| 16 |
-
import platform
|
| 17 |
-
import requests
|
| 18 |
-
import importlib
|
| 19 |
-
import traceback
|
| 20 |
-
import urllib.parse
|
| 21 |
-
from datetime import datetime
|
| 22 |
-
from natsort import natsorted
|
| 23 |
-
|
| 24 |
-
# 兼容青龙
|
| 25 |
-
try:
|
| 26 |
-
from treelib import Tree
|
| 27 |
-
except:
|
| 28 |
-
print("正在尝试自动安装依赖...")
|
| 29 |
-
os.system("pip3 install treelib &> /dev/null")
|
| 30 |
-
from treelib import Tree
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
CONFIG_DATA = {}
|
| 34 |
-
NOTIFYS = []
|
| 35 |
-
GH_PROXY = os.environ.get("GH_PROXY", "https://ghproxy.net/")
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
# 发送通知消息
|
| 39 |
-
def send_ql_notify(title, body):
|
| 40 |
-
try:
|
| 41 |
-
# 导入通知模块
|
| 42 |
-
import notify
|
| 43 |
-
|
| 44 |
-
# 如未配置 push_config 则使用青龙环境通知设置
|
| 45 |
-
if CONFIG_DATA.get("push_config"):
|
| 46 |
-
notify.push_config.update(CONFIG_DATA["push_config"])
|
| 47 |
-
notify.push_config["CONSOLE"] = notify.push_config.get("CONSOLE", True)
|
| 48 |
-
notify.send(title, body)
|
| 49 |
-
except Exception as e:
|
| 50 |
-
if e:
|
| 51 |
-
print("发送通知消息失败!")
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
# 添加消息
|
| 55 |
-
def add_notify(text):
|
| 56 |
-
global NOTIFYS
|
| 57 |
-
NOTIFYS.append(text)
|
| 58 |
-
print("📢", text)
|
| 59 |
-
return text
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
class Config:
|
| 63 |
-
# 下载配置
|
| 64 |
-
def download_file(url, save_path):
|
| 65 |
-
response = requests.get(url)
|
| 66 |
-
if response.status_code == 200:
|
| 67 |
-
with open(save_path, "wb") as file:
|
| 68 |
-
file.write(response.content)
|
| 69 |
-
return True
|
| 70 |
-
else:
|
| 71 |
-
return False
|
| 72 |
-
|
| 73 |
-
# 读取 JSON 文件内容
|
| 74 |
-
def read_json(config_path):
|
| 75 |
-
with open(config_path, "r", encoding="utf-8") as f:
|
| 76 |
-
data = json.load(f)
|
| 77 |
-
return data
|
| 78 |
-
|
| 79 |
-
# 将数据写入 JSON 文件
|
| 80 |
-
def write_json(config_path, data):
|
| 81 |
-
with open(config_path, "w", encoding="utf-8") as f:
|
| 82 |
-
json.dump(data, f, ensure_ascii=False, sort_keys=False, indent=2)
|
| 83 |
-
|
| 84 |
-
# 读取CK
|
| 85 |
-
def get_cookies(cookie_val):
|
| 86 |
-
if isinstance(cookie_val, list):
|
| 87 |
-
return cookie_val
|
| 88 |
-
elif cookie_val:
|
| 89 |
-
if "\n" in cookie_val:
|
| 90 |
-
return cookie_val.split("\n")
|
| 91 |
-
else:
|
| 92 |
-
return [cookie_val]
|
| 93 |
-
else:
|
| 94 |
-
return False
|
| 95 |
-
|
| 96 |
-
def load_plugins(plugins_config={}, plugins_dir="plugins"):
|
| 97 |
-
PLUGIN_FLAGS = os.environ.get("PLUGIN_FLAGS", "").split(",")
|
| 98 |
-
plugins_available = {}
|
| 99 |
-
task_plugins_config = {}
|
| 100 |
-
# 获取所有模块
|
| 101 |
-
sys_ext = "pyd" if platform.system() == "Windows" else "so"
|
| 102 |
-
module_ext = [".py", f".{sys_ext}"]
|
| 103 |
-
all_modules = [
|
| 104 |
-
f.replace(ext, "")
|
| 105 |
-
for f in os.listdir(plugins_dir)
|
| 106 |
-
for ext in module_ext
|
| 107 |
-
if f.endswith(ext)
|
| 108 |
-
]
|
| 109 |
-
# 调整模块优先级
|
| 110 |
-
priority_path = os.path.join(plugins_dir, "_priority.json")
|
| 111 |
-
try:
|
| 112 |
-
with open(priority_path, encoding="utf-8") as f:
|
| 113 |
-
priority_modules = json.load(f)
|
| 114 |
-
except (FileNotFoundError, json.JSONDecodeError):
|
| 115 |
-
priority_modules = []
|
| 116 |
-
if priority_modules:
|
| 117 |
-
all_modules = [
|
| 118 |
-
module for module in priority_modules if module in all_modules
|
| 119 |
-
] + [module for module in all_modules if module not in priority_modules]
|
| 120 |
-
# 加载模块
|
| 121 |
-
for module_name in all_modules:
|
| 122 |
-
if f"-{module_name}" in PLUGIN_FLAGS:
|
| 123 |
-
continue
|
| 124 |
-
try:
|
| 125 |
-
module = importlib.import_module(f"{plugins_dir}.{module_name}")
|
| 126 |
-
ServerClass = getattr(module, module_name.capitalize())
|
| 127 |
-
# 检查配置中是否存在该模块的配置
|
| 128 |
-
if module_name in plugins_config:
|
| 129 |
-
plugin = ServerClass(**plugins_config[module_name])
|
| 130 |
-
plugins_available[module_name] = plugin
|
| 131 |
-
else:
|
| 132 |
-
plugin = ServerClass()
|
| 133 |
-
plugins_config[module_name] = plugin.default_config
|
| 134 |
-
# 检查插件是否支持单独任务配置
|
| 135 |
-
if hasattr(plugin, "default_task_config"):
|
| 136 |
-
task_plugins_config[module_name] = plugin.default_task_config
|
| 137 |
-
except (ImportError, AttributeError) as e:
|
| 138 |
-
print(f"载入模块 {module_name} 失败: {e}")
|
| 139 |
-
return plugins_available, plugins_config, task_plugins_config
|
| 140 |
-
|
| 141 |
-
def breaking_change_update(config_data):
|
| 142 |
-
# 🔼 Update config v0.5.x to 0.6.0
|
| 143 |
-
for task in config_data.get("tasklist", []):
|
| 144 |
-
if "$TASKNAME" in task.get("replace", ""):
|
| 145 |
-
task["replace"] = task["replace"].replace("$TASKNAME", "{TASKNAME}")
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
class MagicRename:
|
| 149 |
-
|
| 150 |
-
magic_regex = {
|
| 151 |
-
"$TV": {
|
| 152 |
-
"pattern": r".*?([Ss]\d{1,2})?(?:[第EePpXx\.\-\_\( ]{1,2}|^)(\d{1,3})(?!\d).*?\.(mp4|mkv)",
|
| 153 |
-
"replace": r"\1E\2.\3",
|
| 154 |
-
},
|
| 155 |
-
"$BLACK_WORD": {
|
| 156 |
-
"pattern": r"^(?!.*纯享)(?!.*加更)(?!.*超前企划)(?!.*训练室)(?!.*蒸蒸日上).*",
|
| 157 |
-
"replace": "",
|
| 158 |
-
},
|
| 159 |
-
}
|
| 160 |
-
|
| 161 |
-
magic_variable = {
|
| 162 |
-
"{TASKNAME}": "",
|
| 163 |
-
"{I}": 1,
|
| 164 |
-
"{EXT}": [r"(?<=\.)\w+$"],
|
| 165 |
-
"{CHINESE}": [r"[\u4e00-\u9fa5]{2,}"],
|
| 166 |
-
"{DATE}": [
|
| 167 |
-
r"(18|19|20)?\d{2}[\.\-/年]\d{1,2}[\.\-/月]\d{1,2}",
|
| 168 |
-
r"(?<!\d)[12]\d{3}[01]?\d[0123]?\d",
|
| 169 |
-
r"(?<!\d)[01]?\d[\.\-/月][0123]?\d",
|
| 170 |
-
],
|
| 171 |
-
"{YEAR}": [r"(?<!\d)(18|19|20)\d{2}(?!\d)"],
|
| 172 |
-
"{S}": [r"(?<=[Ss])\d{1,2}(?=[EeXx])", r"(?<=[Ss])\d{1,2}"],
|
| 173 |
-
"{SXX}": [r"[Ss]\d{1,2}(?=[EeXx])", r"[Ss]\d{1,2}"],
|
| 174 |
-
"{E}": [
|
| 175 |
-
r"(?<=[Ss]\d\d[Ee])\d{1,3}",
|
| 176 |
-
r"(?<=[Ee])\d{1,3}",
|
| 177 |
-
r"(?<=[Ee][Pp])\d{1,3}",
|
| 178 |
-
r"(?<=第)\d{1,3}(?=[集期话部篇])",
|
| 179 |
-
r"(?<!\d)\d{1,3}(?=[集期话部篇])",
|
| 180 |
-
r"(?!.*19)(?!.*20)(?<=[\._])\d{1,3}(?=[\._])",
|
| 181 |
-
r"^\d{1,3}(?=\.\w+)",
|
| 182 |
-
r"(?<!\d)\d{1,3}(?!\d)(?!$)",
|
| 183 |
-
],
|
| 184 |
-
"{PART}": [
|
| 185 |
-
r"(?<=[集期话部篇第])[上中下一二三四五六七八九十]",
|
| 186 |
-
r"[上中下一二三四五六七八九十]",
|
| 187 |
-
],
|
| 188 |
-
"{VER}": [r"[\u4e00-\u9fa5]+版"],
|
| 189 |
-
}
|
| 190 |
-
|
| 191 |
-
priority_list = [
|
| 192 |
-
"上",
|
| 193 |
-
"中",
|
| 194 |
-
"下",
|
| 195 |
-
"一",
|
| 196 |
-
"二",
|
| 197 |
-
"三",
|
| 198 |
-
"四",
|
| 199 |
-
"五",
|
| 200 |
-
"六",
|
| 201 |
-
"七",
|
| 202 |
-
"八",
|
| 203 |
-
"九",
|
| 204 |
-
"十",
|
| 205 |
-
"百",
|
| 206 |
-
"千",
|
| 207 |
-
"万",
|
| 208 |
-
]
|
| 209 |
-
|
| 210 |
-
def __init__(self, magic_regex={}, magic_variable={}):
|
| 211 |
-
self.magic_regex.update(magic_regex)
|
| 212 |
-
self.magic_variable.update(magic_variable)
|
| 213 |
-
self.dir_filename_dict = {}
|
| 214 |
-
|
| 215 |
-
def set_taskname(self, taskname):
|
| 216 |
-
"""设置任务名称"""
|
| 217 |
-
self.magic_variable["{TASKNAME}"] = taskname
|
| 218 |
-
|
| 219 |
-
def magic_regex_conv(self, pattern, replace):
|
| 220 |
-
"""魔法正则匹配"""
|
| 221 |
-
keyword = pattern
|
| 222 |
-
if keyword in self.magic_regex:
|
| 223 |
-
pattern = self.magic_regex[keyword]["pattern"]
|
| 224 |
-
if replace == "":
|
| 225 |
-
replace = self.magic_regex[keyword]["replace"]
|
| 226 |
-
return pattern, replace
|
| 227 |
-
|
| 228 |
-
def sub(self, pattern, replace, file_name):
|
| 229 |
-
"""魔法正则、变量替换"""
|
| 230 |
-
if not replace:
|
| 231 |
-
return file_name
|
| 232 |
-
# 预处理替换变量
|
| 233 |
-
for key, p_list in self.magic_variable.items():
|
| 234 |
-
if key in replace:
|
| 235 |
-
# 正则类替换变量
|
| 236 |
-
if p_list and isinstance(p_list, list):
|
| 237 |
-
for p in p_list:
|
| 238 |
-
match = re.search(p, file_name)
|
| 239 |
-
if match:
|
| 240 |
-
# 匹配成功,替换为匹配到的值
|
| 241 |
-
value = match.group()
|
| 242 |
-
# 日期格式处理:补全、格式化
|
| 243 |
-
if key == "{DATE}":
|
| 244 |
-
value = "".join(
|
| 245 |
-
[char for char in value if char.isdigit()]
|
| 246 |
-
)
|
| 247 |
-
value = (
|
| 248 |
-
str(datetime.now().year)[: (8 - len(value))] + value
|
| 249 |
-
)
|
| 250 |
-
replace = replace.replace(key, value)
|
| 251 |
-
break
|
| 252 |
-
# 非正则类替换变量
|
| 253 |
-
if key == "{TASKNAME}":
|
| 254 |
-
replace = replace.replace(key, self.magic_variable["{TASKNAME}"])
|
| 255 |
-
elif key == "{SXX}" and not match:
|
| 256 |
-
replace = replace.replace(key, "S01")
|
| 257 |
-
elif key == "{I}":
|
| 258 |
-
continue
|
| 259 |
-
else:
|
| 260 |
-
# 清理未匹配的 magic_variable key
|
| 261 |
-
replace = replace.replace(key, "")
|
| 262 |
-
if pattern and replace:
|
| 263 |
-
file_name = re.sub(pattern, replace, file_name)
|
| 264 |
-
else:
|
| 265 |
-
file_name = replace
|
| 266 |
-
return file_name
|
| 267 |
-
|
| 268 |
-
def _custom_sort_key(self, name):
|
| 269 |
-
"""自定义排序键"""
|
| 270 |
-
for i, keyword in enumerate(self.priority_list):
|
| 271 |
-
if keyword in name:
|
| 272 |
-
name = name.replace(keyword, f"_{i:02d}_") # 替换为数字,方便排序
|
| 273 |
-
return name
|
| 274 |
-
|
| 275 |
-
def sort_file_list(self, file_list, dir_filename_dict={}):
|
| 276 |
-
"""文件列表统一排序,给{I+}赋值"""
|
| 277 |
-
filename_list = [
|
| 278 |
-
# 强制加入`文件修改时间`字段供排序,效果:1无可排序字符时则按修改时间排序,2和目录已有文件重名时始终在其后
|
| 279 |
-
f"{f['file_name_re']}_{f['updated_at']}"
|
| 280 |
-
for f in file_list
|
| 281 |
-
if f.get("file_name_re") and not f["dir"]
|
| 282 |
-
]
|
| 283 |
-
# print(f"filename_list_before: {filename_list}")
|
| 284 |
-
dir_filename_dict = dir_filename_dict or self.dir_filename_dict
|
| 285 |
-
# print(f"dir_filename_list: {dir_filename_list}")
|
| 286 |
-
# 合并目录文件列表
|
| 287 |
-
filename_list = list(set(filename_list) | set(dir_filename_dict.values()))
|
| 288 |
-
filename_list = natsorted(filename_list, key=self._custom_sort_key)
|
| 289 |
-
filename_index = {}
|
| 290 |
-
for name in filename_list:
|
| 291 |
-
if name in dir_filename_dict.values():
|
| 292 |
-
continue
|
| 293 |
-
i = filename_list.index(name) + 1
|
| 294 |
-
while i in dir_filename_dict.keys():
|
| 295 |
-
i += 1
|
| 296 |
-
dir_filename_dict[i] = name
|
| 297 |
-
filename_index[name] = i
|
| 298 |
-
for file in file_list:
|
| 299 |
-
if file.get("file_name_re"):
|
| 300 |
-
if match := re.search(r"\{I+\}", file["file_name_re"]):
|
| 301 |
-
i = filename_index.get(
|
| 302 |
-
f"{file['file_name_re']}_{file['updated_at']}", 0
|
| 303 |
-
)
|
| 304 |
-
file["file_name_re"] = re.sub(
|
| 305 |
-
match.group(),
|
| 306 |
-
str(i).zfill(match.group().count("I")),
|
| 307 |
-
file["file_name_re"],
|
| 308 |
-
)
|
| 309 |
-
|
| 310 |
-
def set_dir_file_list(self, file_list, replace):
|
| 311 |
-
"""设置目录文件列表"""
|
| 312 |
-
self.dir_filename_dict = {}
|
| 313 |
-
filename_list = [f["file_name"] for f in file_list if not f["dir"]]
|
| 314 |
-
filename_list.sort()
|
| 315 |
-
if not filename_list:
|
| 316 |
-
return
|
| 317 |
-
if match := re.search(r"\{I+\}", replace):
|
| 318 |
-
# 由替换式转换匹配式
|
| 319 |
-
magic_i = match.group()
|
| 320 |
-
pattern_i = r"\d" * magic_i.count("I")
|
| 321 |
-
pattern = replace.replace(match.group(), "🔢")
|
| 322 |
-
for key, _ in self.magic_variable.items():
|
| 323 |
-
if key in pattern:
|
| 324 |
-
pattern = pattern.replace(key, "🔣")
|
| 325 |
-
pattern = re.sub(r"\\[0-9]+", "🔣", pattern) # \1 \2 \3
|
| 326 |
-
pattern = f"({re.escape(pattern).replace('🔣', '.*?').replace('🔢', f')({pattern_i})(')})"
|
| 327 |
-
# print(f"pattern: {pattern}")
|
| 328 |
-
# 获取起始编号
|
| 329 |
-
if match := re.match(pattern, filename_list[-1]):
|
| 330 |
-
self.magic_variable["{I}"] = int(match.group(2))
|
| 331 |
-
# 目录文件列表
|
| 332 |
-
for filename in filename_list:
|
| 333 |
-
if match := re.match(pattern, filename):
|
| 334 |
-
self.dir_filename_dict[int(match.group(2))] = (
|
| 335 |
-
match.group(1) + magic_i + match.group(3)
|
| 336 |
-
)
|
| 337 |
-
# print(f"filename_list: {self.filename_list}")
|
| 338 |
-
|
| 339 |
-
def is_exists(self, filename, filename_list, ignore_ext=False):
|
| 340 |
-
"""判断文件是否存在,处理忽略扩展名"""
|
| 341 |
-
# print(f"filename: {filename} filename_list: {filename_list}")
|
| 342 |
-
if ignore_ext:
|
| 343 |
-
filename = os.path.splitext(filename)[0]
|
| 344 |
-
filename_list = [os.path.splitext(f)[0] for f in filename_list]
|
| 345 |
-
# {I+} 模式,用I通配数字序号
|
| 346 |
-
if match := re.search(r"\{I+\}", filename):
|
| 347 |
-
magic_i = match.group()
|
| 348 |
-
pattern_i = r"\d" * magic_i.count("I")
|
| 349 |
-
pattern = re.escape(filename).replace(re.escape(magic_i), pattern_i)
|
| 350 |
-
for filename in filename_list:
|
| 351 |
-
if re.match(pattern, filename):
|
| 352 |
-
return filename
|
| 353 |
-
return None
|
| 354 |
-
else:
|
| 355 |
-
return filename if filename in filename_list else None
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
class Quark:
|
| 359 |
-
BASE_URL = "https://drive-pc.quark.cn"
|
| 360 |
-
BASE_URL_APP = "https://drive-m.quark.cn"
|
| 361 |
-
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) quark-cloud-drive/3.14.2 Chrome/112.0.5615.165 Electron/24.1.3.8 Safari/537.36 Channel/pckk_other_ch"
|
| 362 |
-
|
| 363 |
-
def __init__(self, cookie="", index=0):
|
| 364 |
-
self.cookie = cookie.strip()
|
| 365 |
-
self.index = index + 1
|
| 366 |
-
self.is_active = False
|
| 367 |
-
self.nickname = ""
|
| 368 |
-
self.mparam = self._match_mparam_form_cookie(cookie)
|
| 369 |
-
self.savepath_fid = {"/": "0"}
|
| 370 |
-
|
| 371 |
-
def _match_mparam_form_cookie(self, cookie):
|
| 372 |
-
mparam = {}
|
| 373 |
-
kps_match = re.search(r"(?<!\w)kps=([a-zA-Z0-9%+/=]+)[;&]?", cookie)
|
| 374 |
-
sign_match = re.search(r"(?<!\w)sign=([a-zA-Z0-9%+/=]+)[;&]?", cookie)
|
| 375 |
-
vcode_match = re.search(r"(?<!\w)vcode=([a-zA-Z0-9%+/=]+)[;&]?", cookie)
|
| 376 |
-
if kps_match and sign_match and vcode_match:
|
| 377 |
-
mparam = {
|
| 378 |
-
"kps": kps_match.group(1).replace("%25", "%"),
|
| 379 |
-
"sign": sign_match.group(1).replace("%25", "%"),
|
| 380 |
-
"vcode": vcode_match.group(1).replace("%25", "%"),
|
| 381 |
-
}
|
| 382 |
-
return mparam
|
| 383 |
-
|
| 384 |
-
def _send_request(self, method, url, **kwargs):
|
| 385 |
-
headers = {
|
| 386 |
-
"cookie": self.cookie,
|
| 387 |
-
"content-type": "application/json",
|
| 388 |
-
"user-agent": self.USER_AGENT,
|
| 389 |
-
}
|
| 390 |
-
if "headers" in kwargs:
|
| 391 |
-
headers = kwargs["headers"]
|
| 392 |
-
del kwargs["headers"]
|
| 393 |
-
if self.mparam and "share" in url and self.BASE_URL in url:
|
| 394 |
-
url = url.replace(self.BASE_URL, self.BASE_URL_APP)
|
| 395 |
-
kwargs["params"].update(
|
| 396 |
-
{
|
| 397 |
-
"device_model": "M2011K2C",
|
| 398 |
-
"entry": "default_clouddrive",
|
| 399 |
-
"_t_group": "0%3A_s_vp%3A1",
|
| 400 |
-
"dmn": "Mi%2B11",
|
| 401 |
-
"fr": "android",
|
| 402 |
-
"pf": "3300",
|
| 403 |
-
"bi": "35937",
|
| 404 |
-
"ve": "7.4.5.680",
|
| 405 |
-
"ss": "411x875",
|
| 406 |
-
"mi": "M2011K2C",
|
| 407 |
-
"nt": "5",
|
| 408 |
-
"nw": "0",
|
| 409 |
-
"kt": "4",
|
| 410 |
-
"pr": "ucpro",
|
| 411 |
-
"sv": "release",
|
| 412 |
-
"dt": "phone",
|
| 413 |
-
"data_from": "ucapi",
|
| 414 |
-
"kps": self.mparam.get("kps"),
|
| 415 |
-
"sign": self.mparam.get("sign"),
|
| 416 |
-
"vcode": self.mparam.get("vcode"),
|
| 417 |
-
"app": "clouddrive",
|
| 418 |
-
"kkkk": "1",
|
| 419 |
-
}
|
| 420 |
-
)
|
| 421 |
-
del headers["cookie"]
|
| 422 |
-
try:
|
| 423 |
-
response = requests.request(method, url, headers=headers, **kwargs)
|
| 424 |
-
# print(f"{response.text}")
|
| 425 |
-
# response.raise_for_status() # 检查请求是否成功,但返回非200也会抛出异常
|
| 426 |
-
return response
|
| 427 |
-
except Exception as e:
|
| 428 |
-
print(f"_send_request error:\n{e}")
|
| 429 |
-
fake_response = requests.Response()
|
| 430 |
-
fake_response.status_code = 500
|
| 431 |
-
fake_response._content = (
|
| 432 |
-
b'{"status": 500, "code": 1, "message": "request error"}'
|
| 433 |
-
)
|
| 434 |
-
return fake_response
|
| 435 |
-
|
| 436 |
-
def init(self):
|
| 437 |
-
account_info = self.get_account_info()
|
| 438 |
-
if account_info:
|
| 439 |
-
self.is_active = True
|
| 440 |
-
self.nickname = account_info["nickname"]
|
| 441 |
-
return account_info
|
| 442 |
-
else:
|
| 443 |
-
return False
|
| 444 |
-
|
| 445 |
-
def get_account_info(self):
|
| 446 |
-
url = "https://pan.quark.cn/account/info"
|
| 447 |
-
querystring = {"fr": "pc", "platform": "pc"}
|
| 448 |
-
response = self._send_request("GET", url, params=querystring).json()
|
| 449 |
-
if response.get("data"):
|
| 450 |
-
return response["data"]
|
| 451 |
-
else:
|
| 452 |
-
return False
|
| 453 |
-
|
| 454 |
-
def get_growth_info(self):
|
| 455 |
-
url = f"{self.BASE_URL_APP}/1/clouddrive/capacity/growth/info"
|
| 456 |
-
querystring = {
|
| 457 |
-
"pr": "ucpro",
|
| 458 |
-
"fr": "android",
|
| 459 |
-
"kps": self.mparam.get("kps"),
|
| 460 |
-
"sign": self.mparam.get("sign"),
|
| 461 |
-
"vcode": self.mparam.get("vcode"),
|
| 462 |
-
}
|
| 463 |
-
headers = {
|
| 464 |
-
"content-type": "application/json",
|
| 465 |
-
}
|
| 466 |
-
response = self._send_request(
|
| 467 |
-
"GET", url, headers=headers, params=querystring
|
| 468 |
-
).json()
|
| 469 |
-
if response.get("data"):
|
| 470 |
-
return response["data"]
|
| 471 |
-
else:
|
| 472 |
-
return False
|
| 473 |
-
|
| 474 |
-
def get_growth_sign(self):
|
| 475 |
-
url = f"{self.BASE_URL_APP}/1/clouddrive/capacity/growth/sign"
|
| 476 |
-
querystring = {
|
| 477 |
-
"pr": "ucpro",
|
| 478 |
-
"fr": "android",
|
| 479 |
-
"kps": self.mparam.get("kps"),
|
| 480 |
-
"sign": self.mparam.get("sign"),
|
| 481 |
-
"vcode": self.mparam.get("vcode"),
|
| 482 |
-
}
|
| 483 |
-
payload = {
|
| 484 |
-
"sign_cyclic": True,
|
| 485 |
-
}
|
| 486 |
-
headers = {
|
| 487 |
-
"content-type": "application/json",
|
| 488 |
-
}
|
| 489 |
-
response = self._send_request(
|
| 490 |
-
"POST", url, json=payload, headers=headers, params=querystring
|
| 491 |
-
).json()
|
| 492 |
-
if response.get("data"):
|
| 493 |
-
return True, response["data"]["sign_daily_reward"]
|
| 494 |
-
else:
|
| 495 |
-
return False, response["message"]
|
| 496 |
-
|
| 497 |
-
# 可验证资源是否失效
|
| 498 |
-
def get_stoken(self, pwd_id, passcode=""):
|
| 499 |
-
url = f"{self.BASE_URL}/1/clouddrive/share/sharepage/token"
|
| 500 |
-
querystring = {"pr": "ucpro", "fr": "pc"}
|
| 501 |
-
payload = {"pwd_id": pwd_id, "passcode": passcode}
|
| 502 |
-
response = self._send_request(
|
| 503 |
-
"POST", url, json=payload, params=querystring
|
| 504 |
-
).json()
|
| 505 |
-
return response
|
| 506 |
-
|
| 507 |
-
def get_detail(
|
| 508 |
-
self, pwd_id, stoken, pdir_fid, _fetch_share=0, fetch_share_full_path=0
|
| 509 |
-
):
|
| 510 |
-
list_merge = []
|
| 511 |
-
page = 1
|
| 512 |
-
while True:
|
| 513 |
-
url = f"{self.BASE_URL}/1/clouddrive/share/sharepage/detail"
|
| 514 |
-
querystring = {
|
| 515 |
-
"pr": "ucpro",
|
| 516 |
-
"fr": "pc",
|
| 517 |
-
"pwd_id": pwd_id,
|
| 518 |
-
"stoken": stoken,
|
| 519 |
-
"pdir_fid": pdir_fid,
|
| 520 |
-
"force": "0",
|
| 521 |
-
"_page": page,
|
| 522 |
-
"_size": "50",
|
| 523 |
-
"_fetch_banner": "0",
|
| 524 |
-
"_fetch_share": _fetch_share,
|
| 525 |
-
"_fetch_total": "1",
|
| 526 |
-
"_sort": "file_type:asc,updated_at:desc",
|
| 527 |
-
"ver": "2",
|
| 528 |
-
"fetch_share_full_path": fetch_share_full_path,
|
| 529 |
-
}
|
| 530 |
-
response = self._send_request("GET", url, params=querystring).json()
|
| 531 |
-
if response["code"] != 0:
|
| 532 |
-
return response
|
| 533 |
-
if response["data"]["list"]:
|
| 534 |
-
list_merge += response["data"]["list"]
|
| 535 |
-
page += 1
|
| 536 |
-
else:
|
| 537 |
-
break
|
| 538 |
-
if len(list_merge) >= response["metadata"]["_total"]:
|
| 539 |
-
break
|
| 540 |
-
response["data"]["list"] = list_merge
|
| 541 |
-
return response
|
| 542 |
-
|
| 543 |
-
def get_fids(self, file_paths):
|
| 544 |
-
fids = []
|
| 545 |
-
while True:
|
| 546 |
-
url = f"{self.BASE_URL}/1/clouddrive/file/info/path_list"
|
| 547 |
-
querystring = {"pr": "ucpro", "fr": "pc"}
|
| 548 |
-
payload = {"file_path": file_paths[:50], "namespace": "0"}
|
| 549 |
-
response = self._send_request(
|
| 550 |
-
"POST", url, json=payload, params=querystring
|
| 551 |
-
).json()
|
| 552 |
-
if response["code"] == 0:
|
| 553 |
-
fids += response["data"]
|
| 554 |
-
file_paths = file_paths[50:]
|
| 555 |
-
else:
|
| 556 |
-
print(f"获取目录ID:失败, {response['message']}")
|
| 557 |
-
break
|
| 558 |
-
if len(file_paths) == 0:
|
| 559 |
-
break
|
| 560 |
-
return fids
|
| 561 |
-
|
| 562 |
-
def ls_dir(self, pdir_fid, **kwargs):
|
| 563 |
-
list_merge = []
|
| 564 |
-
page = 1
|
| 565 |
-
while True:
|
| 566 |
-
url = f"{self.BASE_URL}/1/clouddrive/file/sort"
|
| 567 |
-
querystring = {
|
| 568 |
-
"pr": "ucpro",
|
| 569 |
-
"fr": "pc",
|
| 570 |
-
"uc_param_str": "",
|
| 571 |
-
"pdir_fid": pdir_fid,
|
| 572 |
-
"_page": page,
|
| 573 |
-
"_size": "50",
|
| 574 |
-
"_fetch_total": "1",
|
| 575 |
-
"_fetch_sub_dirs": "0",
|
| 576 |
-
"_sort": "file_type:asc,updated_at:desc",
|
| 577 |
-
"_fetch_full_path": kwargs.get("fetch_full_path", 0),
|
| 578 |
-
"fetch_all_file": 1, # 跟随Web端,作用未知
|
| 579 |
-
"fetch_risk_file_name": 1, # 如无此参数,违规文件名会被变 ***
|
| 580 |
-
}
|
| 581 |
-
response = self._send_request("GET", url, params=querystring).json()
|
| 582 |
-
if response["code"] != 0:
|
| 583 |
-
return response
|
| 584 |
-
if response["data"]["list"]:
|
| 585 |
-
list_merge += response["data"]["list"]
|
| 586 |
-
page += 1
|
| 587 |
-
else:
|
| 588 |
-
break
|
| 589 |
-
if len(list_merge) >= response["metadata"]["_total"]:
|
| 590 |
-
break
|
| 591 |
-
response["data"]["list"] = list_merge
|
| 592 |
-
return response
|
| 593 |
-
|
| 594 |
-
def save_file(self, fid_list, fid_token_list, to_pdir_fid, pwd_id, stoken):
|
| 595 |
-
url = f"{self.BASE_URL}/1/clouddrive/share/sharepage/save"
|
| 596 |
-
querystring = {
|
| 597 |
-
"pr": "ucpro",
|
| 598 |
-
"fr": "pc",
|
| 599 |
-
"uc_param_str": "",
|
| 600 |
-
"app": "clouddrive",
|
| 601 |
-
"__dt": int(random.uniform(1, 5) * 60 * 1000),
|
| 602 |
-
"__t": datetime.now().timestamp(),
|
| 603 |
-
}
|
| 604 |
-
payload = {
|
| 605 |
-
"fid_list": fid_list,
|
| 606 |
-
"fid_token_list": fid_token_list,
|
| 607 |
-
"to_pdir_fid": to_pdir_fid,
|
| 608 |
-
"pwd_id": pwd_id,
|
| 609 |
-
"stoken": stoken,
|
| 610 |
-
"pdir_fid": "0",
|
| 611 |
-
"scene": "link",
|
| 612 |
-
}
|
| 613 |
-
response = self._send_request(
|
| 614 |
-
"POST", url, json=payload, params=querystring
|
| 615 |
-
).json()
|
| 616 |
-
return response
|
| 617 |
-
|
| 618 |
-
def query_task(self, task_id):
|
| 619 |
-
retry_index = 0
|
| 620 |
-
while True:
|
| 621 |
-
url = f"{self.BASE_URL}/1/clouddrive/task"
|
| 622 |
-
querystring = {
|
| 623 |
-
"pr": "ucpro",
|
| 624 |
-
"fr": "pc",
|
| 625 |
-
"uc_param_str": "",
|
| 626 |
-
"task_id": task_id,
|
| 627 |
-
"retry_index": retry_index,
|
| 628 |
-
"__dt": int(random.uniform(1, 5) * 60 * 1000),
|
| 629 |
-
"__t": datetime.now().timestamp(),
|
| 630 |
-
}
|
| 631 |
-
response = self._send_request("GET", url, params=querystring).json()
|
| 632 |
-
if response["status"] != 200:
|
| 633 |
-
return response
|
| 634 |
-
if response["data"]["status"] == 2:
|
| 635 |
-
if retry_index > 0:
|
| 636 |
-
print()
|
| 637 |
-
break
|
| 638 |
-
else:
|
| 639 |
-
if retry_index == 0:
|
| 640 |
-
print(
|
| 641 |
-
f"正在等待[{response['data']['task_title']}]执行结果",
|
| 642 |
-
end="",
|
| 643 |
-
flush=True,
|
| 644 |
-
)
|
| 645 |
-
else:
|
| 646 |
-
print(".", end="", flush=True)
|
| 647 |
-
retry_index += 1
|
| 648 |
-
time.sleep(0.500)
|
| 649 |
-
return response
|
| 650 |
-
|
| 651 |
-
def download(self, fids):
|
| 652 |
-
url = f"{self.BASE_URL}/1/clouddrive/file/download"
|
| 653 |
-
querystring = {"pr": "ucpro", "fr": "pc", "uc_param_str": ""}
|
| 654 |
-
payload = {"fids": fids}
|
| 655 |
-
response = self._send_request("POST", url, json=payload, params=querystring)
|
| 656 |
-
set_cookie = response.cookies.get_dict()
|
| 657 |
-
cookie_str = "; ".join([f"{key}={value}" for key, value in set_cookie.items()])
|
| 658 |
-
return response.json(), cookie_str
|
| 659 |
-
|
| 660 |
-
def mkdir(self, dir_path):
|
| 661 |
-
url = f"{self.BASE_URL}/1/clouddrive/file"
|
| 662 |
-
querystring = {"pr": "ucpro", "fr": "pc", "uc_param_str": ""}
|
| 663 |
-
payload = {
|
| 664 |
-
"pdir_fid": "0",
|
| 665 |
-
"file_name": "",
|
| 666 |
-
"dir_path": dir_path,
|
| 667 |
-
"dir_init_lock": False,
|
| 668 |
-
}
|
| 669 |
-
response = self._send_request(
|
| 670 |
-
"POST", url, json=payload, params=querystring
|
| 671 |
-
).json()
|
| 672 |
-
return response
|
| 673 |
-
|
| 674 |
-
def rename(self, fid, file_name):
|
| 675 |
-
url = f"{self.BASE_URL}/1/clouddrive/file/rename"
|
| 676 |
-
querystring = {"pr": "ucpro", "fr": "pc", "uc_param_str": ""}
|
| 677 |
-
payload = {"fid": fid, "file_name": file_name}
|
| 678 |
-
response = self._send_request(
|
| 679 |
-
"POST", url, json=payload, params=querystring
|
| 680 |
-
).json()
|
| 681 |
-
return response
|
| 682 |
-
|
| 683 |
-
def delete(self, filelist):
|
| 684 |
-
url = f"{self.BASE_URL}/1/clouddrive/file/delete"
|
| 685 |
-
querystring = {"pr": "ucpro", "fr": "pc", "uc_param_str": ""}
|
| 686 |
-
payload = {"action_type": 2, "filelist": filelist, "exclude_fids": []}
|
| 687 |
-
response = self._send_request(
|
| 688 |
-
"POST", url, json=payload, params=querystring
|
| 689 |
-
).json()
|
| 690 |
-
return response
|
| 691 |
-
|
| 692 |
-
def recycle_list(self, page=1, size=30):
|
| 693 |
-
url = f"{self.BASE_URL}/1/clouddrive/file/recycle/list"
|
| 694 |
-
querystring = {
|
| 695 |
-
"_page": page,
|
| 696 |
-
"_size": size,
|
| 697 |
-
"pr": "ucpro",
|
| 698 |
-
"fr": "pc",
|
| 699 |
-
"uc_param_str": "",
|
| 700 |
-
}
|
| 701 |
-
response = self._send_request("GET", url, params=querystring).json()
|
| 702 |
-
return response["data"]["list"]
|
| 703 |
-
|
| 704 |
-
def recycle_remove(self, record_list):
|
| 705 |
-
url = f"{self.BASE_URL}/1/clouddrive/file/recycle/remove"
|
| 706 |
-
querystring = {"uc_param_str": "", "fr": "pc", "pr": "ucpro"}
|
| 707 |
-
payload = {
|
| 708 |
-
"select_mode": 2,
|
| 709 |
-
"record_list": record_list,
|
| 710 |
-
}
|
| 711 |
-
response = self._send_request(
|
| 712 |
-
"POST", url, json=payload, params=querystring
|
| 713 |
-
).json()
|
| 714 |
-
return response
|
| 715 |
-
|
| 716 |
-
# ↑ 请求函数
|
| 717 |
-
# ↓ 操作函数
|
| 718 |
-
|
| 719 |
-
def extract_url(self, url):
|
| 720 |
-
# pwd_id
|
| 721 |
-
match_id = re.search(r"/s/(\w+)", url)
|
| 722 |
-
pwd_id = match_id.group(1) if match_id else None
|
| 723 |
-
# passcode
|
| 724 |
-
match_pwd = re.search(r"pwd=(\w+)", url)
|
| 725 |
-
passcode = match_pwd.group(1) if match_pwd else ""
|
| 726 |
-
# path: fid-name
|
| 727 |
-
# Legacy 20250905
|
| 728 |
-
paths = []
|
| 729 |
-
matches = re.findall(r"/(\w{32})-?([^/]+)?", url)
|
| 730 |
-
for match in matches:
|
| 731 |
-
fid = match[0]
|
| 732 |
-
name = urllib.parse.unquote(match[1]).replace("*101", "-")
|
| 733 |
-
paths.append({"fid": fid, "name": name})
|
| 734 |
-
pdir_fid = paths[-1]["fid"] if matches else 0
|
| 735 |
-
return pwd_id, passcode, pdir_fid, paths
|
| 736 |
-
|
| 737 |
-
def update_savepath_fid(self, tasklist):
|
| 738 |
-
dir_paths = [
|
| 739 |
-
re.sub(r"/{2,}", "/", f"/{item['savepath']}")
|
| 740 |
-
for item in tasklist
|
| 741 |
-
if not item.get("enddate")
|
| 742 |
-
or (
|
| 743 |
-
datetime.now().date()
|
| 744 |
-
<= datetime.strptime(item["enddate"], "%Y-%m-%d").date()
|
| 745 |
-
)
|
| 746 |
-
]
|
| 747 |
-
if not dir_paths:
|
| 748 |
-
return False
|
| 749 |
-
dir_paths_exist_arr = self.get_fids(dir_paths)
|
| 750 |
-
dir_paths_exist = [item["file_path"] for item in dir_paths_exist_arr]
|
| 751 |
-
# 比较创建不存在的
|
| 752 |
-
dir_paths_unexist = list(set(dir_paths) - set(dir_paths_exist) - set(["/"]))
|
| 753 |
-
for dir_path in dir_paths_unexist:
|
| 754 |
-
mkdir_return = self.mkdir(dir_path)
|
| 755 |
-
if mkdir_return["code"] == 0:
|
| 756 |
-
new_dir = mkdir_return["data"]
|
| 757 |
-
dir_paths_exist_arr.append(
|
| 758 |
-
{"file_path": dir_path, "fid": new_dir["fid"]}
|
| 759 |
-
)
|
| 760 |
-
print(f"创建文件夹:{dir_path}")
|
| 761 |
-
else:
|
| 762 |
-
print(f"创建文件夹:{dir_path} 失败, {mkdir_return['message']}")
|
| 763 |
-
# 储存目标目录的fid
|
| 764 |
-
for dir_path in dir_paths_exist_arr:
|
| 765 |
-
self.savepath_fid[dir_path["file_path"]] = dir_path["fid"]
|
| 766 |
-
# print(dir_paths_exist_arr)
|
| 767 |
-
|
| 768 |
-
def do_save_check(self, shareurl, savepath):
|
| 769 |
-
try:
|
| 770 |
-
pwd_id, passcode, pdir_fid, _ = self.extract_url(shareurl)
|
| 771 |
-
stoken = self.get_stoken(pwd_id, passcode)["data"]["stoken"]
|
| 772 |
-
share_file_list = self.get_detail(pwd_id, stoken, pdir_fid)["data"]["list"]
|
| 773 |
-
print(f"获取分享: {share_file_list}")
|
| 774 |
-
fid_list = [item["fid"] for item in share_file_list]
|
| 775 |
-
fid_token_list = [item["share_fid_token"] for item in share_file_list]
|
| 776 |
-
get_fids = self.get_fids([savepath])
|
| 777 |
-
to_pdir_fid = (
|
| 778 |
-
get_fids[0]["fid"] if get_fids else self.mkdir(savepath)["data"]["fid"]
|
| 779 |
-
)
|
| 780 |
-
save_file = self.save_file(
|
| 781 |
-
fid_list, fid_token_list, to_pdir_fid, pwd_id, stoken
|
| 782 |
-
)
|
| 783 |
-
print(f"转存文件: {save_file}")
|
| 784 |
-
if save_file["code"] == 0:
|
| 785 |
-
task_id = save_file["data"]["task_id"]
|
| 786 |
-
query_task = self.query_task(task_id)
|
| 787 |
-
print(f"查询转存: {query_task}")
|
| 788 |
-
if query_task["code"] == 0:
|
| 789 |
-
del_list = query_task["data"]["save_as"]["save_as_top_fids"]
|
| 790 |
-
if del_list:
|
| 791 |
-
delete_return = self.delete(del_list)
|
| 792 |
-
print(f"删除转存: {delete_return}")
|
| 793 |
-
recycle_list = self.recycle_list()
|
| 794 |
-
record_id_list = [
|
| 795 |
-
item["record_id"]
|
| 796 |
-
for item in recycle_list
|
| 797 |
-
if item["fid"] in del_list
|
| 798 |
-
]
|
| 799 |
-
recycle_remove = self.recycle_remove(record_id_list)
|
| 800 |
-
print(f"清理转存: {recycle_remove}")
|
| 801 |
-
print(f"✅ 转存测试成功")
|
| 802 |
-
return True
|
| 803 |
-
print(f"❌ 转存测试失败: 中断")
|
| 804 |
-
return False
|
| 805 |
-
except Exception as e:
|
| 806 |
-
print(f"❌ 转存测试失败: {str(e)}")
|
| 807 |
-
traceback.print_exc()
|
| 808 |
-
|
| 809 |
-
def do_save_task(self, task):
|
| 810 |
-
# 判断资源失效记录
|
| 811 |
-
if task.get("shareurl_ban"):
|
| 812 |
-
print(f"《{task['taskname']}》:{task['shareurl_ban']}")
|
| 813 |
-
return
|
| 814 |
-
|
| 815 |
-
# 链接转换所需参数
|
| 816 |
-
pwd_id, passcode, pdir_fid, _ = self.extract_url(task["shareurl"])
|
| 817 |
-
|
| 818 |
-
# 获取stoken,同时可验证资源是否失效
|
| 819 |
-
get_stoken = self.get_stoken(pwd_id, passcode)
|
| 820 |
-
if get_stoken.get("status") == 200:
|
| 821 |
-
stoken = get_stoken["data"]["stoken"]
|
| 822 |
-
elif get_stoken.get("status") == 500:
|
| 823 |
-
print(f"跳过任务:网络异常 {get_stoken.get('message')}")
|
| 824 |
-
return
|
| 825 |
-
else:
|
| 826 |
-
message = get_stoken.get("message")
|
| 827 |
-
add_notify(f"❌《{task['taskname']}》:{message}\n")
|
| 828 |
-
task["shareurl_ban"] = message
|
| 829 |
-
return
|
| 830 |
-
# print("stoken: ", stoken)
|
| 831 |
-
|
| 832 |
-
updated_tree = self.dir_check_and_save(task, pwd_id, stoken, pdir_fid)
|
| 833 |
-
if updated_tree.size(1) > 0:
|
| 834 |
-
self.do_rename(updated_tree)
|
| 835 |
-
print()
|
| 836 |
-
add_notify(f"✅《{task['taskname']}》添加追更:\n{updated_tree}")
|
| 837 |
-
return updated_tree
|
| 838 |
-
else:
|
| 839 |
-
print(f"任务结束:没有新的转存任务")
|
| 840 |
-
return False
|
| 841 |
-
|
| 842 |
-
def dir_check_and_save(self, task, pwd_id, stoken, pdir_fid="", subdir_path=""):
|
| 843 |
-
tree = Tree()
|
| 844 |
-
# 获取分享文件列表
|
| 845 |
-
share_file_list = self.get_detail(pwd_id, stoken, pdir_fid)["data"]["list"]
|
| 846 |
-
# print("share_file_list: ", share_file_list)
|
| 847 |
-
|
| 848 |
-
if not share_file_list:
|
| 849 |
-
if subdir_path == "":
|
| 850 |
-
task["shareurl_ban"] = "分享为空,文件已被分享者删除"
|
| 851 |
-
add_notify(f"❌《{task['taskname']}》:{task['shareurl_ban']}\n")
|
| 852 |
-
return tree
|
| 853 |
-
elif (
|
| 854 |
-
len(share_file_list) == 1
|
| 855 |
-
and share_file_list[0]["dir"]
|
| 856 |
-
and subdir_path == ""
|
| 857 |
-
): # 仅有一个文件夹
|
| 858 |
-
print("🧠 该分享是一个文件夹,读取文件夹内列表")
|
| 859 |
-
share_file_list = self.get_detail(
|
| 860 |
-
pwd_id, stoken, share_file_list[0]["fid"]
|
| 861 |
-
)["data"]["list"]
|
| 862 |
-
|
| 863 |
-
# 获取目标目录文件列表
|
| 864 |
-
savepath = re.sub(r"/{2,}", "/", f"/{task['savepath']}{subdir_path}")
|
| 865 |
-
if not self.savepath_fid.get(savepath):
|
| 866 |
-
if get_fids := self.get_fids([savepath]):
|
| 867 |
-
self.savepath_fid[savepath] = get_fids[0]["fid"]
|
| 868 |
-
else:
|
| 869 |
-
print(f"❌ 目录 {savepath} fid获取失败,跳过转存")
|
| 870 |
-
return tree
|
| 871 |
-
to_pdir_fid = self.savepath_fid[savepath]
|
| 872 |
-
dir_file_list = self.ls_dir(to_pdir_fid)["data"]["list"]
|
| 873 |
-
dir_filename_list = [dir_file["file_name"] for dir_file in dir_file_list]
|
| 874 |
-
# print("dir_file_list: ", dir_file_list)
|
| 875 |
-
|
| 876 |
-
tree.create_node(
|
| 877 |
-
savepath,
|
| 878 |
-
pdir_fid,
|
| 879 |
-
data={
|
| 880 |
-
"is_dir": True,
|
| 881 |
-
},
|
| 882 |
-
)
|
| 883 |
-
|
| 884 |
-
# 文件命名类
|
| 885 |
-
mr = MagicRename(CONFIG_DATA.get("magic_regex", {}))
|
| 886 |
-
mr.set_taskname(task["taskname"])
|
| 887 |
-
|
| 888 |
-
# 魔法正则转换
|
| 889 |
-
pattern, replace = mr.magic_regex_conv(
|
| 890 |
-
task.get("pattern", ""), task.get("replace", "")
|
| 891 |
-
)
|
| 892 |
-
# 需保存的文件清单
|
| 893 |
-
need_save_list = []
|
| 894 |
-
# 添加符合的
|
| 895 |
-
for share_file in share_file_list:
|
| 896 |
-
search_pattern = (
|
| 897 |
-
task["update_subdir"]
|
| 898 |
-
if share_file["dir"] and task.get("update_subdir")
|
| 899 |
-
else pattern
|
| 900 |
-
)
|
| 901 |
-
# 正则文件名匹配
|
| 902 |
-
if re.search(search_pattern, share_file["file_name"]):
|
| 903 |
-
# 判断原文件名是否存在,处理忽略扩展名
|
| 904 |
-
if not mr.is_exists(
|
| 905 |
-
share_file["file_name"],
|
| 906 |
-
dir_filename_list,
|
| 907 |
-
(task.get("ignore_extension") and not share_file["dir"]),
|
| 908 |
-
):
|
| 909 |
-
# 文件夹、子目录文件不进行重命名
|
| 910 |
-
if share_file["dir"] or subdir_path:
|
| 911 |
-
share_file["file_name_re"] = share_file["file_name"]
|
| 912 |
-
need_save_list.append(share_file)
|
| 913 |
-
else:
|
| 914 |
-
# 替换后的文件名
|
| 915 |
-
file_name_re = mr.sub(pattern, replace, share_file["file_name"])
|
| 916 |
-
# 判断替换后的文件名是否存在
|
| 917 |
-
if not mr.is_exists(
|
| 918 |
-
file_name_re,
|
| 919 |
-
dir_filename_list,
|
| 920 |
-
task.get("ignore_extension"),
|
| 921 |
-
):
|
| 922 |
-
share_file["file_name_re"] = file_name_re
|
| 923 |
-
need_save_list.append(share_file)
|
| 924 |
-
elif share_file["dir"]:
|
| 925 |
-
# 存在并是一个目录,历遍子目录
|
| 926 |
-
if task.get("update_subdir", False) and re.search(
|
| 927 |
-
task["update_subdir"], share_file["file_name"]
|
| 928 |
-
):
|
| 929 |
-
if task.get("update_subdir_resave_mode", False):
|
| 930 |
-
# 重存模式:删除该目录下所有文件,重新转存
|
| 931 |
-
print(f"重存子目录:{savepath}/{share_file['file_name']}")
|
| 932 |
-
# 删除子目录、回收站中彻底删除
|
| 933 |
-
subdir = next(
|
| 934 |
-
(
|
| 935 |
-
f
|
| 936 |
-
for f in dir_file_list
|
| 937 |
-
if f["file_name"] == share_file["file_name"]
|
| 938 |
-
),
|
| 939 |
-
None,
|
| 940 |
-
)
|
| 941 |
-
delete_return = self.delete([subdir["fid"]])
|
| 942 |
-
self.query_task(delete_return["data"]["task_id"])
|
| 943 |
-
recycle_list = self.recycle_list()
|
| 944 |
-
record_id_list = [
|
| 945 |
-
item["record_id"]
|
| 946 |
-
for item in recycle_list
|
| 947 |
-
if item["fid"] == subdir["fid"]
|
| 948 |
-
]
|
| 949 |
-
self.recycle_remove(record_id_list)
|
| 950 |
-
# 作为新文件添加到转存列表
|
| 951 |
-
share_file["file_name_re"] = share_file["file_name"]
|
| 952 |
-
need_save_list.append(share_file)
|
| 953 |
-
else:
|
| 954 |
-
# 递归模式
|
| 955 |
-
print(f"检查子目录:{savepath}/{share_file['file_name']}")
|
| 956 |
-
subdir_tree = self.dir_check_and_save(
|
| 957 |
-
task,
|
| 958 |
-
pwd_id,
|
| 959 |
-
stoken,
|
| 960 |
-
share_file["fid"],
|
| 961 |
-
f"{subdir_path}/{share_file['file_name']}",
|
| 962 |
-
)
|
| 963 |
-
if subdir_tree.size(1) > 0:
|
| 964 |
-
# 合并子目录树
|
| 965 |
-
tree.create_node(
|
| 966 |
-
"📁" + share_file["file_name"],
|
| 967 |
-
share_file["fid"],
|
| 968 |
-
parent=pdir_fid,
|
| 969 |
-
data={
|
| 970 |
-
"is_dir": share_file["dir"],
|
| 971 |
-
},
|
| 972 |
-
)
|
| 973 |
-
tree.merge(share_file["fid"], subdir_tree, deep=False)
|
| 974 |
-
# 指定文件开始订阅/到达指定文件(含)结束历遍
|
| 975 |
-
if share_file["fid"] == task.get("startfid", ""):
|
| 976 |
-
break
|
| 977 |
-
|
| 978 |
-
if re.search(r"\{I+\}", replace):
|
| 979 |
-
mr.set_dir_file_list(dir_file_list, replace)
|
| 980 |
-
mr.sort_file_list(need_save_list)
|
| 981 |
-
|
| 982 |
-
# 转存文件
|
| 983 |
-
fid_list = [item["fid"] for item in need_save_list]
|
| 984 |
-
fid_token_list = [item["share_fid_token"] for item in need_save_list]
|
| 985 |
-
if fid_list:
|
| 986 |
-
err_msg = None
|
| 987 |
-
save_as_top_fids = []
|
| 988 |
-
while fid_list:
|
| 989 |
-
# 分次转存,100个/次,因query_task返回save_as_top_fids最多100
|
| 990 |
-
save_file_return = self.save_file(
|
| 991 |
-
fid_list[:100], fid_token_list[:100], to_pdir_fid, pwd_id, stoken
|
| 992 |
-
)
|
| 993 |
-
fid_list = fid_list[100:]
|
| 994 |
-
fid_token_list = fid_token_list[100:]
|
| 995 |
-
if save_file_return["code"] == 0:
|
| 996 |
-
# 转存成功,查询转存结果
|
| 997 |
-
task_id = save_file_return["data"]["task_id"]
|
| 998 |
-
query_task_return = self.query_task(task_id)
|
| 999 |
-
if query_task_return["code"] == 0:
|
| 1000 |
-
save_as_top_fids.extend(
|
| 1001 |
-
query_task_return["data"]["save_as"]["save_as_top_fids"]
|
| 1002 |
-
)
|
| 1003 |
-
else:
|
| 1004 |
-
err_msg = query_task_return["message"]
|
| 1005 |
-
else:
|
| 1006 |
-
err_msg = save_file_return["message"]
|
| 1007 |
-
if err_msg:
|
| 1008 |
-
add_notify(f"❌《{task['taskname']}》转存失败:{err_msg}\n")
|
| 1009 |
-
# 建立目���树
|
| 1010 |
-
if len(need_save_list) == len(save_as_top_fids):
|
| 1011 |
-
for index, item in enumerate(need_save_list):
|
| 1012 |
-
icon = self._get_file_icon(item)
|
| 1013 |
-
tree.create_node(
|
| 1014 |
-
f"{icon}{item['file_name_re']}",
|
| 1015 |
-
item["fid"],
|
| 1016 |
-
parent=pdir_fid,
|
| 1017 |
-
data={
|
| 1018 |
-
"file_name": item["file_name"],
|
| 1019 |
-
"file_name_re": item["file_name_re"],
|
| 1020 |
-
"fid": f"{save_as_top_fids[index]}",
|
| 1021 |
-
"path": f"{savepath}/{item['file_name_re']}",
|
| 1022 |
-
"is_dir": item["dir"],
|
| 1023 |
-
"obj_category": item.get("obj_category", ""),
|
| 1024 |
-
},
|
| 1025 |
-
)
|
| 1026 |
-
return tree
|
| 1027 |
-
|
| 1028 |
-
def do_rename(self, tree, node_id=None):
|
| 1029 |
-
if node_id is None:
|
| 1030 |
-
node_id = tree.root
|
| 1031 |
-
for child in tree.children(node_id):
|
| 1032 |
-
file = child.data
|
| 1033 |
-
if file.get("is_dir"):
|
| 1034 |
-
# self.do_rename(tree, child.identifier)
|
| 1035 |
-
pass
|
| 1036 |
-
elif file.get("file_name_re") and file["file_name_re"] != file["file_name"]:
|
| 1037 |
-
rename_ret = self.rename(file["fid"], file["file_name_re"])
|
| 1038 |
-
print(f"重命名:{file['file_name']} → {file['file_name_re']}")
|
| 1039 |
-
if rename_ret["code"] != 0:
|
| 1040 |
-
print(f" ↑ 失败,{rename_ret['message']}")
|
| 1041 |
-
|
| 1042 |
-
def _get_file_icon(self, f):
|
| 1043 |
-
if f.get("dir"):
|
| 1044 |
-
return "📁"
|
| 1045 |
-
ico_maps = {
|
| 1046 |
-
"video": "🎞️",
|
| 1047 |
-
"image": "🖼️",
|
| 1048 |
-
"audio": "🎵",
|
| 1049 |
-
"doc": "📄",
|
| 1050 |
-
"archive": "📦",
|
| 1051 |
-
"default": "",
|
| 1052 |
-
}
|
| 1053 |
-
return ico_maps.get(f.get("obj_category"), "")
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
def verify_account(account):
|
| 1057 |
-
# 验证账号
|
| 1058 |
-
print(f"▶️ 验证第{account.index}个账号")
|
| 1059 |
-
if "__uid" not in account.cookie:
|
| 1060 |
-
print(f"💡 不存在cookie必要参数,判断为仅签到")
|
| 1061 |
-
return False
|
| 1062 |
-
else:
|
| 1063 |
-
account_info = account.init()
|
| 1064 |
-
if not account_info:
|
| 1065 |
-
add_notify(f"👤 第{account.index}个账号登录失败,cookie无效❌")
|
| 1066 |
-
return False
|
| 1067 |
-
else:
|
| 1068 |
-
print(f"👤 账号昵称: {account_info['nickname']}✅")
|
| 1069 |
-
return True
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
def format_bytes(size_bytes: int) -> str:
|
| 1073 |
-
units = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
|
| 1074 |
-
i = 0
|
| 1075 |
-
while size_bytes >= 1024 and i < len(units) - 1:
|
| 1076 |
-
size_bytes /= 1024
|
| 1077 |
-
i += 1
|
| 1078 |
-
return f"{size_bytes:.2f} {units[i]}"
|
| 1079 |
-
|
| 1080 |
-
|
| 1081 |
-
def do_sign(account):
|
| 1082 |
-
if not account.mparam:
|
| 1083 |
-
print("⏭️ 移动端参数未设置,跳过签到")
|
| 1084 |
-
print()
|
| 1085 |
-
return
|
| 1086 |
-
# 每日领空间
|
| 1087 |
-
growth_info = account.get_growth_info()
|
| 1088 |
-
if growth_info:
|
| 1089 |
-
VIP_MAP = {
|
| 1090 |
-
"NORMAL": "普通用户",
|
| 1091 |
-
"EXP_SVIP": "88VIP",
|
| 1092 |
-
"SUPER_VIP": "SVIP",
|
| 1093 |
-
"Z_VIP": "SVIP+",
|
| 1094 |
-
}
|
| 1095 |
-
growth_message = f"💾 {VIP_MAP.get(growth_info['member_type'], growth_info['member_type'])} 总空间:{format_bytes(growth_info['total_capacity'])},签到累计获得:{format_bytes(growth_info['cap_composition'].get('sign_reward', 0))}"
|
| 1096 |
-
if growth_info["cap_sign"]["sign_daily"]:
|
| 1097 |
-
sign_message = f"📅 签到记录: 今日已签到+{int(growth_info['cap_sign']['sign_daily_reward']/1024/1024)}MB,连签进度({growth_info['cap_sign']['sign_progress']}/{growth_info['cap_sign']['sign_target']})✅"
|
| 1098 |
-
message = f"{sign_message}\n{growth_message}"
|
| 1099 |
-
print(message)
|
| 1100 |
-
else:
|
| 1101 |
-
sign, sign_return = account.get_growth_sign()
|
| 1102 |
-
if sign:
|
| 1103 |
-
sign_message = f"📅 执行签到: 今日签到+{int(sign_return/1024/1024)}MB,连签进度({growth_info['cap_sign']['sign_progress']+1}/{growth_info['cap_sign']['sign_target']})✅"
|
| 1104 |
-
message = f"{sign_message}\n{growth_message}"
|
| 1105 |
-
if (
|
| 1106 |
-
str(
|
| 1107 |
-
CONFIG_DATA.get("push_config", {}).get("QUARK_SIGN_NOTIFY")
|
| 1108 |
-
).lower()
|
| 1109 |
-
== "false"
|
| 1110 |
-
or os.environ.get("QUARK_SIGN_NOTIFY") == "false"
|
| 1111 |
-
):
|
| 1112 |
-
print(message)
|
| 1113 |
-
else:
|
| 1114 |
-
message = message.replace("今日", f"[{account.nickname}]今日")
|
| 1115 |
-
add_notify(message)
|
| 1116 |
-
else:
|
| 1117 |
-
print(f"📅 签到异常: {sign_return}")
|
| 1118 |
-
else:
|
| 1119 |
-
print("⏭️ 签到进度读取异常,可能登录失效,跳过签到")
|
| 1120 |
-
print()
|
| 1121 |
-
|
| 1122 |
-
|
| 1123 |
-
def do_save(account, tasklist=[]):
|
| 1124 |
-
print(f"🧩 载入插件")
|
| 1125 |
-
plugins, CONFIG_DATA["plugins"], task_plugins_config = Config.load_plugins(
|
| 1126 |
-
CONFIG_DATA.get("plugins", {})
|
| 1127 |
-
)
|
| 1128 |
-
print()
|
| 1129 |
-
print(f"转存账号: {account.nickname}")
|
| 1130 |
-
# 获取全部保存目录fid
|
| 1131 |
-
account.update_savepath_fid(tasklist)
|
| 1132 |
-
|
| 1133 |
-
def is_time(task):
|
| 1134 |
-
return (
|
| 1135 |
-
not task.get("enddate")
|
| 1136 |
-
or (
|
| 1137 |
-
datetime.now().date()
|
| 1138 |
-
<= datetime.strptime(task["enddate"], "%Y-%m-%d").date()
|
| 1139 |
-
)
|
| 1140 |
-
) and (
|
| 1141 |
-
"runweek" not in task
|
| 1142 |
-
# 星期一为0,星期日为6
|
| 1143 |
-
or (datetime.today().weekday() + 1 in task.get("runweek"))
|
| 1144 |
-
)
|
| 1145 |
-
|
| 1146 |
-
for plugin_name, plugin in plugins.items():
|
| 1147 |
-
if plugin.is_active and hasattr(plugin, "task_before"):
|
| 1148 |
-
tasklist = (
|
| 1149 |
-
plugin.task_before(tasklist=tasklist, account=account) or tasklist
|
| 1150 |
-
)
|
| 1151 |
-
|
| 1152 |
-
# 执行任务
|
| 1153 |
-
for index, task in enumerate(tasklist):
|
| 1154 |
-
print()
|
| 1155 |
-
print(f"#{index+1}------------------")
|
| 1156 |
-
print(f"任务名称: {task['taskname']}")
|
| 1157 |
-
print(f"分享链接: {task['shareurl']}")
|
| 1158 |
-
print(f"保存路径: {task['savepath']}")
|
| 1159 |
-
if task.get("pattern"):
|
| 1160 |
-
print(f"正则匹配: {task['pattern']}")
|
| 1161 |
-
if task.get("replace"):
|
| 1162 |
-
print(f"正则替换: {task['replace']}")
|
| 1163 |
-
if task.get("update_subdir"):
|
| 1164 |
-
print(f"更子目录: {task['update_subdir']}")
|
| 1165 |
-
if task.get("runweek") or task.get("enddate"):
|
| 1166 |
-
print(
|
| 1167 |
-
f"运行周期: WK{task.get('runweek',[])} ~ {task.get('enddate','forever')}"
|
| 1168 |
-
)
|
| 1169 |
-
print()
|
| 1170 |
-
# 判断任务周期
|
| 1171 |
-
if not is_time(task):
|
| 1172 |
-
print(f"任务不在运行周期内,跳过")
|
| 1173 |
-
else:
|
| 1174 |
-
is_new_tree = account.do_save_task(task)
|
| 1175 |
-
|
| 1176 |
-
# 补充任务的插件配置
|
| 1177 |
-
def merge_dicts(a, b):
|
| 1178 |
-
result = a.copy()
|
| 1179 |
-
for key, value in b.items():
|
| 1180 |
-
if (
|
| 1181 |
-
key in result
|
| 1182 |
-
and isinstance(result[key], dict)
|
| 1183 |
-
and isinstance(value, dict)
|
| 1184 |
-
):
|
| 1185 |
-
result[key] = merge_dicts(result[key], value)
|
| 1186 |
-
elif key not in result:
|
| 1187 |
-
result[key] = value
|
| 1188 |
-
return result
|
| 1189 |
-
|
| 1190 |
-
task["addition"] = merge_dicts(
|
| 1191 |
-
task.get("addition", {}), task_plugins_config
|
| 1192 |
-
)
|
| 1193 |
-
# 调用插件
|
| 1194 |
-
if is_new_tree:
|
| 1195 |
-
print(f"🧩 调用插件")
|
| 1196 |
-
for plugin_name, plugin in plugins.items():
|
| 1197 |
-
if plugin.is_active and hasattr(plugin, "run"):
|
| 1198 |
-
task = (
|
| 1199 |
-
plugin.run(task, account=account, tree=is_new_tree) or task
|
| 1200 |
-
)
|
| 1201 |
-
print()
|
| 1202 |
-
print(f"===============插件收尾===============")
|
| 1203 |
-
for plugin_name, plugin in plugins.items():
|
| 1204 |
-
if plugin.is_active and hasattr(plugin, "task_after"):
|
| 1205 |
-
data = plugin.task_after(tasklist=tasklist, account=account)
|
| 1206 |
-
if data.get("tasklist"):
|
| 1207 |
-
CONFIG_DATA["tasklist"] = data["tasklist"]
|
| 1208 |
-
if data.get("config"):
|
| 1209 |
-
CONFIG_DATA["plugins"][plugin_name] = data["config"]
|
| 1210 |
-
print()
|
| 1211 |
-
|
| 1212 |
-
|
| 1213 |
-
def main():
|
| 1214 |
-
global CONFIG_DATA
|
| 1215 |
-
start_time = datetime.now()
|
| 1216 |
-
print(f"===============程序开始===============")
|
| 1217 |
-
print(f"⏰ 执行时间: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 1218 |
-
print()
|
| 1219 |
-
# 读取启动参数
|
| 1220 |
-
config_path = sys.argv[1] if len(sys.argv) > 1 else "quark_config.json"
|
| 1221 |
-
# 推送测试
|
| 1222 |
-
if os.environ.get("QUARK_TEST", "").lower() == "true":
|
| 1223 |
-
print(f"===============通知测试===============")
|
| 1224 |
-
CONFIG_DATA["push_config"] = json.loads(os.environ.get("PUSH_CONFIG"))
|
| 1225 |
-
send_ql_notify(
|
| 1226 |
-
"【夸克自动转存】",
|
| 1227 |
-
f"通知测试\n\n{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}",
|
| 1228 |
-
)
|
| 1229 |
-
print()
|
| 1230 |
-
if cookies := json.loads(os.environ.get("COOKIE", "[]")):
|
| 1231 |
-
print(f"===============转存测试===============")
|
| 1232 |
-
accounts = Quark(cookies[0])
|
| 1233 |
-
accounts.do_save_check("https://pan.quark.cn/s/1ed94d530d63", "/来自:分享")
|
| 1234 |
-
print()
|
| 1235 |
-
return
|
| 1236 |
-
# 从环境变量中获取 TASKLIST
|
| 1237 |
-
tasklist_from_env = []
|
| 1238 |
-
if tasklist_json := os.environ.get("TASKLIST"):
|
| 1239 |
-
try:
|
| 1240 |
-
tasklist_from_env = json.loads(tasklist_json)
|
| 1241 |
-
except Exception as e:
|
| 1242 |
-
print(f"从环境变量解析任务列表失败 {e}")
|
| 1243 |
-
# 检查本地文件是否存在,如果不存在就下载
|
| 1244 |
-
if not os.path.exists(config_path):
|
| 1245 |
-
if os.environ.get("QUARK_COOKIE"):
|
| 1246 |
-
print(
|
| 1247 |
-
f"⚙️ 读取到 QUARK_COOKIE 环境变量,仅签到领空间。如需执行转存,请删除该环境变量后配置 {config_path} 文件"
|
| 1248 |
-
)
|
| 1249 |
-
cookie_val = os.environ.get("QUARK_COOKIE")
|
| 1250 |
-
cookie_form_file = False
|
| 1251 |
-
else:
|
| 1252 |
-
print(f"⚙️ 配置文件 {config_path} 不存在❌,正远程从下载配置模版")
|
| 1253 |
-
config_url = f"{GH_PROXY}https://raw.githubusercontent.com/Cp0204/quark_auto_save/main/quark_config.json"
|
| 1254 |
-
if Config.download_file(config_url, config_path):
|
| 1255 |
-
print("⚙️ 配置模版下载成功✅,请到程序目录中手动配置")
|
| 1256 |
-
return
|
| 1257 |
-
else:
|
| 1258 |
-
print(f"⚙️ 正从 {config_path} 文件中读取配置")
|
| 1259 |
-
CONFIG_DATA = Config.read_json(config_path)
|
| 1260 |
-
Config.breaking_change_update(CONFIG_DATA)
|
| 1261 |
-
cookie_val = CONFIG_DATA.get("cookie")
|
| 1262 |
-
cookie_form_file = True
|
| 1263 |
-
# 获取cookie
|
| 1264 |
-
cookies = Config.get_cookies(cookie_val)
|
| 1265 |
-
if not cookies:
|
| 1266 |
-
print("❌ cookie 未配置")
|
| 1267 |
-
return
|
| 1268 |
-
accounts = [Quark(cookie, index) for index, cookie in enumerate(cookies)]
|
| 1269 |
-
# 签到
|
| 1270 |
-
print(f"===============签到任务===============")
|
| 1271 |
-
if tasklist_from_env:
|
| 1272 |
-
verify_account(accounts[0])
|
| 1273 |
-
else:
|
| 1274 |
-
for account in accounts:
|
| 1275 |
-
verify_account(account)
|
| 1276 |
-
do_sign(account)
|
| 1277 |
-
print()
|
| 1278 |
-
# 转存
|
| 1279 |
-
if accounts[0].is_active and cookie_form_file:
|
| 1280 |
-
print(f"===============转存任务===============")
|
| 1281 |
-
# 任务列表
|
| 1282 |
-
if tasklist_from_env:
|
| 1283 |
-
do_save(accounts[0], tasklist_from_env)
|
| 1284 |
-
else:
|
| 1285 |
-
do_save(accounts[0], CONFIG_DATA.get("tasklist", []))
|
| 1286 |
-
print()
|
| 1287 |
-
# 通知
|
| 1288 |
-
if NOTIFYS:
|
| 1289 |
-
notify_body = "\n".join(NOTIFYS)
|
| 1290 |
-
print(f"===============推送通知===============")
|
| 1291 |
-
send_ql_notify("【夸克自动转存】", notify_body)
|
| 1292 |
-
print()
|
| 1293 |
-
if cookie_form_file:
|
| 1294 |
-
# 更新配置
|
| 1295 |
-
Config.write_json(config_path, CONFIG_DATA)
|
| 1296 |
-
|
| 1297 |
-
print(f"===============程序结束===============")
|
| 1298 |
-
duration = datetime.now() - start_time
|
| 1299 |
-
print(f"😃 运行时长: {round(duration.total_seconds(), 2)}s")
|
| 1300 |
-
print()
|
| 1301 |
-
|
| 1302 |
-
|
| 1303 |
-
if __name__ == "__main__":
|
| 1304 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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