Douyin TikTok Download API

repository·main·Indexed 12 days ago

https://github.com/evil0ctal/douyin_tiktok_download_api

A high-performance asynchronous API and toolset for scraping and downloading watermark-free videos and data from Douyin, TikTok, and Bilibili. Built with FastAPI and HTTPX, it includes a Python library (douyin-tiktok-scraper), a PyWebIO web interface, and a Chrome Cookie Sniffer extension for capturing necessary authentication cookies. Supports various URL formats, batch parsing, and deployment via Docker Compose or Linux one-click scripts.

Tokens
5K
Snippets
18
Records
34
Agent score
97%

What's inside Douyin TikTok Download API

  1. Overview of Douyin_TikTok_Download_API

    main

    Douyin_TikTok_Download_API is a high-performance asynchronous data crawling tool designed for Douyin, TikTok, and Bilibili. It provides capabilities for online batch parsing and downloading of videos or photo albums without watermarks.

    Developers can use it in three primary ways:

    1. As a library: Import and use scraper.py or install the douyin-tiktok-scraper PyPI package.
    2. As a self-hosted API: Deploy the project on a private server to access its parsing and downloading endpoints.
    3. Via Web Interface: Use the built-in web application for manual batch analysis and downloading.

    The project is built using PyWebIO, FastAPI, and HTTPX.

  2. Understand the project architecture and components

    main

    The project is organized into three main functional areas:

    • /crawlers: Handles requests to different platform APIs (Douyin, TikTok, Bilibili, Hybrid) and returns processed data as dictionaries (dict). It is fully asynchronous and uses HTTPX.
    • /app/api: A FastAPI implementation that receives request parameters, uses the Crawlers classes to process data, and returns results in JSON format. This is used for video downloads and iOS Shortcut integrations.
    • /app/web: A simple web interface built with PyWebIO that allows users to input values via a browser and view the processed data from the Crawlers classes.
  3. Configure Douyin Cookies for self-hosted deployment

    main
    Due to Douyin's risk control mechanisms, if you are deploying this project on a private server, you must obtain a valid Cookie from the Douyin website using a browser and replace the existing one in config.yaml to ensure the service remains functional.
  4. Install Chrome Cookie Sniffer

    main

    To install the extension, download the source code via Git or as a ZIP file, then load it into Chrome using Developer Mode:

    1. Download Source:

      git clone <repository-url>

      (Or unzip the downloaded ZIP file).

    2. Enable Developer Mode: Open chrome://extensions/ in Chrome and toggle the "Developer mode" switch in the top right.

    3. Load Extension: Click "Load unpacked" and select the chrome-cookie-sniffer folder.

    4. Verify: Ensure "Cookie Sniffer" appears in your extension list and the icon is visible in your toolbar.

    git clone <repository-url>
  5. Use Chrome Cookie Sniffer to capture cookies

    main

    The extension automatically intercepts cookies from POST/GET requests on supported sites (like douyin.com).

    1. Capture: Visit a supported website and browse normally to trigger network requests.
    2. View: Click the extension icon in the browser toolbar to see the captured cookies in a card list.
    3. Manage:
      • Copy: Click the copy button on a card to copy the cookie string to your clipboard.
      • Delete: Remove individual service cookies or clear all data.
      • Export: Export all captured data as a JSON file.
  6. Deploy on Linux using the one-click script

    main

    The project provides a shell script for one-click deployment on Ubuntu 20.04 LTS. It is recommended to deploy on a US-based server to avoid potential bugs.

    Installation:

    wget -O install.sh https://raw.githubusercontent.com/Evil0ctal/Douyin_TikTok_Download_API/main/bash/install.sh && sudo bash install.sh

    Service Management:

    • Start: sudo systemctl start Douyin_TikTok_Download_API.service
    • Stop: sudo systemctl stop Douyin_TikTok_Download_API.service
    • Enable at boot: sudo systemctl enable Douyin_TikTok_Download_API.service
    • Disable at boot: sudo systemctl disable Douyin_TikTok_Download_API.service

    Updating the project: To update, run the update.sh script located in the project's bash directory:

    cd /www/wwwroot/Douyin_TikTok_Download_API/bash && sudo bash update.sh
  7. Install the `douyin-tiktok-scraper` Python library

    main

    You can import the parsing logic directly into your Python projects using the available PyPI package. Note that this library is currently marked as obsolete and may require updates.

    To install the package, use pip install douyin-tiktok-scraper.

    pip install douyin-tiktok-scraper
  8. Configure Webhook callbacks

    main

    You can configure the extension to automatically push updated cookies to a specified URL via a POST request.

    1. Open the extension popup.
    2. Enter your callback URL in the input field at the top.
    3. Click the "🔧 Test" button to verify the connection.

    Webhook Data Format: When a cookie is updated, the extension sends a JSON payload to your URL:

    {
      "service": "douyin",
      "cookie": "具体的Cookie字符串",
      "timestamp": "2025-08-29T12:34:56.789Z"
    }

    During a test connection, the payload includes additional fields:

    {
      "test": true,
      "message": "这是一个测试回调..."
    }
  9. Deploy via Linux one-click script

    main

    For Ubuntu 20.04 LTS, you can use the provided installation script. It is recommended to deploy on a US-based server to avoid bugs.

    Install the service:

    wget -O install.sh https://raw.githubusercontent.com/Evil0ctal/Douyin_TikTok_Download_API/main/bash/install.sh && sudo bash install.sh

    Service Management:

    • Start: sudo systemctl start Douyin_TikTok_Download_API.service
    • Stop: sudo systemctl stop Douyin_TikTok_Download_API.service
    • Enable on boot: sudo systemctl enable Douyin_TikTok_Download_API.service
    • Disable on boot: sudo systemctl disable Douyin_TikTok_Download_API.service

    Update the project: Navigate to the project bash directory and run the update script:

    cd /www/wwwroot/Douyin_TikTok_Download_API/bash && sudo bash update.sh
  10. Deploy via Docker

    main

    Docker is the recommended deployment method for ensuring environment consistency and isolation. Ensure your server has network access to Douyin or TikTok to avoid issues.

    Quick Start

    1. Pull the image: docker pull evil0ctal/douyin_tiktok_download_api:latest
    2. Run the container: docker run -d --name douyin_tiktok_api -p 80:80 evil0ctal/douyin_tiktok_download_api
    3. Verify: Run docker ps to confirm the douyin_tiktok_api container is active.
    4. Access: Use http://localhost (or your server's IP) to access the API or Web interface.

    Advanced Configuration

    You can customize the deployment using volume mounts for data persistence and environment variables:

    docker run -d --name douyin_tiktok_api -p 80:80 \
      -v /path/to/your/data:/data \
      -e MY_ENV_VAR=my_value \
      evil0ctal/douyin_tiktok_download_api
    • -v /path/to/your/data:/data: Mounts a local directory to /data inside the container.
    • -e MY_ENV_VAR=my_value: Sets an environment variable.
    docker run -d --name douyin_tiktok_api -p 80:80 evil0ctal/douyin_tiktok_download_api