No description
Find a file
2026-03-19 15:47:16 +08:00
.vscode Fetch danmaku from ddplay 2026-03-19 11:08:23 +08:00
.gitignore Initial commit 2026-03-18 07:57:34 +00:00
danmaku_convert.py Add default shortcut for fetching and converting danmaku in one command 2026-03-19 11:29:36 +08:00
LICENSE Initial commit 2026-03-18 07:57:34 +00:00
README.md Add default shortcut for fetching and converting danmaku in one command 2026-03-19 11:29:36 +08:00
remux_mkv.py Add function to extract poster and thumbnail from video 2026-03-19 15:47:16 +08:00

danmaku-convert

Tools for:

  1. Converting DandanPlay comment JSON into a simplified array.
  2. Fetching danmaku from DandanPlay API by Bangumi.tv subject ID.

Requirements

  • Python 3.10+

Command Overview

python3 danmaku_convert.py -h

Subcommands:

  • convert: convert local JSON format.
  • fetch: fetch all episodes by Bangumi subject ID, then download selected episodes.

Convert Local JSON

python3 danmaku_convert.py convert input.json converted.json

Input format example:

{
	"count": 136,
	"comments": [
		{"cid": 1, "p": "343.15,1,16777215,6c0a879c", "m": "text"}
	]
}

Output format example:

[
	{"text": "text", "time": 343.15, "mode": 0, "color": "#FFFFFF"}
]

Fetch Danmaku by Bangumi Subject ID

The fetch flow is:

  1. Query /api/v2/bangumi/bgmtv/{subjectId} to get bangumi details and all episodes.
  2. Show all episodes and let you choose what to download.
  3. For each episode, call /api/v2/comment/{episodeId} with withRelated=true.
  4. Repeat requests with incremental from to get all comments.
  5. Merge and deduplicate comments, then write one JSON file per episode.

Interactive episode selection

python3 danmaku_convert.py fetch 975 \
	--appid "YOUR_APP_ID" \
	--appsecret "YOUR_APP_SECRET" \
	--output-dir downloads

Then input selection like 1,3-5 or all.

Non-interactive selection

python3 danmaku_convert.py fetch 975 \
	--appid "YOUR_APP_ID" \
	--appsecret "YOUR_APP_SECRET" \
	--select "1,2,4-6" \
	--output-dir downloads

Options

  • --ch-convert {0,1,2}: Chinese conversion (0 none, 1 simplified, 2 traditional).
  • --delay: delay seconds between requests while paging comments.
  • --max-rounds: max paging rounds per episode.

Default Shortcut: Fetch + Convert (No Intermediate Files)

You can now run:

python3 danmaku_convert.py 454684

This default mode will:

  1. Fetch all episodes by Bangumi subject ID.
  2. Ask you to choose episode indexes to download.
  3. Download full danmaku for selected episodes with withRelated=true.
  4. Convert directly in memory.
  5. Save only converted arrays (one JSON per episode), without raw intermediate files.

Optional credentials and tuning:

python3 danmaku_convert.py 454684 \
	--appid "YOUR_APP_ID" \
	--appsecret "YOUR_APP_SECRET" \
	--output-dir converted \
	--delay 0.2

If --appid / --appsecret is omitted, script will read env vars:

  • DANDANPLAY_APPID
  • DANDANPLAY_APPSECRET

If env vars are also empty, script will prompt for input.

Output Format (fetch)

Each episode produces one JSON file like:

{
	"subjectId": 975,
	"bangumiTitle": "Example Title",
	"episode": {
		"episodeId": 123456,
		"episodeNumber": "1",
		"episodeTitle": "Episode 1",
		"airDate": "2024-01-01T00:00:00"
	},
	"withRelated": true,
	"count": 999,
	"comments": [
		{"cid": 1, "p": "12.3,1,16777215,1001", "m": "hello"}
	]
}