Skip to main content

bili23-cli

Headless CLI for downloading Bilibili videos — reuses the Bili23-Downloader GUI login session, so the CLI never asks you to log in.

Give it a Bilibili URL, get an .mp4. That's it.

bili23-cli "https://www.bilibili.com/video/BV1GE411Q7Ew/"

Why this exists

The official Bili23-Downloader is a Qt GUI app — great for clicking around, but not scriptable. The author's separate CLI repo was last published to PyPI in 2022 and is now stale (missing modern Bilibili auth: Wbi signing, buvid/ticket cookies, etc.).

bili23-cli is a modern, dependency-light rewrite that:

  • 🍪 Reuses your GUI login — reads the cookie the GUI already stored, so you get your account's quality (1080P / 4K / VIP) without logging in again.
  • 🔐 Implements current Bilibili auth — Wbi signature (w_rid), full cookie set (SESSDATA / buvid3/4 / bili_ticket / …), correct UA & Referer.
  • 🪶 Minimal dependencies — only httpx + system ffmpeg. No PySide6 / Qt.
  • 🧵 Multi-threaded — 4 MB chunked Range downloads.
  • 🎛️ Selectable quality / codec — -q 1080P -c HEVC, or auto for best-available.

Prerequisites

  1. The GUI app installed & logged in — Bili23-Downloader. Log in once; bili23-cli reads its session cookie.
    • This is how you get high quality. Anonymous use (--no-cookie) works but is limited to ~480P and some videos 403.
  2. ffmpeg on your PATH (for merging audio + video):
  3. Python ≥ 3.9.

Installation

# with uv
uv tool install bili23-cli

# or with pipx
pipx install bili23-cli

This installs the bili23-cli command globally, in an isolated environment.

From source

git clone https://github.com/1WorldCapture/bili23-cli.git
cd bili23-cli
uv tool install .     # or: pipx install .

Usage

bili23-cli <URL-or-BVid> [options]

Examples

# Simplest: download to current dir, auto best quality
bili23-cli "https://www.bilibili.com/video/BV1GE411Q7Ew/"

# Bare BV id works too
bili23-cli BV1GE411Q7Ew

# Choose quality + codec, output dir
bili23-cli BV1GE411Q7Ew -o ~/Downloads -q 1080P -c HEVC

# Multi-part video: pick part 3
bili23-cli "https://www.bilibili.com/video/BVxxxxx/" -p 3

# More threads
bili23-cli BV1GE411Q7Ew -t 16

Options

Option Description
url Bilibili video URL or bare BV id (positional)
-o, --output DIR Output directory (default: current dir)
-q, --quality auto / 8K / 杜比视界 / HDR / 4K / 1080P60 / 1080P+ / 1080P / 720P / 480P / 360P (default: auto)
-c, --codec auto / AVC / HEVC / AV1 (default: auto, prefers AVC > HEVC > AV1)
-p, --page N Part number, 1-based (default: 1)
-t, --thread N Download threads (default: 8)
--no-merge Don't merge; keep video.m4s / audio.m4s
--no-cookie Skip the GUI login cookie (anonymous; quality limited)
--keep-parts Keep .m4s parts after merge

How it works

Auth reuse (the key trick)

The GUI stores your login in (macOS) ~/Library/Application Support/Bili23 Downloader/config.json under the Cookie key. bili23-cli reads it and rebuilds the exact cookie dict the GUI sends — including SESSDATA, bili_jct, buvid3/4, bili_ticket, and the CURRENT_FNVAL=4048 flag — so the CLI looks indistinguishable from the GUI to Bilibili's servers.

On each run it also calls /x/web-interface/nav to fetch fresh Wbi signing keys (img_key / sub_key) — it does not trust the cached values, which silently expire.

Download pipeline

Only two API calls are needed:

  1. GET /x/web-interface/wbi/view?bvid=… (+ Wbi sig) → title, cid, parts
  2. GET /x/player/wbi/playurl?bvid=…&cid=…&qn=…&fnval=4048&fourk=1 (+ Wbi sig) → DASH video[] / audio[] CDN URLs

Then: multi-threaded Range download of video.m4s + audio.m4s, followed by ffmpeg -c copy into .mp4.

See docs/research-notes.md for the full reverse-engineering writeup of the GUI's internals.

Scope (v0.1)

Supported: user-uploaded videos (BV/av) — parse, quality/codec selection, multi-threaded download, merge.

Not yet: bangumi / movies / courses / audio / favorites (different APIs), danmaku / subtitles / cover / metadata, batch download, cross-process resume, login flow (by design — reuse the GUI).

Acknowledgements

This project is an independent CLI companion to — and not affiliated with — ScottSloan/Bili23-Downloader. The auth and download logic is a clean-room reimplementation based on studying that project's source.

Bilibili is a trademark of Shanghai Kuoyu Network Technology Co., Ltd. This tool is for personal use; please respect Bilibili's Terms of Service and copyright.

License

GPL-3.0

Metadata

Release files for bili23-cli 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bili23-cli 0.2.2
File Size Uploaded Provenance
bili23_cli-0.2.2.tar.gz 21.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bili23-cli 0.2.2
File Interpreter ABI Platform
bili23_cli-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 46.4 kB

Release files / bili23_cli-0.2.2.tar.gz

Download URL bili23_cli-0.2.2.tar.gz
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
1e7a28c88c4d53166ef735d0658f0f2fd2aa5b8e2698e9e17be3eacc0b92a821
BLAKE2b-256 checksum
How to use checksums
936bb5210e817d709f649af060c59a25d871d83560ec50f509b72ae8d37a6820
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / bili23_cli-0.2.2-py3-none-any.whl

Download URL bili23_cli-0.2.2-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d72c690e99fd8680e4188bb737da93f1b30a035d754e2769fc9a173f674e2ea9
BLAKE2b-256 checksum
How to use checksums
d1c422ec58411f8f9a81dca08bae4e156a483971ade0afa8b173e274c08c9624
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for bili23-cli 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page