# Bilibili Danmaku Scraper (`romy/bilibili-danmaku-scraper`) Actor

Extract decoded Bilibili (哔哩哔哩) danmaku (bullet comments) with timestamps, color, mode, sender, and a per-video summary. One flat price per video, no per-comment surcharge. No login required.

- **URL**: https://apify.com/romy/bilibili-danmaku-scraper.md
- **Developed by:** [Romy](https://apify.com/romy) (community)
- **Categories:** Videos, Social media
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $9.36 / 1,000 video processeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Bilibili Danmaku Scraper

Extract decoded Bilibili (哔哩哔哩) danmaku (弹幕, "bullet comments" — the
scrolling on-video reactions Bilibili is known for) with full timestamp,
color, mode, and sender data, plus a per-video summary (unique senders,
peak-activity minute, time range). No login required.

### Why

Danmaku is returned by Bilibili's own API as raw Protobuf binary
(`x/v2/dm/web/seg.so`), not JSON — most scrapers either skip it entirely or
depend on a third-party protobuf library. This actor uses a hand-rolled
varint/tag decoder (no dependency) against the community-documented
`DanmakuElem`/`DmSegMobileReply` schema, ported from the mature sibling
actor `bilibili-all-in-one-api` (already live and verified on Apify),
along with its `bvid -> cid` video-info resolution.

**Pricing differentiation**: competing danmaku actors on Apify charge per
comment on top of a per-video fee (e.g. $0.00999/video + $0.00015/danmaku,
which adds up fast on a popular video with thousands of comments). This
actor charges **one flat price per video** — you get every danmaku it
finds, no matter how many, for one price.

### How it works

1. Resolves each input video (URL or bare bvid) to Bilibili's internal
   `cid` (the video-part id danmaku is actually indexed by, not the bvid).
2. Fetches danmaku in ~6-minute segments (`maxSegments` input, default 3),
   stopping early once a segment comes back empty.
3. Decodes each segment's raw Protobuf into structured JSON: `id`,
   `progressMs` (position in the video), `mode`, `fontSize`, `color`,
   `midHash` (hashed sender id), `content`, `ctime` (send time),
   `weight`, `pool`, `attr`.
4. Pushes one dataset row per video: video metadata + a summary (unique
   senders, first/last send time, the single busiest minute and its count)
   - the full decoded danmaku array.

### Input

| Field | Type | Description |
|---|---|---|
| `videos` | array of strings | Bilibili video URLs or bare bvids (required) |
| `maxSegments` | integer | Max ~6-minute segments to fetch per video (default 3, max 20) |

### Output

One dataset item per video:

```json
{
  "bvid": "BV1Q5tG6bEX3",
  "title": "...",
  "owner": "...",
  "duration": 123,
  "viewCount": 456789,
  "totalDanmakuCount": 18165,
  "fetchedDanmakuCount": 254,
  "summary": {
    "uniqueSenders": 249,
    "firstCtime": 1788404458,
    "lastCtime": 1788427409,
    "peakMinute": 0,
    "peakMinuteCount": 159
  },
  "danmaku": [
    { "id": 3203383280, "progressMs": 2067, "mode": 5, "fontSize": 25, "color": 16777215, "midHash": "432e7d85", "content": "是什么蒙蔽了我的双眼", "ctime": 1788404458, "weight": 11, "attr": 1048580 }
  ]
}
```

`totalDanmakuCount` is Bilibili's own reported count for the whole video;
`fetchedDanmakuCount` is how many this run actually pulled (limited by
`maxSegments` — raise it for very long videos).

A video that fails to resolve (bad URL/bvid, deleted video) doesn't abort
the run — it's logged and pushed as an `{ input, error }` row so a batch of
mixed-quality input doesn't lose the videos that did work.

### Pricing

Pay-per-event, one flat `video` event per successfully processed video —
no per-comment charge. See the actor's Pricing tab on Apify Console for
current tiered rates.

### Getting started

```bash
apify run
```

# Actor input Schema

## `videos` (type: `array`):

Bilibili video URLs (e.g. https://www.bilibili.com/video/BV1xx411c7XX) or bare bvids (BV1xx411c7XX).

## `maxSegments` (type: `integer`):

Each segment covers ~6 minutes of video. Increase for longer videos. Fetching stops early if a segment comes back empty.

## Actor input object example

```json
{
  "videos": [
    "https://www.bilibili.com/video/BV1GJ411x7h7"
  ],
  "maxSegments": 3
}
```

# Actor output Schema

## `dataset` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "videos": [
        "https://www.bilibili.com/video/BV1GJ411x7h7"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("romy/bilibili-danmaku-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "videos": ["https://www.bilibili.com/video/BV1GJ411x7h7"] }

# Run the Actor and wait for it to finish
run = client.actor("romy/bilibili-danmaku-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "videos": [
    "https://www.bilibili.com/video/BV1GJ411x7h7"
  ]
}' |
apify call romy/bilibili-danmaku-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,romy/bilibili-danmaku-scraper"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/y7DXy3hRHnpvQf1L0/builds/a0oL98TcNrhiM2MaI/openapi.json
