SDK 说明
同一套函数名,支持JavaScript和Python
引入 SDK
js
const OmniBox = require("omnibox_sdk");
const runner = require("spider_runner");
module.exports = { home, category, detail, search, play };
runner.run(module.exports);python
from spider_runner import OmniBox, run
if __name__ == "__main__":
run({"home": home, "category": category, "detail": detail, "search": search, "play": play})基础能力
用于请求外部接口、打印日志、读取环境变量。
request(url, options)
发送 HTTP 请求,返回 statusCode / headers / body。
js
const response = await OmniBox.request("https://api.example.com/data", {
method: "GET",
headers: { "User-Agent": "Mozilla/5.0" },
});
const data = JSON.parse(response.body || "{}");python
import json
response = await OmniBox.request("https://api.example.com/data", {
"method": "GET",
"headers": {"User-Agent": "Mozilla/5.0"},
})
data = json.loads(response.get("body", "{}"))log(level, message)
输出脚本日志,便于调试和排错。
js
await OmniBox.log("info", "开始执行");python
await OmniBox.log("info", "开始执行")getEnv(name)
读取后端环境变量(也可直接读 process.env / os.environ)。
js
const apiKey = await OmniBox.getEnv("API_KEY");python
api_key = await OmniBox.getEnv("API_KEY")爬虫源数据
用于读取当前爬虫源下的收藏标签与分类数据。
getSourceFavoriteTags()
获取当前源的收藏标签列表。
js
const tags = await OmniBox.getSourceFavoriteTags();python
tags = await OmniBox.getSourceFavoriteTags()getSourceCategoryData(categoryType, page, pageSize)
分页读取列表数据(Runner 注入当前源 ID,用法同 getSourceFavoriteTags())。
支持参数:
- 必填:
categoryType—history(当前源播放历史)、favorite(当前源收藏)、follow(全站追剧,与源无关)、或其它收藏标签名(可先getSourceFavoriteTags())。 - 可选:
page、pageSize(默认1、20)。
js
const data = await OmniBox.getSourceCategoryData("history", 1, 20);python
data = await OmniBox.getSourceCategoryData("history", 1, 20)网盘能力
用于网盘文件浏览、播放信息获取与盘类型识别。
getDriveFileList(shareURL, pdirFid)
读取分享链接下指定目录文件列表。
js
const files = await OmniBox.getDriveFileList("https://share.url", "0");python
files = await OmniBox.getDriveFileList("https://share.url", "0")getDriveVideoPlayInfo(shareURL, fid, flag)
获取可播放地址。
js
const playInfo = await OmniBox.getDriveVideoPlayInfo("https://share.url", "fid", "");python
play_info = await OmniBox.getDriveVideoPlayInfo("https://share.url", "fid", "")getDriveInfoByShareURL(shareURL)
根据分享链接识别网盘类型和显示名称。
js
const driveInfo = await OmniBox.getDriveInfoByShareURL("https://share.url");python
drive_info = await OmniBox.getDriveInfoByShareURL("https://share.url")getDriveShareInfo(shareURL)
获取分享信息(如网盘类型、token 等)。
js
const shareInfo = await OmniBox.getDriveShareInfo("https://share.url");python
share_info = await OmniBox.getDriveShareInfo("https://share.url")刮削能力
用于触发 TMDB 刮削并读取已保存的刮削结果。
processScraping(videoId, keyword, resourceName, videoFiles)
执行刮削任务并保存结果。
js
await OmniBox.processScraping("resource_id", "关键词", "资源名", []);python
await OmniBox.processScraping("resource_id", "关键词", "资源名", [])getScrapeMetadata(videoId)
获取刮削后的元数据(如 scrapeData、videoMappings)。
js
const metadata = await OmniBox.getScrapeMetadata("resource_id");python
metadata = await OmniBox.getScrapeMetadata("resource_id")播放辅助
用于播放阶段的嗅探、媒体信息探测、弹幕、解析站与历史记录。
sniffVideo(url, headers)
嗅探页面中的真实视频地址(需完整版运行环境)。
js
const { url, header } = await OmniBox.sniffVideo("https://example.com/play", {
Referer: "https://example.com/",
});python
result = await OmniBox.sniffVideo("https://example.com/play", {"Referer": "https://example.com/"})getVideoMediaInfo(playUrl, headers)
根据播放地址探测媒体信息(ffprobe 原始结果,含 format / streams)。
js
const mediaInfo = await OmniBox.getVideoMediaInfo("https://example.com/video.m3u8", {
Referer: "https://example.com/",
});
const duration = Number(mediaInfo?.format?.duration || 0);python
media_info = await OmniBox.getVideoMediaInfo(
"https://example.com/video.m3u8",
{"Referer": "https://example.com/"},
)
duration = int(float(((media_info.get("format") or {}).get("duration") or 0)))getDanmakuByFileName(fileName)
根据文件名匹配弹幕列表。
js
const danmaku = await OmniBox.getDanmakuByFileName("video.mp4");python
danmaku = await OmniBox.getDanmakuByFileName("video.mp4")getAnalyzeSites()
获取解析站配置(name/url/type)。
js
const sites = await OmniBox.getAnalyzeSites();python
sites = await OmniBox.getAnalyzeSites()addPlayHistory(...)
添加观看记录(不存在时新增)。
支持参数:
- 必填:
vodId、title、episode - 可选:
pic、episodeNumber、episodeName、totalDuration
js
const mediaInfo = await OmniBox.getVideoMediaInfo("https://example.com/video.m3u8", {
Referer: "https://example.com/",
});
const duration = Number(mediaInfo?.format?.duration || 0);
const added = await OmniBox.addPlayHistory({
vodId: "video_123",
title: "片名",
pic: "https://example.com/poster.jpg",
episode: "ep_1",
episodeNumber: 1,
episodeName: "第1集",
totalDuration: duration,
});python
media_info = await OmniBox.getVideoMediaInfo(
"https://example.com/video.m3u8",
{"Referer": "https://example.com/"},
)
duration = int(float(((media_info.get("format") or {}).get("duration") or 0)))
added = await OmniBox.addPlayHistory(
"video_123", # vod_id
"片名", # title
pic="https://example.com/poster.jpg",
episode="ep_1",
episode_number=1,
episode_name="第1集",
total_duration=duration,
)缓存能力
用于跨请求缓存解析结果(语义接近 Redis)。
getCache(key)
读取缓存,未命中返回 null / None。
js
const cached = await OmniBox.getCache("search:key:1");python
cached = await OmniBox.getCache("search:key:1")setCache(key, value, exSeconds)
写入缓存,可设置过期秒数。
js
await OmniBox.setCache("search:key:1", { list: [] }, 3600);python
await OmniBox.setCache("search:key:1", {"list": []}, 3600)deleteCache(key)
删除缓存,返回删除条数。
js
const deleted = await OmniBox.deleteCache("search:key:1");python
deleted = await OmniBox.deleteCache("search:key:1")