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. Provides timestamps and user data for each comment.

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 main handler for the get_danmaku tool, decorated with @mcp.tool for registration. It handles input URL, extracts BV id and CID, calls the helper to fetch danmaku, and returns the list or appropriate error messages. The docstring and type hints provide the schema.
    @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 performs the actual API request to Bilibili's danmaku endpoint, parses the XML response using ElementTree, extracts danmaku texts, 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}'}
  • API endpoint constant for fetching danmaku data.
    API_GET_DANMAKU = "https://api.bilibili.com/x/v1/dm/list.so"

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