anx-rule/2 格式
最小结构
json
{
"format": "anx-rule/2",
"id": "example",
"name": "Example Anime",
"baseUrl": "https://api.example.com",
"iconUrl": "https://example.com/favicon.ico",
"description": "示例 JSON API 规则",
"headers": {
"User-Agent": "Mozilla/5.0 ...",
"Accept": "application/json"
},
"search": [],
"detail": [],
"play": []
}顶层字段
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
format | string | 推荐 | 当前值 anx-rule/2 |
id | string | 是 | 稳定、唯一;通常与文件名和索引 key 一致 |
name | string | 是 | 用户可见名称 |
baseUrl | URL | 是 | URL 解析与相对请求的基准 |
iconUrl | HTTP(S) URL | 推荐 | 规则库和源管理页图标 |
description | string | 否 | 简短用途说明 |
headers | object | 否 | 规则的全局请求头 |
recipes | string[] | 否 | maccms、player_aaaa |
search | step[] | 是 | 搜索管线 |
detail | step[] | 是 | 详情/剧集管线 |
play | step[] | 是 | 播放解析管线 |
useWebview | boolean | 否 | 允许 sniff 使用 WebView |
directConnection | boolean | 否 | 绕过系统代理;仅在站点确有同出口绑定时使用 |
enabled、createdAt、updatedAt 属于安装后的本地生命周期字段,贡献仓库规则时通常无需手工填写。
完整 JSON API 示例
json
{
"format": "anx-rule/2",
"id": "example",
"name": "Example Anime",
"baseUrl": "https://api.example.com",
"iconUrl": "https://example.com/favicon.ico",
"headers": {
"Accept": "application/json",
"Origin": "https://example.com",
"Referer": "https://example.com/"
},
"search": [
{
"op": "fetch",
"url": "/api/videos?keyword={keyword}"
},
{
"op": "jsonSeries",
"listPath": "data.records",
"idKey": "id",
"nameKey": "title",
"imageKey": "cover",
"descKey": "summary",
"detailUrlTemplate": "/api/videos/{id}"
}
],
"detail": [
{ "op": "follow" },
{
"op": "jsonEpisodes",
"episodesPath": "data.episodes",
"episodeNameKey": "label",
"episodeIdTemplate": "{episodeId:raw}",
"sourceName": "默认线路"
}
],
"play": [
{
"op": "fetch",
"url": "/api/episodes/{episodeId:raw}/play"
},
{
"op": "setMediaHeaders",
"headers": {
"Referer": "https://example.com/"
}
},
{
"op": "json",
"path": "data.playUrl"
}
]
}模板变量
字符串参数支持 {name} 与 {name:raw}:
{name}:URL 编码后插入。{name:raw}:原样插入。
内置变量:
| 变量 | 可用阶段 | 含义 |
|---|---|---|
keyword | search | 搜索关键词 |
seriesId | detail | 搜索产出的系列标识或详情 URL |
episodeId | play | 详情产出的剧集标识 |
baseUrl | 全部 | 规则基准 URL |
timestamp | 全部 | 当前时间戳 |
url | 全部 | 当前值的字符串形式 |
setVar 可以创建自定义变量。JSON 列表操作符还会把当前条目字段作为模板变量提供。
结果契约
Series
搜索结果至少包含稳定的 seriesId 与 name,可附带图片、简介、BGM subject id 和评分。
Source / Episode
详情结果是一组线路。每条 Source 包含线路名和 Episode 列表;每集至少有 episodeId、顺序索引与显示名。
播放结果
播放 URL 不能为空,并应在 URL 归一化后仍为真实媒体或播放器支持的 Magnet/Torrent 标识。若媒体需要 Referer、User-Agent、Cookie 或其他头部,必须在管线中明确声明。
