Skip to main content

A Python tool to programmatically edit CapCut project files via JSON manipulation.

Project description

๐Ÿงž CapGenie: Your CapCut Project Wizard ๐Ÿช„

CapGenie is a Python package that empowers you to programmatically create, load, and modify CapCut project files. It works by giving you direct control over the underlying JSON data that defines your CapCut projects, allowing for powerful automation and manipulation.

Perfect for developers, content creators, and AI agents looking to automate video editing workflows!

โœจ Features

  • ๐Ÿš€ Initialize New Projects: Spin up a complete CapCut project folder structure from scratch.
  • ๐Ÿ“‚ Load & Edit Existing Projects: Seamlessly open and make changes to your current CapCut projects.
  • ๐Ÿ”ง Direct JSON Control: Access and modify all key JSON files within a project (e.g., draft_content.json).
  • ๐Ÿ”„ Simplified JSON Sync:
    • Export project timelines to a user-friendly, simplified JSON format.
    • Modify this JSON (manually or programmatically).
    • Import the changes back into your CapCut project, updating the timeline.
  • ๐Ÿ“ Easy File Management: List project files and folders with ease.
  • ๐Ÿค– AI-Ready: Designed to be easily integrated into workflows where an AI agent modifies project parameters.

โš™๏ธ Installation

You can install CapGenie using pip:

pip install capgenie

(Note: CapGenie will be available on PyPI once published. For now, you can install it locally as described in the development setup.)

๐Ÿš€ Quick Start

Here's how to get started with CapGenie:

from capgenie import Project, CapCutFileManager # Assuming CapCutFileManager is also for public use

# --- Option 1: Create a brand new CapCut project ---
# CapGenie will set up the necessary folder structure.
new_project_path = r'C:\\path\\to\\your\\new_capcut_project_folder'
project = Project(project_path=new_project_path, create_new=True)
print(f"๐ŸŽ‰ New project created at: {new_project_path}")

# --- Option 2: Load an existing CapCut project ---
# Point to the root folder of your CapCut project (e.g., 'com.lveditor.draft')
existing_project_path = r'C:\\Users\\YourName\\AppData\\Local\\CapCut\\User Data\\Projects\\com.lveditor.draft\\your_project_id_folder'
project = Project(project_path=existing_project_path)
print(f"๐ŸŽฌ Loaded project: {project.project_path}")

# --- Working with the Simplified Project JSON ---

# 1. Export the project's timeline to a simplified JSON
simplified_json_path = r'C:\\path\\to\\your\\project_timeline.json'
project.export_to_simplified_json(simplified_json_path)
print(f"๐Ÿ“„ Project timeline exported to: {simplified_json_path}")

# Now, you (or an AI agent!) can open 'project_timeline.json' and modify it.
# See the "Simplified JSON Structure" section below for details.

# 2. Synchronize changes from the simplified JSON back to the CapCut project
project.sync_from_simplified_json(simplified_json_path)
print(f"๐Ÿ”„ Project timeline updated from: {simplified_json_path}")

# --- Direct JSON File Manipulation (Advanced) ---
# You can also directly access and modify specific CapCut JSON files.

# Example: Load, modify, and save 'draft_content.json'
draft_content = project.load_json('draft_content.json')
if draft_content:
    # Make your changes to the draft_content dictionary
    # For example, let's assume we're changing the overall project duration (this is a hypothetical example)
    # draft_content['duration'] = 120000000 # Example: 120 seconds
    print("๐Ÿ” Loaded draft_content.json")
    project.save_json('draft_content.json', draft_content)
    print("๐Ÿ’พ Saved changes to draft_content.json")
else:
    print("โš ๏ธ Could not load draft_content.json")

# List files and folders within the project
print("\nProject Files:", project.list_files())
print("Project Folders:", project.list_folders())

๐Ÿ“„ Simplified JSON Structure

The export_to_simplified_json and sync_from_simplified_json methods use a streamlined JSON format to represent the project's timeline. This makes it easier to understand and modify track information.

{
  "project_name": "My Awesome Video", // Optional: A name for your project
  "aspect_ratio": "16:9",             // Optional: e.g., "16:9", "9:16", "1:1"
  "duration_ms": 10000,               // Optional: Total duration in milliseconds
  "materials": {                      // Contains all media used in tracks
    "videos": [
      {
        "id": "video_001",
        "path": "C:/path/to/your/video1.mp4",
        "duration_ms": 5000 // Original duration of the media file
      }
    ],
    "audios": [
      {
        "id": "audio_001",
        "path": "C:/path/to/your/audio1.mp3",
        "duration_ms": 3000
      }
    ],
    "images": [], // Placeholder for future image support
    "texts": [    // For text overlays
      {
        "id": "text_001",
        "content": "Hello World!",
        "font_size": 72,
        "color": "#FFFFFF"
        // ... other text properties
      }
    ]
  },
  "tracks": [
    { // Video Track 0
      "type": "video", // "video", "audio"
      "segments": [
        {
          "material_id": "video_001", // Links to an ID in `materials.videos`
          "name": "Clip 1",
          "start_time_ms": 0,         // Position on the track timeline (ms)
          "duration_ms": 2500,        // How long this segment plays on the track (ms)
          "media_start_time_ms": 0,   // From where in the original media file to start (ms)
          "volume": 1.0,              // 0.0 to 1.0
          "speed": 1.0,               // Playback speed
          "transition_outgoing": {    // Optional: Transition to the next segment
            "name": "fade",
            "duration_ms": 500
          }
        },
        {
          "material_id": "video_001",
          "name": "Clip 2",
          "start_time_ms": 2500,
          "duration_ms": 2500,
          "media_start_time_ms": 2500, // Start from 2.5s into the original video
          "volume": 1.0,
          "speed": 1.0
        }
      ]
    },
    { // Audio Track 0 (often linked to video) or separate Audio Track 1
      "type": "audio",
      "segments": [
        {
          "material_id": "audio_001",
          "name": "Background Music",
          "start_time_ms": 0,
          "duration_ms": 3000,
          "media_start_time_ms": 0,
          "volume": 0.5
        }
      ]
    },
    { // Text Track 0
      "type": "text",
      "segments": [
        {
          "material_id": "text_001", // Links to an ID in `materials.texts`
          "name": "Intro Text",
          "start_time_ms": 500,
          "duration_ms": 2000
        }
      ]
    }
  ]
}

Key points about the simplified JSON:

  • Human-Readable: Designed to be easily understood and modified.
  • AI-Friendly: Structured for programmatic manipulation by AI agents or scripts.
  • Synchronization:
    • export_to_simplified_json: Reads your CapCut project and generates this JSON.
    • sync_from_simplified_json: Takes a modified version of this JSON and updates your CapCut project's timeline accordingly.
  • Caution: sync_from_simplified_json will typically overwrite the existing timeline based on the JSON content. Always back up important projects.

(The exact structure of this simplified JSON will depend on how your Project.export_to_simplified_json and Project.sync_from_simplified_json methods are implemented. The example above is a comprehensive suggestion.)

๐Ÿ›๏ธ CapCut Project Structure (Brief Overview)

A CapCut project folder (often found in ...AppData\\Local\\CapCut\\User Data\\Projects\\com.lveditor.draft\\[PROJECT_ID_FOLDER]) typically contains:

[PROJECT_ID_FOLDER]/
โ”œโ”€โ”€ draft_content.json       # Core timeline, media, effects data (VERY IMPORTANT)
โ”œโ”€โ”€ draft_meta_info.json     # Project metadata
โ”œโ”€โ”€ draft_cover.jpg          # Project thumbnail
โ”œโ”€โ”€ Resources/               # Sometimes stores imported media copies
โ”œโ”€โ”€ common_attachment/
โ”œโ”€โ”€ matting/
โ”œโ”€โ”€ ... (other folders and JSON files for specific features)

CapGenie helps you manage and interact with these files, especially the critical draft_content.json.

๐Ÿ› ๏ธ How CapGenie Works

  1. Project Initialization/Loading: CapGenie either sets up a new valid CapCut folder structure or loads an existing one by identifying key files like draft_content.json.
  2. JSON Parsing: It reads and parses the CapCut JSON files (which are complex) into Python dictionaries.
  3. Simplified Abstraction (Optional but Recommended):
    • The export_to_simplified_json method translates the complex draft_content.json (and potentially other files) into a more manageable, high-level JSON structure (as shown above). This is the "agent-editable" JSON.
    • The sync_from_simplified_json method takes this simplified JSON, translates it back into the detailed format CapCut expects, and updates the draft_content.json (and other necessary files).
  4. Direct Manipulation: You can also opt to directly load, modify, and save the raw CapCut JSON files if you understand their intricate structure.
  5. File System Operations: CapGenie uses the CapCutFileManager (or similar utility) to handle the correct creation, copying, and organization of files and folders to ensure CapCut can recognize the project.

The Goal: To allow an agent (or a script) to define video edits (like adding clips, text, changing timings) by modifying a relatively simple JSON, and then have CapGenie translate those instructions into a fully functional CapCut project.

๐Ÿค Contributing

Contributions are welcome! If you'd like to improve CapGenie or add new features:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature-name).
  3. Make your changes.
  4. Write tests for your changes.
  5. Ensure all tests pass (pytest).
  6. Submit a pull request.

Please read our (to-be-created) CONTRIBUTING.md for more detailed guidelines.

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with โค๏ธ and ๐Ÿ by Yanis Djeroro (and Cascade!)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

capgenie-0.1.0.tar.gz (62.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

capgenie-0.1.0-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file capgenie-0.1.0.tar.gz.

File metadata

  • Download URL: capgenie-0.1.0.tar.gz
  • Upload date:
  • Size: 62.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for capgenie-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9eea45c8d893d1e146e49acc5ee0452827caa1987b1d64e448e90e3b510ea5e3
MD5 51529d0eeb7f0c9b4c9a223b726142dd
BLAKE2b-256 7d8ffb34604babb7d237c7ad381e0ddeef8f72a9ea0521eeec07ed89ce8e810a

See more details on using hashes here.

File details

Details for the file capgenie-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: capgenie-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for capgenie-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e0117be7541ed8328272c4ac0d7cd8ff0a34beccffe51f073eb7c5064ba5ee8
MD5 d9e43266e70205a2fd59c87697d606d1
BLAKE2b-256 ffe93f84df8fb68a114e7f37509ee04ad3fadddfbaa2539d202072409bb4ddc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page