接口概述
本接口提供直播源地址获取功能,支持:抖音直播、快手直播、哔哩哔哩直播、斗鱼直播、虎牙直播等国内外 50+ 直播平台。通过传入平台名称和房间号,即可获取对应的直播流地址。
功能特点
- ✅ 支持 50+ 直播平台
- ✅ 自动识别房间号(支持直接输入完整 URL)
- ✅ 支持多线路返回
- ✅ 返回标准 m3u8、flv 等流媒体地址
接入方式
接口地址
POST https://www.yuntts.com/api/v1/live-api
认证方式
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer Token |
| Content-Type | string | 是 | application/json |
💡 如何获取 API 密钥?
- 登录 会员中心管理后台
- 进入 "API设置" 菜单
- 在 "API密钥管理" 中创建新的密钥
请求说明
请求头
| Header | 类型 | 必填 | 说明 |
|---|---|---|---|
Content-Type |
string | ✅ | application/json |
Authorization |
string | ✅ | Bearer Token 认证 |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
live_platform |
string | ✅ | 直播平台名称(中文) |
parameter |
string | ✅ | 直播间号或完整 URL |
请求示例
cURL 请求
curl -X POST "https://www.yuntts.com/api/v1/live-api"
-H "Content-Type: application/json"
-H "Authorization: Bearer sk-xxxxxxxxxxxx"
-d '{
"live_platform": "B站",
"parameter": "123456"
}'
JavaScript 请求
async function getLiveUrl(platform, roomId) {
const response = await fetch('https://你的域名/wp-json/api/v1/live-api', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxxxxxxxxxx'
},
body: JSON.stringify({
live_platform: platform,
parameter: roomId
})
});
const data = await response.json();
if (data.code === 200 && data.data && data.data.state === 1) {
console.log('直播地址:', data.data.data);
return data.data.data;
} else {
console.error('获取失败:', data.message);
return null;
}
}
// 使用示例
getLiveUrl('B站', '123456');
Python 请求
import requests
def get_live_url(platform, room_id):
url = 'https://www.yuntts.com/api/v1/live-api'
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxxxxxxxxxx'
}
data = {
'live_platform': platform,
'parameter': room_id
}
response = requests.post(url, headers=headers, json=data)
result = response.json()
if result.get('code') == 200 and result.get('data', {}).get('state') == 1:
return result['data']['data']
else:
print(f"获取失败: {result.get('message')}")
return None
# 使用示例
url = get_live_url('B站', '123456')
print(url)
PHP 请求
<?php
function getLiveUrl($platform, $roomId) {
$url = 'https://www.yuntts.com/api/v1/live-api';
$apiKey = 'sk-xxxxxxxxxxxx';
$data = array(
'live_platform' => $platform,
'parameter' => $roomId
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if ($result['code'] === 200 && $result['data']['state'] === 1) {
return $result['data']['data'];
} else {
return null;
}
}
// 使用示例
$urls = getLiveUrl('B站', '123456');
print_r($urls);
响应格式
成功响应(HTTP 200)
{
"code": 200,
"message": "获取直播地址成功",
"data": {
"state": 1,
"data": {
"线路1": "https://d1--ov-gotcha207.bilivideo.com/live-bvc/938438/live_31703119_1835454_2500/index.m3u8?expires=...",
"线路2": "https://d1--ov-gotcha207b.bilivideo.com/live-bvc/938438/live_31703119_1835454_2500/index.m3u8?expires=..."
}
}
}
参数错误响应(HTTP 400)
{
"code": 400,
"message": "请输入直播平台名称!",
"data": {
"state": 0
}
}
未找到响应(HTTP 404)
{
"code": 404,
"message": "未找到直播地址,请检查平台名称和房间号!",
"data": {
"state": 0
}
}
认证失败响应(HTTP 401)
{
"code": 401,
"message": "API密钥无效",
"data": null
}
支持平台
热门平台 ✅
| 平台名称 | parameter 示例 | 说明 |
|---|---|---|
| B站 | 123456 或 https://live.bilibili.com/123456 |
bilibili |
| 斗鱼 | 123456 或 https://www.douyu.com/123456 |
douyu |
| 虎牙 | 123456 或 https://www.huya.com/123456 |
huya |
| 抖音 | 123456 |
douyin |
| 快手 | 123456 |
kuaishou |
视频平台 ✅
| 平台名称 | 说明 |
|---|---|
| 爱奇艺 | ✅ 正常 |
| 优酷 | ✅ 正常 |
| 央视频 | ✅ 正常 |
| 咪咕 | ✅ 正常 |
| 企鹅体育 | ✅ 正常 |
游戏直播平台 ✅
| 平台名称 | 说明 |
|---|---|
| 六间房 | ✅ 正常 |
| CC直播 | ✅ 正常 |
| KK直播 | ✅ 正常 |
| 战旗 | ✅ 正常 |
| Twitch | ✅ 正常 |
| TikTok | ✅ 正常 |
社交直播平台 ✅
| 平台名称 | 说明 |
|---|---|
| 一直播 | ✅ 正常 |
| 映客 | ✅ 正常 |
| 花椒 | ✅ 正常 |
| 陌陌直播 | ✅ 正常 |
| YY直播 | ✅ 正常 |
其他平台 ✅
| 平台名称 | 说明 |
|---|---|
| 京东直播 | ✅ 正常 |
| 酷我 | ✅ 正常 |
| 酷狗 | ✅ 正常 |
| 猫耳 | ✅ 正常 |
| BIGO | ✅ 正常 |
示例代码
前端播放器集成
使用 Video.js
<!DOCTYPE html>
<html>
<head>
<link href="https://vjs.zencdn.net/7.x/video-js.min.css" rel="stylesheet">
<script src="https://vjs.zencdn.net/7.x/video.min.js"></script>
</head>
<body>
<video id="my-video" class="video-js" controls preload="auto" >
<p class="vjs-no-js">
要播放此视频,请启用 JavaScript 并考虑升级到 Web 浏览器。
</p>
</video>
<script>
async function playLiveStream(platform, roomId) {
const response = await fetch('https://www.yuntts.com/api/v1/live-api', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxxxxxxxxxx'
},
body: JSON.stringify({
live_platform: platform,
parameter: roomId
})
});
const result = await response.json();
if (result.code === 200 && result.data.state === 1) {
const urls = result.data.data;
// 使用第一条线路
const streamUrl = urls['线路1'] || Object.values(urls)[0];
const player = videojs('my-video');
player.src({
src: streamUrl,
type: streamUrl.includes('.m3u8') ? 'application/x-mpegURL' : 'rtmp/flv'
});
player.play();
} else {
alert('获取直播地址失败: ' + result.message);
}
}
// 调用示例
playLiveStream('B站', '123456');
</script>
</body>
</html>
使用 DPlayer
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/dplayer@1.26.0/dist/DPlayer.min.css" rel="stylesheet">
</head>
<body>
<div id="dplayer"></div>
<script src="https://cdn.jsdelivr.net/npm/dplayer@1.26.0/dist/DPlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hls.js@1.1.5/dist/hls.min.js"></script>
<script>
async function initPlayer(platform, roomId) {
const response = await fetch('https://你的域名/wp-json/api/v1/live-api', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxxxxxxxxxx'
},
body: JSON.stringify({
live_platform: platform,
parameter: roomId
})
});
const result = await response.json();
if (result.code === 200 && result.data.state === 1) {
const urls = result.data.data;
const streamUrl = urls['线路1'] || Object.values(urls)[0];
const dp = new DPlayer({
container: document.getElementById('dplayer'),
live: true,
autoplay: true,
token: 'tokened',
danmaku: {
id: 'live-' + roomId,
api: 'https://api.prprpr.me/dplayer/'
},
video: {
url: streamUrl,
type: 'hls',
customType: {
hls: function (video, player) {
const hls = new Hls();
hls.loadSource(video.src);
hls.attachMedia(video);
}
}
}
});
}
}
// 调用示例
initPlayer('斗鱼', '123456');
</script>
</body>
</html>
错误处理
错误代码对照表
| HTTP 状态码 | code | 错误代码 | 说明 |
|---|---|---|---|
| 200 | 200 | - | 获取成功 |
| 400 | 400 | empty_platform |
平台名称为空 |
| 400 | 400 | empty_parameter |
参数为空 |
| 401 | 401 | rest_invalid_api_key |
API密钥无效 |
| 401 | 401 | rest_forbidden |
缺少认证头 |
| 404 | 404 | stream_not_found |
未找到直播地址 |
| 500 | 500 | api_request_failed |
上游请求失败 |
| 500 | 500 | response_parse_failed |
响应解析失败 |
建议的错误处理代码
async function handleLiveUrl(platform, roomId) {
try {
const response = await fetch('https://你的域名/wp-json/api/v1/live-api', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer sk-xxxxxxxxxxxx'
},
body: JSON.stringify({
live_platform: platform,
parameter: roomId
})
});
const result = await response.json();
switch (result.code) {
case 200:
if (result.data.state === 1) {
// 成功获取直播地址
return result.data.data;
} else {
// 直播间未开播或不存在
console.log('直播间未开播或不存在');
return null;
}
case 400:
if (result.message.includes('平台')) {
alert('请输入有效的直播平台名称');
} else {
alert('请输入有效的房间号');
}
return null;
case 401:
alert('API密钥无效,请检查配置');
return null;
case 404:
alert('未找到该直播间的地址');
return null;
default:
alert('获取失败: ' + result.message);
return null;
}
} catch (error) {
console.error('网络错误:', error);
alert('网络连接失败,请检查网络');
return null;
}
}
常见问题
Q1: 如何获取 API 密钥?
A: 登录 WordPress 管理后台 → API设置 → API密钥管理 → 创建新密钥
Q2: 支持 HTTPS 吗?
A: 支持!接口同时支持 HTTP 和 HTTPS,建议使用 HTTPS 以保证数据传输安全。
Q3: 请求超时怎么办?
A: 默认超时时间为 30 秒。如果网络较慢,可以:
- 检查网络连接
- 稍后重试
- 联系管理员检查上游服务状态
Q4: 返回的地址无法播放?
A: 可能原因:
- 直播间未开播
- 平台API变更
- 地址已过期(直播地址有时效性)
- 播放器不支持该格式
Q5: 如何处理未开播的情况?
A: 当直播间未开播时,接口会返回:
{
"state": 0,
"data": null
}
建议前端提示用户"直播间未开播"并引导稍后重试。
Q6: 支持直接输入 URL 吗?
A: 支持!以下方式都可以:
parameter: "123456"
parameter: "https://live.bilibili.com/123456"
parameter: "https://www.douyu.com/123456"
parameter: "https://www.huya.com/123456"
Q7: 如何选择清晰的线路?
A: 返回的线路按质量排序,通常"线路1"质量最佳。如果播放卡顿,可以尝试其他线路。
技术支持
如有问题,请检查:
- API 密钥是否正确
- 网络连接是否正常
- 直播间是否存在且已开播
- 查看 WordPress 错误日志
⚠️ 免责声明
本接口仅供学习和研究使用。请勿用于商业用途或其他违法活动。使用本工具获取的直播内容,请遵守相关版权法规。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)