Preface¶
When organizing knowledge, summarizing long videos, or creating derivative works in DSH, a common practice is to manually copy closed captions (CC) or run a separate download script and then convert to Markdown. Platform subtitles often require signing in to retrieve the API URL, and when there is no subtitle track you may need a separate ASR. Export formats, cleaning, and timeline alignment each come with their own tooling. The community plugin dsh-bilibili-subtitles (maintainer: Chenfan2; category: Network tools) bundles fetch subtitles → clean → multi-format output → quality report into a single pipeline, and can be installed in the DSH desktop app or a Web/CLI profile.
What this is¶
dsh-bilibili-subtitles works with Bilibili links, local videos, or existing subtitle files: it prioritizes external subtitles and Bilibili platform/CC/AI subtitles, and falls back to embedded tracks, hardcoded-subtitle OCR, or Whisper ASR when those are unavailable. Output can be Markdown, Word (.docx), PDF, TXT, SRT, and structured JSON, with a quality report covering coverage and other metrics.
Repository and documentation: GitHub; community catalog: SkillHub plugin entry. The current version in package.json is 0.2.0, license MIT. The plugin runs with the permissions of the current DSH process; review the source code and license before installing.
Core features¶
Inputs and subtitle sources¶
- Bilibili links: BV/av, multi-part videos, episodes (ep/ss), b23.tv short links; use
--pages auto/all/1,3-5for multi-part videos. - Local: video files with an external subtitle via
--subtitle, or embedded subtitles, OCR, or ASR pipelines. - Source priority (as described in the README): external SRT/VTT/ASS/Bilibili JSON → platform/CC/AI subtitles → local embedded → hardcoded-subtitle OCR → Whisper ASR.
Documents and cleaning¶
- Formats:
--formatsupports combinations ofmd,docx,pdf,txt,srt,json. - Cleaning: deduplication, ad/watermark filtering, merging short sentences, segmentation by semantics/pauses, glossary (
--glossary), and preservation of speaker labels. - Bilingual:
--bilingualaligns two subtitle tracks by timestamp; a two-line single track can be auto-split. - Quality report: generates
*.quality.jsonincluding coverage, overlap, low confidence, garbled text, and abnormal speech rate;statusisok/warn/fail, and the tool does not pretend success when it fails.
Environment and optional dependencies¶
- Python 3.10+; core dependencies are from the standard library; DOCX requires
python-docx. - Optional:
faster-whisper(ASR), LibreOffice orreportlab(PDF),rapidocr_onnxruntime+ ffmpeg (OCR), ffmpeg (embedded subtitles/frame extraction;imageio-ffmpegcan also be used).
Within DSH, prefer the Python provided by load_workspace_dependencies (bundles python-docx); optional packages such as those for ASR/PDF can be installed into the workspace and imported via PYTHONPATH.
Installation and enabling¶
DSH desktop app: Sidebar → “Plugins” → “Add plugin” → paste the repository URL:
https://github.com/Chenfan2/dsh-bilibili-subtitles
Web / CLI profile (command as in the README):
dsh plugin --profile web add github:Chenfan2/dsh-bilibili-subtitles
Skill only, no plugin UI required: copy the plugin directory to $DSH_HOME/skills/dsh-bilibili-subtitles, or extract the corresponding zip into that path.
When running the Python entry point directly, you can execute in the plugin directory:
pip install -r requirements.txt
# Optional
pip install faster-whisper reportlab imageio-ffmpeg rapidocr_onnxruntime
package.json requires Node >=22 and DSH >=0.2.0-rc.2 <0.3.0-0.
Typical usage¶
Exporting platform subtitles¶
Bilibili only returns the subtitle_url for platform/AI subtitles under a signed-in session. Recommended: set the environment variable BILIBILI_SESSDATA (do not commit it to the repository or share it with others; the tool does not write cookies into logs or the quality report):
$env:BILIBILI_SESSDATA = "your SESSDATA"
python main.py "https://www.bilibili.com/video/BV1xx411c7mD" --format md,docx
You can also use --sessdata, --cookie, or --cookies cookies.txt. Without signing in, platform subtitles will report LOGIN_REQUIRED; if faster-whisper is installed, add --asr for a speech-to-text fallback, or supply --subtitle.
Command examples¶
# Platform subtitles → Markdown + Word
python main.py "https://www.bilibili.com/video/BV1xx411c7mD" --format md,docx
# Specify output file
python main.py "BV1xx411c7mD" --format docx -o "笔记.docx"
# Local video + external subtitle
python main.py input.mp4 --subtitle input.srt --format md,docx
# Batch a directory
python main.py ./videos --format md,docx --out-dir output/batch
The default output directory is output/. Typical artifacts per video include <title>_<BV>.md, .docx, .quality.json, and .segments.json; batch tasks additionally write _manifest.json.
Commonly used parameters (excerpt): --timestamps / --no-timestamps, --merge-sentences, --title, --template, --asr-model small, --ocr (local hardcoded subtitles), --json-summary (machine-readable summary to stdout). See python main.py --help for the full list.
Failure degradation and exit codes¶
Degradation order as specified in the README includes: if external subtitle parsing fails, continue with platform/embedded; if sign-in is required, prompt for SESSDATA and allow ASR as a fallback when permitted; if there is no subtitle track, report NO_SUBTITLE; if one format fails to render, other formats continue. In batch runs, a single failure does not affect already succeeded items; errors are recorded in *.error.json and the manifest.
Exit codes: 0 success, 2 input/API/parsing, 3 no subtitles/sign-in required/quality failure, 4 missing dependency, 5 rendering failure, 1 unexpected error.
Use cases and notes¶
Fits: scenarios where you need to turn Bilibili or local video subtitles into notes, deliverables (Word/PDF), or searchable Markdown, or need SRT/JSON for downstream pipelines; you want a single command with a quality report and directory batching.
Limitations (per the README): platform subtitles are subject to video, account, region, and uploader settings; AI subtitles may contain errors and timestamp drift; bilingual is timestamp alignment, not translation; OCR is for local videos only and is experimental; ASR for long videos is slow; the small model is about 460 MB on first download. Only process videos and subtitles you have rights to use; output preserves title, uploader, and link for traceability.
The DSH ecosystem emphasizes “everything is a plugin”; SkillHub is a community directory and is not officially affiliated with DeepSeek / 幻方.
Wrap-up¶
dsh-bilibili-subtitles unifies multiple Bilibili and local subtitle sources into deliverable documents, and provides clear errors and degradation paths for situations like sign-in requirements, missing tracks, and missing dependencies. For installation or to review changes, refer to the GitHub repository and the installation commands above.