# public-clis/bilibili-cli architecture

> Architecture diagram of the GitHub repository public-clis/bilibili-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/public-clis/bilibili-cli
- Repository: https://github.com/public-clis/bilibili-cli

## Overview

bilibili-cli is a terminal interface to Bilibili: a user invokes a registered command, the command validates inputs and authentication as needed, fetches or changes Bilibili data through the API client, then renders it or emits normalized structured output. Major branches cover account/authentication, video and audio, discovery/search, collections and dynamics, and interactions. Shared command helpers bridge async calls and handle errors; payload and formatter modules shape results. The graph reflects the provided excerpts and README; some command-to-client details rely on documented capabilities rather than sampled implementation.

Main entry points: [`bili_cli/cli.py`](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/cli.py) (Command registry), [`bili_cli/client.py`](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/client.py) (Bilibili API client), [`bili_cli/commands/video.py`](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/video.py) (Video commands), [`bili_cli/payloads.py`](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/payloads.py) (Payload normalization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI entry"]
  node_cli["Command registry<br/>[cli.py]"]
end

subgraph group_identity["Account and auth"]
  node_account["Account commands<br/>[account.py]"]
  node_auth["Credential strategy<br/>[auth.py]"]
  node_credential_file["Saved credentials<br/>[auth.py]"]
  node_browser_cookies["Browser cookies"]
  node_qr_login["QR login service"]
end

subgraph group_content["Video and audio"]
  node_video["Video commands<br/>[video.py]"]
  node_audio["Audio extraction<br/>[audio.py]"]
  node_audio_lib["Audio processing"]
end

subgraph group_discovery["Discovery and users"]
  node_user_search["User and search<br/>[user_search.py]"]
  node_discovery_cmd["Hot and ranking<br/>[discovery.py]"]
end

subgraph group_activity["Collections and actions"]
  node_collections["Collections and dynamics<br/>[collections.py]"]
  node_interactions["User interactions<br/>[interactions.py]"]
end

subgraph group_shared["Shared services"]
  node_common["Command helpers<br/>[common.py]"]
  node_client["Bilibili API client<br/>[client.py]"]
  node_payloads["Payload normalization<br/>[payloads.py]"]
  node_formatter["Output formatting<br/>[formatter.py]"]
end

node_user(("Terminal user"))
node_bilibili["Bilibili services"]

node_user -->|"invokes"| node_cli
node_cli -->|"registers"| node_account
node_cli -->|"registers"| node_video
node_cli -->|"registers"| node_audio
node_cli -->|"registers"| node_user_search
node_cli -->|"registers"| node_discovery_cmd
node_cli -->|"registers"| node_collections
node_cli -->|"registers"| node_interactions
node_account -->|"uses helpers"| node_common
node_account -->|"requests credentials"| node_auth
node_auth -->|"loads and saves"| node_credential_file
node_auth -->|"extracts cookies"| node_browser_cookies
node_account -->|"starts login"| node_qr_login
node_auth -->|"generates QR"| node_qr_login
node_video -->|"fetches video data"| node_client
node_video -->|"runs requests"| node_common
node_video -->|"normalizes results"| node_payloads
node_audio -->|"downloads audio"| node_client
node_audio -.->|"extracts segments"| node_audio_lib
node_user_search -->|"searches and fetches"| node_client
node_user_search -->|"normalizes results"| node_payloads
node_discovery_cmd -->|"fetches rankings"| node_client
node_discovery_cmd -->|"normalizes results"| node_payloads
node_collections -->|"fetches and changes"| node_client
node_collections -->|"normalizes results"| node_payloads
node_interactions -->|"submits actions"| node_client
node_interactions -->|"normalizes results"| node_payloads
node_client -->|"calls API"| node_bilibili
node_common -->|"formats output"| node_formatter
node_video -->|"renders output"| node_formatter
node_client -.->|"raises errors"| node_common

click node_cli "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/cli.py"
click node_account "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/account.py"
click node_auth "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/auth.py"
click node_credential_file "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/auth.py"
click node_video "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/video.py"
click node_audio "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/audio.py"
click node_user_search "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/user_search.py"
click node_discovery_cmd "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/discovery.py"
click node_collections "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/collections.py"
click node_interactions "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/interactions.py"
click node_common "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/common.py"
click node_client "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/client.py"
click node_payloads "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/payloads.py"
click node_formatter "https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/formatter.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_user toneBlue
class node_account,node_auth,node_credential_file,node_browser_cookies,node_qr_login toneAmber
class node_video,node_audio,node_audio_lib toneMint
class node_user_search,node_discovery_cmd toneRose
class node_collections,node_interactions,node_bilibili toneIndigo
class node_common,node_client,node_payloads,node_formatter toneTeal
```

## Components

### CLI entry

- [Command registry](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/cli.py): `bili_cli/cli.py`

### Account and auth

- [Account commands](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/account.py): `bili_cli/commands/account.py`
- [Credential strategy](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/auth.py): `bili_cli/auth.py`
- [Saved credentials](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/auth.py): `bili_cli/auth.py`
- **Browser cookies**
- **QR login service**

### Video and audio

- [Video commands](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/video.py): `bili_cli/commands/video.py`
- [Audio extraction](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/audio.py): `bili_cli/commands/audio.py`
- **Audio processing**

### Discovery and users

- [User and search](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/user_search.py): `bili_cli/commands/user_search.py`
- [Hot and ranking](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/discovery.py): `bili_cli/commands/discovery.py`

### Collections and actions

- [Collections and dynamics](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/collections.py): `bili_cli/commands/collections.py`
- [User interactions](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/interactions.py): `bili_cli/commands/interactions.py`

### Shared services

- [Command helpers](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/commands/common.py): `bili_cli/commands/common.py`
- [Bilibili API client](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/client.py): `bili_cli/client.py`
- [Payload normalization](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/payloads.py): `bili_cli/payloads.py`
- [Output formatting](https://github.com/public-clis/bilibili-cli/blob/main/bili_cli/formatter.py): `bili_cli/formatter.py`

### Other components

- **Terminal user**
- **Bilibili services**

## Connections

- Terminal user → Command registry: invokes (evidence: `README.md`)
- Command registry → Account commands: registers (evidence: `bili_cli/cli.py`)
- Command registry → Video commands: registers (evidence: `bili_cli/cli.py`)
- Command registry → Audio extraction: registers (evidence: `bili_cli/cli.py`)
- Command registry → User and search: registers (evidence: `bili_cli/cli.py`)
- Command registry → Hot and ranking: registers (evidence: `bili_cli/cli.py`)
- Command registry → Collections and dynamics: registers (evidence: `bili_cli/cli.py`)
- Command registry → User interactions: registers (evidence: `bili_cli/cli.py`)
- Account commands → Command helpers: uses helpers (evidence: `bili_cli/commands/account.py`)
- Account commands → Credential strategy: requests credentials
- Credential strategy → Saved credentials: loads and saves (evidence: `bili_cli/auth.py`)
- Credential strategy → Browser cookies: extracts cookies (evidence: `bili_cli/auth.py`)
- Account commands → QR login service: starts login (evidence: `bili_cli/commands/account.py`)
- Credential strategy → QR login service: generates QR (evidence: `bili_cli/auth.py`)
- Video commands → Bilibili API client: fetches video data (evidence: `bili_cli/commands/video.py`)
- Video commands → Command helpers: runs requests (evidence: `bili_cli/commands/video.py`)
- Video commands → Payload normalization: normalizes results (evidence: `bili_cli/commands/video.py`)
- Audio extraction → Bilibili API client: downloads audio (evidence: `README.md`)
- Audio extraction → Audio processing: extracts segments (evidence: `README.md`)
- User and search → Bilibili API client: searches and fetches (evidence: `bili_cli/commands/user_search.py`)
- User and search → Payload normalization: normalizes results (evidence: `bili_cli/commands/user_search.py`)
- Hot and ranking → Bilibili API client: fetches rankings (evidence: `bili_cli/commands/discovery.py`)
- Hot and ranking → Payload normalization: normalizes results (evidence: `bili_cli/commands/discovery.py`)
- Collections and dynamics → Bilibili API client: fetches and changes (evidence: `README.md`)
- Collections and dynamics → Payload normalization: normalizes results (evidence: `bili_cli/commands/collections.py`)
- User interactions → Bilibili API client: submits actions (evidence: `bili_cli/commands/interactions.py`)
- User interactions → Payload normalization: normalizes results (evidence: `bili_cli/commands/interactions.py`)
- Bilibili API client → Bilibili services: calls API (evidence: `README.md`)
- Command helpers → Output formatting: formats output (evidence: `bili_cli/commands/common.py`)
- Video commands → Output formatting: renders output (evidence: `bili_cli/commands/video.py`)
- Bilibili API client → Command helpers: raises errors (evidence: `bili_cli/commands/common.py`)
