feat(monitor): 抖音 Web 接口客户端 —— 绕开爬虫子进程,直接发 HTTP
移植自 mac-agent-os 的 mediacrawler_adapter:不起子进程、不开页面,用浏览器里那份
登录态直接调抖音 Web 接口。产物键名照抄 store/douyin,所以 ingest 那条链路一个字不用改。
**目前能用的(真环境实测,非推断)**:
profile/other : 200, 7075 字节 —— 博主主页指标(粉丝/获赞/作品数/昵称)
aweme/detail : 200, 45425 字节 —— 单条作品详情(含点赞/评论/收藏/分享)
**目前不能用的:作品列表 `aweme/post`。** 两个互相独立的原因:
1. 这个接口被抖音单独升级成了真校验:不带 x-tt-argus 回 403「Uifid Not Found」,
带上 dummy 值回 200 + **空 body**。也就是说「头在不在」骗得过,「真校验」过不了。
同一套头打 profile/other 和 aweme/detail 都是通的 —— 抖音是挑着接口加保护的,
挑中的恰好是「批量拉作品列表」这个最敏感的动作。
2. 改走页面截获也不行:CDP 浏览器打开博主主页会落到「验证码中间页」(当天大量探测的
代价,过几小时要重测)。
所以现在的边界是:**已知作品的指标刷新能做,自动发现新作品做不了**。
**排查中控住变量后得到的两条事实**(都写进注释了):
· `Accept` / `Accept-Language` / `Referer` 才是主页接口能返回真数据的原因 —— 只有
UA+client hints+Cookie 时是 200 但仅 121 字节的空壳,补上这三个头变 7074 字节。
(我先前猜的 sec-ch-ua 不是关键。)
· 因此 UA 与 client hints 必须**成套地取自同一个浏览器**,所以 BrowserIdentity 一次
从 CDP 取齐 cookie + UA + hints,而不是各自写死。
「200 + 空 body 必须当场报错」也是刻意写死的:放过去它会在下游变成「这个博主没作品」,
把一次失败伪装成一条正常结果 —— 爬虫那条路正是这么栽的,还被翻译成「账号被封」。
测试 +11:cookie 解析、请求头成套性(含 uifid 缺失/回退)、产物键名与 store 对齐、
以及 _get 的三条失败路径(空 body / 403 带网关原话 / 正常返回)。
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
"""
|
||||
plugins/matrix.py — Matrix 账号矩阵插件 (v3.2)
|
||||
跨机注册表: Registry(L0 Gitee) + Override(L1 local) + 运行时(L2 cross_machine)
|
||||
版本: 3.2.0 | 更新: 2026-05-31
|
||||
"""
|
||||
import os, yaml, json, subprocess, time
|
||||
from pathlib import Path
|
||||
|
||||
from plugins.base import DashboardPlugin, AGENT_SYNC, AGENT_LOCAL, HOSTNAME, MACHINE_UID
|
||||
from plugins._registry import get_machine_list, get_plugin_data
|
||||
|
||||
MATRIX_MGMT = AGENT_SYNC / "05_tools" / "07_matrix" / "scripts" / "matrix_mgmt.py"
|
||||
|
||||
|
||||
def _run_mgmt(method: str, *args, **kwargs):
|
||||
import importlib.util
|
||||
spec = importlib.util.spec_from_file_location("matrix_mgmt", MATRIX_MGMT)
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(mod)
|
||||
mgr = mod.MatrixManager()
|
||||
fn = getattr(mgr, method)
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
|
||||
class MatrixPlugin(DashboardPlugin):
|
||||
name = "matrix"
|
||||
label = "矩阵养号"
|
||||
icon = "📱"
|
||||
version = "3.2.0"
|
||||
description = "Matrix: 跨机账号注册表 / 蓝图编排 / 原子操作 / 备份恢复"
|
||||
order = 30
|
||||
|
||||
def get_sub_views(self) -> list[dict]:
|
||||
return [
|
||||
{"key": "matrix-accounts", "label": "账号管理", "icon": "👤", "group": "matrix"},
|
||||
{"key": "matrix-blueprints", "label": "蓝图编排", "icon": "📋", "group": "matrix"},
|
||||
{"key": "matrix-atom-ops", "label": "原子操作", "icon": "⚡", "group": "matrix"},
|
||||
{"key": "matrix-backup", "label": "备份恢复", "icon": "💾", "group": "matrix"},
|
||||
{"key": "matrix-export", "label": "导入导出", "icon": "📦", "group": "matrix"},
|
||||
]
|
||||
|
||||
def _build_machine_map(self) -> dict:
|
||||
"""聚合 registry 中所有 assigned_machine 及本机/远程状态"""
|
||||
accounts = _run_mgmt("list_accounts")
|
||||
machines = {}
|
||||
for a in accounts:
|
||||
owner = a.get("owner_machine", "未分配")
|
||||
if owner not in machines:
|
||||
machines[owner] = {"总": 0, "本机": 0, "已启用": 0, "已登录": 0, "离线": 0}
|
||||
machines[owner]["总"] += 1
|
||||
if a.get("is_local"): machines[owner]["本机"] += 1
|
||||
if a.get("enabled"): machines[owner]["已启用"] += 1
|
||||
if a.get("_status") == "logged_in": machines[owner]["已登录"] += 1
|
||||
elif a.get("_status") == "remote": machines[owner]["离线"] += 1
|
||||
return machines
|
||||
|
||||
def summary(self, machines):
|
||||
try:
|
||||
info = _run_mgmt("system_info")
|
||||
_run_mgmt("publish_status") # 写 cross_machine
|
||||
accounts = _run_mgmt("list_accounts")
|
||||
except Exception as e:
|
||||
return {"error": str(e)}
|
||||
|
||||
# 本机概览
|
||||
local = [a for a in accounts if a.get("is_local")]
|
||||
local_enabled = sum(1 for a in local if a.get("enabled"))
|
||||
local_logged = sum(1 for a in local if a.get("_status") == "logged_in")
|
||||
all_enabled = sum(1 for a in accounts if a.get("enabled"))
|
||||
|
||||
machine_map = self._build_machine_map()
|
||||
|
||||
# 聚合其他机器数据
|
||||
for d in get_plugin_data(self.name):
|
||||
hn = d.get("hostname", "")
|
||||
if hn and hn != HOSTNAME:
|
||||
data = d.get("data", {})
|
||||
if hn not in machine_map:
|
||||
machine_map[hn] = data.get("account_summary", {"_note": "在线"})
|
||||
|
||||
return {
|
||||
"注册表账号": info["total_accounts"],
|
||||
"本机": len(local),
|
||||
"本机已启用": local_enabled,
|
||||
"本机已登录": local_logged,
|
||||
"各机器": machine_map,
|
||||
}
|
||||
|
||||
def detail(self, machine=""):
|
||||
try:
|
||||
_run_mgmt("publish_status")
|
||||
info = _run_mgmt("system_info")
|
||||
accounts = _run_mgmt("list_accounts")
|
||||
blueprints = _run_mgmt("list_blueprints")
|
||||
ops = _run_mgmt("list_atomic_ops")
|
||||
except Exception as e:
|
||||
return {HOSTNAME: {"error": str(e)}}
|
||||
|
||||
# 按所有者分组
|
||||
by_owner = {}
|
||||
for a in accounts:
|
||||
owner = a.get("owner_machine", "未分配")
|
||||
if owner not in by_owner:
|
||||
by_owner[owner] = []
|
||||
by_owner[owner].append(a)
|
||||
|
||||
return {HOSTNAME: {
|
||||
"系统信息": info,
|
||||
"注册表": accounts, # 完整列表(含远程)
|
||||
"按机器分组": by_owner, # 按 owner 分组更好展示
|
||||
"本机账号": [a for a in accounts if a.get("is_local")],
|
||||
"蓝图列表": blueprints,
|
||||
"原子操作": ops,
|
||||
"配置路径": str(AGENT_LOCAL / "tools" / "matrix" / "config"),
|
||||
}}
|
||||
|
||||
def actions(self) -> list[dict]:
|
||||
return [
|
||||
{"name": "刷新数据", "method": "POST", "endpoint": "/api/plugins/matrix/refresh"},
|
||||
{"name": "注册表", "method": "GET", "endpoint": "/api/matrix/accounts"},
|
||||
{"name": "蓝图管理", "method": "GET", "endpoint": "/api/matrix/blueprints"},
|
||||
{"name": "导出账号", "method": "GET", "endpoint": "/api/matrix/export"},
|
||||
]
|
||||
Reference in New Issue
Block a user