YTB2BILI: Complete Guide to Automated YouTube to Bilibili Video Transfer System

System Overview

YTB2BILI represents a comprehensive video automation processing system specifically designed for content creators, enabling seamless video downloads from YouTube and other platforms, automatic subtitle generation, content translation, metadata creation, and scheduled uploads to Bilibili. This solution employs modular design principles, breaking down complex video processing workflows into manageable steps through an intelligent task chain processing engine, significantly enhancing content transfer efficiency.

Core Functionality Deep Dive

Intelligent Video Processing Chain

The system implements a four-step preparation workflow for real-time video processing:

  1. Subtitle Generation: Integrates Whisper AI technology to automatically recognize video speech and generate high-quality subtitle files. Supports multi-language recognition with accuracy exceeding 95%, with average processing time of 2-5 minutes depending on video length.
  2. Cover Download: Automatically retrieves original video covers, uploads them to Tencent Cloud COS storage, and generates CDN access links. Supports high-definition cover downloads, typically completing within 10-30 seconds.
  3. Subtitle Translation: Provides both Baidu Translation and DeepSeek AI translation solutions, supporting multi-language mutual translation. The translation process intelligently preserves timeline information, with average processing time of 30-60 seconds.
  4. Metadata Generation: Based on AI analysis of video content, automatically generates titles, descriptions, and tags compliant with Bilibili platform standards. The system analyzes video themes, keywords, and content features to produce optimized metadata, consuming 30-90 seconds.

Scheduled Upload Strategy

To avoid triggering platform restrictions through frequent uploads, the system employs intelligent scheduling mechanisms:

  • Video Upload: Uploads only one processed video per hour, controlling upload frequency through time intervals
  • Subtitle Upload: Delays subtitle upload by 1 hour after successful video upload, ensuring video approval
  • Manual Trigger: Provides web interface for manual control, allowing immediate upload bypassing the queue

Visual Management Panel

The system offers an intuitive web management interface featuring:

  • Video List: Real-time display of all video processing statuses with status filtering (pending/processing/completed/failed)
  • Detailed Information: Complete video information and processing step tracking, including execution time and results for each step
  • Single Step Retry: Supports individual retry of failed task steps without restarting from scratch
  • Progress Monitoring: Real-time display of processing progress percentage and elapsed execution time
  • File Management: Online viewing and download of all generated files including videos, subtitles, and covers

Bilibili Account Integration

The system deeply integrates with Bilibili’s authentication framework:

  • QR Code Login: Supports Bilibili TV version QR code for quick login
  • QR Code Generation: Backend automatically generates PNG format login QR codes
  • Status Detection: Frontend real-time polling to detect login status changes
  • User Information: Retrieves and displays username, avatar, and other account information
  • Status Persistence: Automatically saves login tokens and cookies to avoid repeated authentication
  • Login Verification: Intelligently detects account login status, prompting re-authentication when anomalies occur

Technical Architecture Analysis

Backend Technology Stack

  • Development Language: Go 1.24+, leveraging latest language features for enhanced performance
  • Web Framework: Gin high-performance HTTP framework supporting high-concurrency requests
  • Database Support: GORM v2 ORM framework compatible with MySQL 8.0+, PostgreSQL 15+, and SQLite
  • File Storage: Tencent Cloud COS object storage supporting large file multipart uploads
  • Dependency Management: Uber FX for declarative dependency injection
  • Scheduled Tasks: Robfig Cron v3 providing second-level precision task scheduling
  • Logging System: Zap + Lumberjack for structured logging and automatic rotation

Frontend Technology Stack

  • Framework: Next.js 15+ supporting App Router routing mode
  • Development Language: TypeScript 5.x ensuring type safety
  • UI Components: React 18 + Tailwind CSS 3.x responsive design
  • Icon System: Lucide React modern icon library
  • HTTP Client: Axios supporting request interception and automatic retry
  • Deployment Method: Static export + embedded deployment simplifying operations

External Service Integration

Service Name Function Description Integration Method
yt-dlp Multi-platform video download Command-line tool invocation
Whisper AI Speech recognition and subtitle generation Local model deployment
Baidu Translation API Professional machine translation RESTful API
DeepSeek AI AI translation and content generation RESTful API
Bilibili SDK Video upload and user authentication Official API
Tencent Cloud COS Object storage service SDK integration

Project Structure Explanation

ytb2bili/
├── main.go                      # Application entry point
├── Makefile                     # Automated build script
├── config.toml                  # Main configuration file
├── config.toml.example          # Configuration template
├── go.mod                       # Go module dependencies
└── README.md                    # Project documentation
internal/                        # Internal business logic
├── chain_task/                  # Task chain processing engine
│   ├── chain_task_handler.go    # Task chain executor
│   ├── upload_scheduler.go      # Upload scheduler
│   ├── handlers/                # Task processors
│   │   ├── generate_subtitles.go      # Subtitle generation
│   │   ├── translate_subtitle.go      # Subtitle translation
│   │   ├── generate_metadata.go       # Metadata generation
│   │   ├── download_img_handler.go    # Cover processing
│   │   ├── upload_to_bilibili.go      # Video upload
│   │   └── upload_subtitle_to_bilibili.go  # Subtitle upload
│   └── manager/                 # Task management
├── core/                        # Core business layer
│   ├── app_server.go            # HTTP server
│   ├── models/                  # Data models
│   ├── services/                # Business services
│   └── types/                   # Type definitions
├── handler/                     # HTTP request handlers
├── storage/                     # Storage abstraction layer
└── web/                         # Frontend resources
pkg/                             # Reusable components
├── analytics/                   # Data analytics
├── cos/                         # Tencent Cloud COS client
├── logger/                      # Logging components
├── services/                    # Common services
├── store/                       # Database operations
├── translator/                  # Translation services
└── utils/                       # Utility functions

Quick Deployment Guide

Environment Requirements

Component Version Requirement Description
Go 1.24+ Backend runtime environment
Node.js 18+ Frontend build (build-time only)
Database MySQL 8.0+/PostgreSQL 15+/SQLite Data storage
yt-dlp Latest version Video download tool (auto-installed)

One-Click Deployment Solution

# Clone project
git clone https://github.com/difyz9/ytb2bili.git
cd ytb2bili/bili-up-api
# One-click build (frontend + backend)
make build
# Start service
./bili-up-api-server

After deployment, visit http://localhost:8096 to access the complete functionality.

Configuration File Setup

  1. Copy configuration template:
cp config.toml.example config.toml
  1. Edit configuration file:
# Service configuration
listen = ":8096"
environment = "production"
debug = false
FileUpDir = "/data/ytb2bili/media"
# Database configuration
[database]
  type = "mysql"
  host = "localhost"
  port = 3306
  username = "ytb2bili"
  password = "your_password"
  database = "ytb2bili"
  timezone = "Asia/Shanghai"
# Tencent Cloud COS configuration
[TenCosConfig]
  enabled = true
  CosBucketURL = "https://your-bucket.cos.ap-guangzhou.myqcloud.com"
  CosSecretId = "YourSecretId"
  CosSecretKey = "YourSecretKey"
  CosRegion = "ap-guangzhou"
  CosBucket = "your-bucket"
  SubAppId = "YourAppId"

Database Design

Core Table Structure

Video Main Table (tb_videos):

CREATE TABLE `tb_videos` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `video_id` varchar(100) NOT NULL COMMENT 'YouTube video ID',
  `title` varchar(500) DEFAULT NULL COMMENT 'Video title',
  `description` text COMMENT 'Video description',
  `cover_url` varchar(1000) DEFAULT NULL COMMENT 'Cover image URL',
  `file_path` varchar(1000) DEFAULT NULL COMMENT 'Local file path',
  `status` varchar(20) DEFAULT '001' COMMENT 'Processing status',
  `bilibili_bvid` varchar(20) DEFAULT NULL COMMENT 'Bilibili BV number',
  `bilibili_aid` bigint DEFAULT NULL COMMENT 'Bilibili AV number',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_video_id` (`video_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Task Steps Table (task_steps):

CREATE TABLE `task_steps` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `video_id` varchar(100) NOT NULL,
  `step_name` varchar(100) NOT NULL,
  `step_order` int NOT NULL,
  `status` enum('pending','running','completed','failed','skipped') DEFAULT 'pending',
  `start_time` timestamp NULL DEFAULT NULL,
  `end_time` timestamp NULL DEFAULT NULL,
  `duration` int DEFAULT NULL COMMENT 'Execution duration (seconds)',
  `error_msg` text COMMENT 'Error message',
  `result_data` json DEFAULT NULL,
  `can_retry` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_video_step` (`video_id`,`step_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Status Flow Mechanism

The system uses six status markers to track video processing progress:

  • 001: Pending
  • 002: Processing
  • 200: Ready for upload
  • 300: Video uploaded
  • 400: Completed
  • 999: Failed
    Status transitions follow strict workflows ensuring ordered execution of processing steps.

Frequently Asked Questions

Installation and Configuration Issues

Q: What should I do if database connection fails?

  1. Check database parameters in configuration file
  2. Verify database service status: sudo systemctl status mysql
  3. Confirm user permissions: mysql -u username -p -e "SHOW DATABASES"
    Q: How do I switch to SQLite database?
    Modify configuration file:
[database]
  type = "sqlite"
  database = "./data/ytb2bili.db"

Video Processing Issues

Q: What are common causes of subtitle generation failure?

  1. Check if Whisper model is correctly installed
  2. Ensure sufficient system memory (recommended 4GB+)
  3. Review logs for specific error information
    Q: How to resolve slow video download speeds?
  4. Update yt-dlp: pip install --upgrade yt-dlp
  5. Check network connection quality
  6. Configure proxy in settings if needed
    Q: How to handle unavailable translation services?
    Baidu Translation verification:
curl -X POST "https://fanyi-api.baidu.com/api/trans/vip/translate" \
  -d "q=test&from=en&to=zh&appid=YOUR_APPID&salt=123&sign=YOUR_SIGN"

DeepSeek verification:

curl -X POST "https://api.deepseek.com/chat/completions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"model":"deepseek-chat","messages":[{"role":"user","content":"test"}]}'

Upload and Authentication Issues

Q: What to do if Bilibili login QR code doesn’t display?

  1. Check if service port is properly open: netstat -tulpn | grep 8096
  2. Verify interface response: curl http://localhost:8096/api/v1/auth/qrcode
  3. Confirm firewall settings allow access
    Q: How to handle upload restrictions?
    The system has built-in intelligent scheduling:
  • Automatically controls upload frequency (1 video per hour)
  • 1-hour interval between video and subtitle uploads
  • Supports manual trigger for emergency uploads

Production Deployment Recommendations

Docker Deployment Solution

Create docker-compose.yml:

version: '3.8'
services:
  ytb2bili:
    image: ytb2bili:latest
    ports:
      - "8096:8096"
    volumes:
      - ./config.toml:/app/config.toml
      - ./data:/data/ytb2bili
    environment:
      - CONFIG_FILE=/app/config.toml
    depends_on:
      - mysql
    restart: unless-stopped
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_DATABASE: ytb2bili
      MYSQL_USER: ytb2bili
      MYSQL_PASSWORD: app_password
    volumes:
      - mysql_data:/var/lib/mysql
    restart: unless-stopped
volumes:
  mysql_data:

Start command:

docker-compose up -d

Nginx Reverse Proxy Configuration

server {
    listen 443 ssl http2;
    server_name your-domain.com;
    
    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;
    
    client_max_body_size 10G;
    
    location / {
        proxy_pass http://localhost:8096;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        proxy_connect_timeout 300s;
        proxy_send_timeout 300s;
        proxy_read_timeout 300s;
    }
}

Monitoring and Maintenance

Log Monitoring:

# Real-time application log viewing
tail -f logs/app.log
# Error log filtering
grep "ERROR" logs/app.log

Performance Analysis:

# HTTP request analysis
curl -w "@curl-format.txt" -s -o /dev/null http://localhost:8096/api/v1/videos
# Memory analysis
go tool pprof http://localhost:8096/debug/pprof/heap

Regular Maintenance Tasks:

  1. Weekly temporary file cleanup: find /data/ytb2bili -name "*.tmp" -delete
  2. Monthly database backup: mysqldump -u root -p ytb2bili > backup.sql
  3. Quarterly dependency updates: go mod tidy && go mod download

System Extensibility

Supported Video Platforms

Through yt-dlp integration, the system supports the following platforms:

  • YouTube
  • TikTok
  • Instagram
  • Twitter
  • Bilibili
  • And 1000+ additional websites

Translation Service Extension

The system adopts modular translation architecture:

// Currently supported services
type Translator interface {
    Translate(text string, from string, to string) (string, error)
}
// Easy to extend new services
type GoogleTranslator struct {}
func (g *GoogleTranslator) Translate(text, from, to string) (string, error) {
    // Implementation logic
}

Storage Solution Extension

Besides Tencent Cloud COS, the system reserves storage interfaces:

type Storage interface {
    Upload(file io.Reader, key string) error
    Download(key string) (io.ReadCloser, error)
    GetURL(key string) string
}

Easy to extend support for:

  • Alibaba Cloud OSS
  • AWS S3
  • Self-hosted MinIO

Conclusion

The YTB2BILI system achieves full-process automation from video download to platform upload through its intelligent task chain processing engine. Its modular architecture design ensures system scalability and maintainability, while the visual management panel significantly reduces the usage threshold. Whether for individual content creators or team operations, this system can markedly improve video processing efficiency and reduce repetitive labor.
The system employs a modern technology stack with Go backend and Next.js frontend, ensuring high performance and excellent user experience. Through scheduled upload strategies and intelligent error handling mechanisms, it effectively addresses platform restriction issues. Comprehensive database design and status management systems ensure processing reliability and traceability.
For users requiring large-scale video content processing, the system provides Docker deployment solutions and Nginx proxy configurations supporting high-availability production environments. Rich logging and monitoring features make system operations more convenient.