Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e6e67c22d | ||
|
|
43e06b7d0f |
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "videosdowntools",
|
"name": "videosdowntools",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tauri": "tauri"
|
"tauri": "tauri"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import httpx
|
|||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
API = "https://git.asio.asia/api/v1/repos/nixevol/RaptDramaDump"
|
API = "https://git.asio.asia/api/v1/repos/nixevol/RaptDramaDump"
|
||||||
ASSET = ROOT / "dist" / "VideosDownTools-windows-x64.zip"
|
ASSET = ROOT / "dist" / "VideosDownTools-windows-x64.zip"
|
||||||
NOTES = "导出 DramaBox 登录凭据时会弹出保存窗口。"
|
NOTES = "导入 DramaBox 凭据后会先读取个人信息,确认登录成功后才进入。"
|
||||||
PART_SIZE = 40 * 1024 * 1024
|
PART_SIZE = 40 * 1024 * 1024
|
||||||
|
|
||||||
|
|
||||||
@@ -81,16 +81,23 @@ def main() -> None:
|
|||||||
|
|
||||||
def _upload(http: httpx.Client, release_id, path: Path) -> None:
|
def _upload(http: httpx.Client, release_id, path: Path) -> None:
|
||||||
data = path.read_bytes()
|
data = path.read_bytes()
|
||||||
uploaded = _post_asset(http, release_id, path.name, data)
|
uploaded = None
|
||||||
if uploaded.status_code != 413:
|
try:
|
||||||
if uploaded.status_code >= 300:
|
uploaded = _post_asset(http, release_id, path.name, data)
|
||||||
raise SystemExit(f"上传压缩包失败 {uploaded.status_code}")
|
except httpx.TransportError:
|
||||||
|
uploaded = None
|
||||||
|
if uploaded is not None and uploaded.status_code < 300:
|
||||||
return
|
return
|
||||||
|
if uploaded is not None and uploaded.status_code != 413:
|
||||||
|
raise SystemExit(f"上传压缩包失败 {uploaded.status_code}")
|
||||||
count = (len(data) + PART_SIZE - 1) // PART_SIZE
|
count = (len(data) + PART_SIZE - 1) // PART_SIZE
|
||||||
for index in range(count):
|
for index in range(count):
|
||||||
part = data[index * PART_SIZE : (index + 1) * PART_SIZE]
|
part = data[index * PART_SIZE : (index + 1) * PART_SIZE]
|
||||||
name = f"{path.name}.part{index + 1:03d}"
|
name = f"{path.name}.part{index + 1:03d}"
|
||||||
uploaded = _post_asset(http, release_id, name, part)
|
try:
|
||||||
|
uploaded = _post_asset(http, release_id, name, part)
|
||||||
|
except httpx.TransportError as exc:
|
||||||
|
raise SystemExit("上传压缩包时连接中断") from exc
|
||||||
if uploaded.status_code >= 300:
|
if uploaded.status_code >= 300:
|
||||||
raise SystemExit(f"上传压缩包失败 {uploaded.status_code}")
|
raise SystemExit(f"上传压缩包失败 {uploaded.status_code}")
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,38 @@ def create_guest(template: dict | None = None) -> dict:
|
|||||||
return _guest_from_bootstrap(device, data)
|
return _guest_from_bootstrap(device, data)
|
||||||
|
|
||||||
|
|
||||||
|
def refresh_account(app: dict) -> dict:
|
||||||
|
if not isinstance(app, dict):
|
||||||
|
raise RuntimeError("登录凭据已失效")
|
||||||
|
data = _post("drama-box/ap001/bootstrap", {
|
||||||
|
"distinctId": str(app.get("instance_id") or uuid.uuid4()),
|
||||||
|
"installTime": str(app.get("install_time") or int(time.time() * 1000)),
|
||||||
|
}, app)
|
||||||
|
return account_from_bootstrap(app, data)
|
||||||
|
|
||||||
|
|
||||||
|
def account_from_bootstrap(app: dict, data: dict) -> dict:
|
||||||
|
user = data.get("user") if isinstance(data, dict) else None
|
||||||
|
if not isinstance(user, dict):
|
||||||
|
raise RuntimeError("登录凭据已失效")
|
||||||
|
uid = str(user.get("uid") or user.get("userId") or "").strip()
|
||||||
|
token = str(user.get("token") or "").strip()
|
||||||
|
if not uid or uid == "0" or not token:
|
||||||
|
raise RuntimeError("登录凭据已失效")
|
||||||
|
expected = str((app or {}).get("user_id") or "").strip()
|
||||||
|
if expected and uid != expected:
|
||||||
|
raise RuntimeError("登录凭据已失效")
|
||||||
|
if not token.startswith("Bearer "):
|
||||||
|
token = f"Bearer {token}"
|
||||||
|
nickname = ""
|
||||||
|
for key in ("nickname", "nickName", "name", "userName"):
|
||||||
|
nickname = str(user.get(key) or "").strip()
|
||||||
|
if nickname:
|
||||||
|
break
|
||||||
|
vip = user.get("isVip") in (1, True) or str(user.get("isVip") or "").lower() in {"1", "true", "y"}
|
||||||
|
return {"user_id": uid, "token": token, "name": nickname, "vip": vip}
|
||||||
|
|
||||||
|
|
||||||
def ensure_guest() -> dict:
|
def ensure_guest() -> dict:
|
||||||
if client.has_guest():
|
if client.has_guest():
|
||||||
return client.guest
|
return client.guest
|
||||||
|
|||||||
@@ -23,43 +23,7 @@ def enter(language: str = "") -> dict:
|
|||||||
def import_adb(serial: str, language: str = "") -> dict:
|
def import_adb(serial: str, language: str = "") -> dict:
|
||||||
from server.services.dramabox.app_device import read_app_login
|
from server.services.dramabox.app_device import read_app_login
|
||||||
|
|
||||||
record = read_app_login(serial)
|
return _install_app_login(read_app_login(serial), language)
|
||||||
try:
|
|
||||||
locale = resolve(language or record.get("language") or client.language or DEFAULT_LANGUAGE)
|
|
||||||
except RuntimeError:
|
|
||||||
locale = resolve(DEFAULT_LANGUAGE)
|
|
||||||
if not client.token:
|
|
||||||
client.token = secrets.token_hex(16)
|
|
||||||
client.language = locale["id"]
|
|
||||||
client.app = {key: value for key, value in record.items() if key not in {"name", "vip"}}
|
|
||||||
client.app["language"] = locale["id"]
|
|
||||||
client.app["current_language"] = locale["id"]
|
|
||||||
nickname = str(record.get("name") or record.get("user_id") or "DramaBox")
|
|
||||||
client.profile = {
|
|
||||||
"id": record.get("user_id") or "",
|
|
||||||
"username": nickname,
|
|
||||||
"nickname": nickname,
|
|
||||||
"email": "",
|
|
||||||
"phone": "",
|
|
||||||
"badge": "VIP" if record.get("vip") else "",
|
|
||||||
"vipday": 1 if record.get("vip") else 0,
|
|
||||||
"score": 0,
|
|
||||||
"watched": 0,
|
|
||||||
"rewards": 0,
|
|
||||||
"login_day": 0,
|
|
||||||
"country": locale.get("country") or "",
|
|
||||||
"language": locale.get("language") or "",
|
|
||||||
"native": locale.get("native") or "",
|
|
||||||
"locale": locale.get("id") or "",
|
|
||||||
"loginType": "app",
|
|
||||||
"has_login": "1",
|
|
||||||
"app_login": "1",
|
|
||||||
"avatarNumUrl": "",
|
|
||||||
}
|
|
||||||
client.save()
|
|
||||||
from server.services.dramabox.app_api import ensure_guest
|
|
||||||
ensure_guest()
|
|
||||||
return {"token": client.token, "profile": client.profile}
|
|
||||||
|
|
||||||
|
|
||||||
_CREDENTIAL_KIND = "dramabox-login"
|
_CREDENTIAL_KIND = "dramabox-login"
|
||||||
@@ -159,19 +123,68 @@ if ($result -eq [System.Windows.Forms.DialogResult]::OK) {
|
|||||||
|
|
||||||
|
|
||||||
def import_credential(payload: dict, language: str = "") -> dict:
|
def import_credential(payload: dict, language: str = "") -> dict:
|
||||||
record = _credential_record(payload)
|
return _install_app_login(_credential_record(payload), language)
|
||||||
|
|
||||||
|
|
||||||
|
def _install_app_login(record: dict, language: str = "") -> dict:
|
||||||
try:
|
try:
|
||||||
locale = resolve(language or record.get("language") or client.language or DEFAULT_LANGUAGE)
|
locale = resolve(language or record.get("language") or client.language or DEFAULT_LANGUAGE)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
locale = resolve(DEFAULT_LANGUAGE)
|
locale = resolve(DEFAULT_LANGUAGE)
|
||||||
|
previous = {
|
||||||
|
"token": client.token,
|
||||||
|
"language": client.language,
|
||||||
|
"app": dict(client.app),
|
||||||
|
"profile": dict(client.profile) if isinstance(client.profile, dict) else {},
|
||||||
|
}
|
||||||
if not client.token:
|
if not client.token:
|
||||||
client.token = secrets.token_hex(16)
|
client.token = secrets.token_hex(16)
|
||||||
client.language = locale["id"]
|
client.language = locale["id"]
|
||||||
client.app = {key: value for key, value in record.items() if key not in {"name", "vip"}}
|
client.app = {key: value for key, value in record.items() if key not in {"name", "vip"}}
|
||||||
client.app["language"] = locale["id"]
|
client.app["language"] = locale["id"]
|
||||||
client.app["current_language"] = locale["id"]
|
client.app["current_language"] = locale["id"]
|
||||||
|
client.profile = _profile_from_record(record, locale)
|
||||||
|
client.save()
|
||||||
|
try:
|
||||||
|
_confirm_account(locale)
|
||||||
|
except RuntimeError:
|
||||||
|
client.token = previous["token"]
|
||||||
|
client.language = previous["language"]
|
||||||
|
client.app = previous["app"]
|
||||||
|
client.profile = previous["profile"]
|
||||||
|
client.save()
|
||||||
|
raise
|
||||||
|
from server.services.dramabox.app_api import ensure_guest
|
||||||
|
ensure_guest()
|
||||||
|
return {"token": client.token, "profile": client.profile}
|
||||||
|
|
||||||
|
|
||||||
|
def _confirm_account(locale: dict) -> None:
|
||||||
|
from server.services.dramabox.app_api import refresh_account
|
||||||
|
|
||||||
|
try:
|
||||||
|
fresh = refresh_account(client.app)
|
||||||
|
except RuntimeError as exc:
|
||||||
|
text = str(exc).strip()
|
||||||
|
if "失效" in text:
|
||||||
|
raise
|
||||||
|
if any(word in text for word in ("拦截", "没有响应", "没有返回", "网络")):
|
||||||
|
raise RuntimeError("暂时读不到个人信息,请检查网络后再导入") from exc
|
||||||
|
raise RuntimeError("登录凭据已失效") from exc
|
||||||
|
if fresh.get("token"):
|
||||||
|
client.app["token"] = fresh["token"]
|
||||||
|
if fresh.get("user_id"):
|
||||||
|
client.app["user_id"] = fresh["user_id"]
|
||||||
|
record = dict(client.app)
|
||||||
|
record["name"] = fresh.get("name") or ""
|
||||||
|
record["vip"] = fresh.get("vip") is True
|
||||||
|
client.profile = _profile_from_record(record, locale)
|
||||||
|
client.save()
|
||||||
|
|
||||||
|
|
||||||
|
def _profile_from_record(record: dict, locale: dict) -> dict:
|
||||||
nickname = str(record.get("name") or record.get("user_id") or "DramaBox")
|
nickname = str(record.get("name") or record.get("user_id") or "DramaBox")
|
||||||
client.profile = {
|
return {
|
||||||
"id": record.get("user_id") or "",
|
"id": record.get("user_id") or "",
|
||||||
"username": nickname,
|
"username": nickname,
|
||||||
"nickname": nickname,
|
"nickname": nickname,
|
||||||
@@ -192,10 +205,6 @@ def import_credential(payload: dict, language: str = "") -> dict:
|
|||||||
"app_login": "1",
|
"app_login": "1",
|
||||||
"avatarNumUrl": "",
|
"avatarNumUrl": "",
|
||||||
}
|
}
|
||||||
client.save()
|
|
||||||
from server.services.dramabox.app_api import ensure_guest
|
|
||||||
ensure_guest()
|
|
||||||
return {"token": client.token, "profile": client.profile}
|
|
||||||
|
|
||||||
|
|
||||||
def _credential_record(payload: dict) -> dict:
|
def _credential_record(payload: dict) -> dict:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "VideosDownTools",
|
"productName": "VideosDownTools",
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"identifier": "com.videosdowntools.desktop",
|
"identifier": "com.videosdowntools.desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": {
|
"beforeDevCommand": {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from server.services.dramabox.app_api import account_from_bootstrap
|
||||||
from server.services.dramabox.login import _credential_record
|
from server.services.dramabox.login import _credential_record
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +36,27 @@ def test_credential_file_is_one_json_document() -> None:
|
|||||||
raise AssertionError("不完整的凭据文件应被拒绝")
|
raise AssertionError("不完整的凭据文件应被拒绝")
|
||||||
|
|
||||||
|
|
||||||
|
def test_account_profile_must_match_the_credential() -> None:
|
||||||
|
app = {"user_id": "88", "token": "Bearer old"}
|
||||||
|
fresh = account_from_bootstrap(app, {"user": {"uid": "88", "token": "new", "nickname": "阿花", "isVip": 1}})
|
||||||
|
assert fresh["token"] == "Bearer new"
|
||||||
|
assert fresh["name"] == "阿花"
|
||||||
|
assert fresh["vip"] is True
|
||||||
|
try:
|
||||||
|
account_from_bootstrap(app, {"user": {"uid": "99", "token": "new", "nickname": "别人"}})
|
||||||
|
except RuntimeError as exc:
|
||||||
|
assert "失效" in str(exc)
|
||||||
|
else:
|
||||||
|
raise AssertionError("用户编号不一致应视为未登录")
|
||||||
|
try:
|
||||||
|
account_from_bootstrap(app, {})
|
||||||
|
except RuntimeError as exc:
|
||||||
|
assert "失效" in str(exc)
|
||||||
|
else:
|
||||||
|
raise AssertionError("没有个人信息应视为未登录")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_credential_file_is_one_json_document()
|
test_credential_file_is_one_json_document()
|
||||||
|
test_account_profile_must_match_the_credential()
|
||||||
print("ok")
|
print("ok")
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "videosdowntools-ui",
|
"name": "videosdowntools-ui",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.3",
|
"version": "0.1.4",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
Reference in New Issue
Block a user