Skip to main content
Glama
lesir831

Bilibili Video Info MCP

by lesir831

get_danmaku

Extract bullet comments from Bilibili videos to analyze viewer engagement and feedback. Provide the video URL to retrieve danmaku with content, timestamps, and user details.

Instructions

Get danmaku (bullet comments) from a Bilibili video

Args: url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN Returns: List of danmaku (bullet comments) with content, timestamp and user information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • The MCP tool handler for 'get_danmaku'. It processes the input URL, extracts BVID, fetches video basic info to get CID, calls the helper to get danmaku list, handles errors, and returns the result.
    @mcp.tool( annotations={ "title": "获取视频弹幕", "readOnlyHint": True, "openWorldHint": False } ) async def get_danmaku(url: str) -> list: """Get danmaku (bullet comments) from a Bilibili video Args: url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN Returns: List of danmaku (bullet comments) with content, timestamp and user information """ bvid = bilibili_api.extract_bvid(url) if not bvid: return [f"错误: 无法从 URL 提取 BV 号: {url}"] aid, cid, error = bilibili_api.get_video_basic_info(bvid) if error: return [f"获取视频信息失败: {error['error']}"] danmaku, error = bilibili_api.get_danmaku(cid) if error: return [f"获取弹幕失败: {error['error']}"] if not danmaku: return ["该视频没有弹幕"] return danmaku
  • Supporting helper function that makes API request to fetch danmaku XML for a given CID, parses the XML using ElementTree, extracts text from 'd' elements, and returns the list or error.
    def get_danmaku(cid): """Fetches danmaku for a given cid.""" headers = _get_headers() danmaku_list = [] try: params_danmaku = {'oid': cid} response_danmaku = requests.get(API_GET_DANMAKU, params=params_danmaku, headers=headers) danmaku_content = response_danmaku.content.decode('utf-8', errors='ignore') root = ET.fromstring(danmaku_content) for d in root.findall('d'): danmaku_list.append(d.text) return danmaku_list, None except (requests.RequestException, ET.ParseError) as e: return [], {'error': f'Failed to get or parse danmaku: {e}'}
  • Docstring defining input (url: str) and output (list) schema for the tool, including example and description.
    """Get danmaku (bullet comments) from a Bilibili video Args: url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN Returns: List of danmaku (bullet comments) with content, timestamp and user information """
  • Registration of the 'get_danmaku' tool using @mcp.tool decorator with metadata annotations.
    @mcp.tool( annotations={ "title": "获取视频弹幕", "readOnlyHint": True, "openWorldHint": False } )
  • API endpoint constant used by the get_danmaku helper.
    API_GET_DANMAKU = "https://api.bilibili.com/x/v1/dm/list.so"
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lesir831/bilibili-video-info-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server