What does bilibili-favorites do?
Export Bilibili favorites, classify them with ChatGPT/Claude/Gemini or other frontier LLMs, then sync the organized folders back.
Overview
This tool helps you take control of your Bilibili favorites by automatically exporting them, using a powerful LLM (like ChatGPT, Claude, or Gemini) to intelligently categorize each video based on its title and description, and then syncing the resulting folders back to your Bilibili account. The entire process is configurable, allowing you to define custom classification prompts.
Requirements
- Python 3.9+
- A Bilibili account with favorites to manage
- An API key for one of the supported LLMs (OpenAI, Anthropic, Google AI, or any compatible API)
Installation
pip install bilibili-favorites
Configuration
Create a .env file in your working directory or set the following environment variables:
BILIBILI_SESSDATA=your_bilibili_sessdata
LLM_API_KEY=your_llm_api_key
LLM_MODEL=gpt-4-turbo # or claude-3-opus-20240229, gemini-pro, etc.
Note: To obtain your Bilibili SESSDATA, log in to bilibili.com, open your browser's developer tools, go to the Application tab, find the Cookies for bilibili.com, and copy the value of the
SESSDATAcookie.
Usage
Step 1: Export all favorites
bilibili-favorites export
This will save your favorites to a local JSON file.
Step 2: Classify with an LLM
bilibili-favorites classify --prompt "Categorize these Bilibili videos into topics like technology, gaming, music, education, and entertainment. Group similar topics together."
You can also provide a custom prompt file:
bilibili-favorites classify --prompt-file my_prompt.txt
Step 3: Sync folders back to Bilibili
bilibili-favorites sync
This will create or update folders in your Bilibili account according to the LLM's classification.
Configuration Options
| Option | Description | Default |
|---|---|---|
BILIBILI_SESSDATA | Your Bilibili session cookie | Required |
LLM_API_KEY | API key for the LLM provider | Required |
LLM_MODEL | Model identifier (e.g., gpt-4-turbo, claude-3-opus-20240229, gemini-pro) | gpt-4-turbo |
LLM_BASE_URL | Base URL for the LLM API (for custom endpoints) | Optional |
OUTPUT_DIR | Directory for exported data | ./bilibili_favorites |
Custom Prompts
To tailor the classification to your needs, provide a custom prompt. The prompt should instruct the LLM on how to categorize videos. For example:
You are a Bilibili content organizer. Given the following video title and description, assign it to exactly one of these categories:
- Technology & Programming
- Gaming & Esports
- Music & Dance
- Education & Knowledge
- Entertainment & Lifestyle
- Animation & Comics
Respond with only the category name, nothing else.
Troubleshooting
- Authentication errors: Ensure your
BILIBILI_SESSDATAis correct and not expired. Re-log in to Bilibili and update it if necessary. - LLM API errors: Double-check your
LLM_API_KEYand that the model name is correct. For Claude or Gemini, verify the API endpoint. - Sync failures: Some Bilibili folders have limits on the number of videos. If a folder exceeds the limit, the sync may fail. Try reducing the number of categories or splitting large categories.
License
MIT