Skip to content

A powerful CLI tool to download videos and images from Douyin (TikTok China) with metadata extraction, automatic concurrency optimization

Notifications You must be signed in to change notification settings

3ai92/douyin-cli

Repository files navigation

Douyin CLI 🎬

A powerful command-line tool to download videos and images from Douyin (TikTok China) with automatic metadata extraction, intelligent concurrency optimization, and a beautiful terminal UI.

📦 Installation

Prerequisites

  • Node.js >= 18.0.0
  • npm or yarn

Install

npm install

🚀 Usage

Interactive Mode

Run without arguments to enter interactive mode:

npm start
# or
tsx main.ts

You'll be prompted to:

  1. Choose input source (URL or File)
  2. Enter URL or file path
  3. Choose output type (Download or JSON)
  4. Configure output directory/path

📁 Output Structure

Download Mode

downloads/
├── 2024-11-22_16-30-45/
│   ├── 7568455934909926699.mp4
│   ├── 1234567890123456789.mp4
│   └── metadata/
│       └── download_1700656245000.json
└── 2024-11-22_17-15-20/
    ├── ...

JSON Output

When exporting JSON, files are named using video IDs:

  • Single video: {video_id}.json
  • Multiple videos: output.json (or custom name)

📊 Metadata Structure

{
  "index": 1,
  "media": {
    "type": "video",
    "video_id": "7568455934909926699",
    "original_url": "https://www.douyin.com/video/...",
    "download_url": "https://...",
    "like": 12345,
    "comment": 678,
    "share": 90,
    "save": 234,
    "video_desc": "Video description",
    "create_at": "2024-11-22 16:30:45"
  },
  "user": {
    "username": "user123",
    "name": "User Name",
    "bio": "User bio",
    "user_id": "123456789",
    "sec_uid": "MS4wLjABAAAA..."
  },
  "user_videos": [
    {
      "video_id": "1234567890",
      "desc": "Video description",
      "like": 1000,
      "comment": 50,
      "create_at": "2024-11-22 16:30:45",
      "original_url": "https://..."
    }
  ]
}

⚙️ Configuration

Auto-Optimized Concurrency

The tool automatically calculates optimal concurrency based on:

  • CPU Cores: Number of available CPU cores
  • Memory Usage: Current system memory usage
  • Rules:
    • Memory < 50%: CPU cores × 2 (max 10)
    • Memory < 70%: CPU cores
    • Memory ≥ 70%: CPU cores ÷ 2 (min 2)

You can override this with --concurrency option.

📝 Notes

  • The tool automatically removes duplicate URLs
  • Downloads are organized by timestamp for easy management
  • Metadata includes original URLs, user information, and video statistics
  • User video lists are automatically fetched when sec_uid is available
  • JSON files are named using video IDs for single video exports

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

ISC

👤 Author

batd.ain.92@gmail.com


Made with ❤️ for downloading Douyin content

About

A powerful CLI tool to download videos and images from Douyin (TikTok China) with metadata extraction, automatic concurrency optimization

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published