Extract structured data from Bilibili videos, UP主 profiles, and collections for content research. Powered by yt-dlp locally — no API key required.
Version: 1.0.0 Prerequisite: yt-dlp >= 2024.01.01
bash
# macOS
brew install yt-dlp
# pip
pip install yt-dlp
# Verify
yt-dlp --version
Some Bilibili content requires login (higher quality, member-only). Export cookies:
bash
yt-dlp --cookies-from-browser chrome "URL"
Extract title, UP主, stats, description, tags from a single video.
bash
yt-dlp --dump-json --skip-download "https://www.bilibili.com/video/BV_ID"
Key JSON fields:
FieldJSON pathTitle.titleUP主.uploaderUP主 ID.uploader_idUpload date.upload_date (YYYYMMDD → YYYY-MM-DD)Duration.duration (seconds → H:MM:SS)Views.view_countLikes.like_countCoins.comment_count (Bilibili maps this field)Description.descriptionTags.tags[]Thumbnail.thumbnailCategories.categories[]
Multi-part videos (分P):
Bilibili videos can have multiple parts. yt-dlp extracts each part separately:
bash
# List all parts
yt-dlp --flat-playlist --dump-json "https://www.bilibili.com/video/BV_ID"
# Extract specific part
yt-dlp --dump-json --skip-download --playlist-items 2 "https://www.bilibili.com/video/BV_ID"
bash
# List available subtitles
yt-dlp --list-subs --skip-download "https://www.bilibili.com/video/BV_ID"
# Download subtitles
yt-dlp --skip-download --write-sub --sub-lang zh-Hans \
--sub-format json3 --convert-subs srt \
-o "/tmp/bili-%(id)s.%(ext)s" "https://www.bilibili.com/video/BV_ID"
After download, read the .srt file and clean it:
^\d+$)Output format: [HH:MM:SS] subtitle text
Common language codes: zh-Hans (简体中文), zh-Hant (繁体中文), en (English), ja (日本語).
yt-dlp does not extract danmaku directly. Use the Bilibili API:
bash
# Get CID from video metadata first
yt-dlp --dump-json --skip-download "URL" | python3 -c "
import sys, json
data = json.load(sys.stdin)
print(data.get('_cid', data.get('id', 'unknown')))
"
# Then fetch danmaku XML
curl -s "https://comment.bilibili.com/{CID}.xml" -o danmaku.xml
The XML contains <d> elements with danmaku text and timing info:
time,type,fontSize,color,timestamp,pool,userHash,dmidbash
yt-dlp --flat-playlist --dump-json --playlist-end 20 \
"https://space.bilibili.com/UID/video"
Output is one JSON per line. Parse for .title, .duration, .view_count, .upload_date.
Output format: Table with columns: #, Title, Duration, Views, Date.
bash
yt-dlp --flat-playlist --dump-json \
"https://www.bilibili.com/video/BV_ID?p=1"
Or for named collections:
bash
yt-dlp --flat-playlist --dump-json \
"https://space.bilibili.com/UID/channel/collectiondetail?sid=SERIES_ID"
For Bilibili audio-only content (music区):
bash
yt-dlp --dump-json --skip-download "https://www.bilibili.com/audio/au_ID"
PatternTypebilibili.com/video/BV...Single videobilibili.com/video/av...Single video (legacy)b23.tv/SHORTCODEShort link (auto-resolves)space.bilibili.com/UID/videoUP主 video listbilibili.com/bangumi/play/...Anime / seriesbilibili.com/audio/au...Audio
= 10000 →
{n/10000:.1f}万(Chinese convention)
Otherwise → raw number
When user provides a Bilibili URL:
When user asks to download a video:
Bilibili Research Kit is an open-source project by SnapVee.