永久免费的多平台弹幕解析服务 - 无限制调用
直接传入视频URL,自动识别平台并解析弹幕
传统接口模式,支持各平台视频ID
无任何收费项目,永久免费使用
平均响应时间 < 50ms
没有调用次数限制
7×24小时稳定运行
支持5大主流视频平台
无需注册,即开即用
// 方式一:URL模式获取B站视频弹幕
async function getBilibiliDanmaku() {
try {
const response = await fetch('https://danmu.huaqi.pro/?url=https://www.bilibili.com/video/BV1xx411c7mu');
const data = await response.json();
console.log(`弹幕总数: ${data.total}`);
console.log(`前10条弹幕:`);
data.danmaku.slice(0, 10).forEach((dm, index) => {
console.log(`${index + 1}. [${dm.time}s] ${dm.text} (用户: ${dm.author})`);
});
} catch (error) {
console.error('获取弹幕失败:', error);
}
}
// 方式二:ID模式获取弹幕
async function getDanmakuById() {
try {
const response = await fetch('https://danmu.huaqi.pro/?ac=dm&id=BV1xx411c7mu');
const data = await response.json();
console.log(`通过ID获取弹幕数量: ${data.total}`);
data.danmaku.forEach(dm => {
console.log(`${dm.time}s: ${dm.text}`);
});
} catch (error) {
console.error('获取弹幕失败:', error);
}
}
// 执行示例
getBilibiliDanmaku();
getDanmakuById();
import requests
import json
def get_danmaku_by_url(video_url):
"""通过视频URL获取弹幕"""
try:
api_url = f"https://danmu.huaqi.pro/?url={video_url}"
response = requests.get(api_url)
response.raise_for_status()
data = response.json()
print(f"弹幕总数: {data['total']}")
print(f"前10条弹幕:")
for i, dm in enumerate(data['danmaku'][:10]):
print(f"{i+1}. [{dm['time']}s] {dm['text']} (用户: {dm['author']})")
return data
except requests.RequestException as e:
print(f"请求失败: {e}")
return None
except json.JSONDecodeError as e:
print(f"JSON解析失败: {e}")
return None
def get_danmaku_by_id(video_id):
"""通过视频ID获取弹幕"""
try:
api_url = f"https://danmu.huaqi.pro/?ac=dm&id={video_id}"
response = requests.get(api_url)
response.raise_for_status()
data = response.json()
print(f"通过ID获取弹幕数量: {data['total']}")
for dm in data['danmaku'][:5]: # 显示前5条
print(f"{dm['time']}s: {dm['text']}")
return data
except Exception as e:
print(f"获取弹幕失败: {e}")
return None
# 使用示例
if __name__ == "__main__":
# 测试不同平台
platforms = [
"https://www.bilibili.com/video/BV1xx411c7mu", # B站
"https://www.iqiyi.com/v_1jk3n2b76go.html", # 爱奇艺
"https://v.qq.com/x/cover/mzc00200mp8qiuq.html", # 腾讯视频
"https://v.youku.com/v_show/id_XNTkxMjY3NzMyOA==.html", # 优酷
"https://www.mgtv.com/b/427837/15582333.html" # 芒果TV
]
for url in platforms:
print(f"\n--- 测试平台: {url} ---")
get_danmaku_by_url(url)
# 测试ID模式
print(f"\n--- 测试ID模式 ---")
get_danmaku_by_id("BV1xx411c7mu")
baseUrl . '?url=' . urlencode($videoUrl);
return $this->makeRequest($apiUrl);
}
/**
* 通过视频ID获取弹幕
*/
public function getDanmakuById($videoId) {
$apiUrl = $this->baseUrl . '?ac=dm&id=' . urlencode($videoId);
return $this->makeRequest($apiUrl);
}
/**
* 发送HTTP请求
*/
private function makeRequest($url) {
$context = stream_context_create([
'http' => [
'timeout' => 30,
'user_agent' => 'DanmakuAPI Client 1.0'
]
]);
$response = file_get_contents($url, false, $context);
if ($response === false) {
throw new Exception("请求失败: $url");
}
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new Exception("JSON解析失败: " . json_last_error_msg());
}
return $data;
}
/**
* 格式化输出弹幕信息
*/
public function displayDanmaku($data, $limit = 10) {
echo "弹幕总数: " . $data['total'] . "\n";
echo "前{$limit}条弹幕:\n";
$count = 0;
foreach ($data['danmaku'] as $dm) {
if ($count >= $limit) break;
printf("%d. [%.1fs] %s (用户: %s)\n",
$count + 1,
$dm['time'],
$dm['text'],
$dm['author']
);
$count++;
}
echo "\n";
}
}
// 使用示例
try {
$api = new DanmakuAPI();
// 测试各平台URL模式
$testUrls = [
'B站' => 'https://www.bilibili.com/video/BV1xx411c7mu',
'爱奇艺' => 'https://www.iqiyi.com/v_1jk3n2b76go.html',
'腾讯视频' => 'https://v.qq.com/x/cover/mzc00200mp8qiuq.html',
'优酷' => 'https://v.youku.com/v_show/id_XNTkxMjY3NzMyOA==.html',
'芒果TV' => 'https://www.mgtv.com/b/427837/15582333.html'
];
foreach ($testUrls as $platform => $url) {
echo "--- 测试{$platform} ---\n";
$data = $api->getDanmakuByUrl($url);
$api->displayDanmaku($data, 5);
}
// 测试ID模式
echo "--- 测试ID模式 ---\n";
$data = $api->getDanmakuById('BV1xx411c7mu');
$api->displayDanmaku($data, 5);
} catch (Exception $e) {
echo "错误: " . $e->getMessage() . "\n";
}
?>