{
  "name": "AI CapCut Video Editor Automation",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "video-edit",
        "options": {}
      },
      "id": "1",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition1",
              "leftValue": "={{ $json.input_type }}",
              "rightValue": "prompt",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "2",
      "name": "IF Node (Prompt vs Reference)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o",
        "prompt": "=Analyze this prompt for video edits: {{$json.prompt}}. Output JSON with cuts (array of timings), effects (array of types), text (array of overlays), sound (track name).",
        "options": {}
      },
      "id": "3",
      "name": "OpenAI Node (Prompt Analysis)",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1,
      "position": [
        680,
        200
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Video analysis with FFmpeg (assume video downloaded to /tmp)\nconst ffmpeg = require('fluent-ffmpeg');\nconst path = require('path');\n\n// Download video if URL\n// For demo: extract cuts via scene detection\nffmpeg('/tmp/reference.mp4')\n  .on('end', () => {\n    // Parse output for cuts, effects (simplified)\n    return {\n      cuts: [{start: 0, end: 5}, {start: 5, end: 10}],\n      effects: ['zoom', 'transition'],\n      text: ['OCR text here'],\n      sound: 'extracted_audio.mp3'\n    };\n  })\n  .ffprobe(() => {\n    // Add ML detection logic here (e.g., via torch if available)\n  });"
      },
      "id": "4",
      "name": "Code Node (Video Analysis)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        400
      ]
    },
    {
      "parameters": {},
      "id": "5",
      "name": "Merge Node",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.2,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Generate CapCut JSON from edit plan\nconst plan = $input.all()[0].json;\nconst capcutJson = {\n  \"draft_meta\": {\n    \"version\": 1,\n    \"tracks\": [\n      {\n        \"segments\": plan.cuts.map(c => ({start: c.start, end: c.end})),\n        \"effects\": plan.effects,\n        \"text\": plan.text,\n        \"audio\": plan.sound\n      }\n    ]\n  }\n};\nreturn { project: capcutJson };"
      },
      "id": "6",
      "name": "Code Node (CapCut JSON Generate)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1120,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:8080/capcut/create",
        "authentication": "none",
        "requestMethod": "POST",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "project",
              "value": "={{ $json.project }}"
            }
          ]
        },
        "options": {}
      },
      "id": "7",
      "name": "HTTP Request Node (CapCut API)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1340,
        300
      ]
    },
    {
      "parameters": {
        "command": "capcut open {{$json.project_id}} --export /output/final.mp4"
      },
      "id": "8",
      "name": "Execute Command Node (Run CapCut)",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1560,
        300
      ]
    },
    {
      "parameters": {
        "operation": "upload",
        "fileName": "edited_video.mp4",
        "binaryData": true,
        "binaryPropertyName": "data",
        "options": {}
      },
      "id": "9",
      "name": "Google Drive Node (Upload)",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3.2,
      "position": [
        1780,
        300
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "your@email.com",
        "toEmail": "={{ $json.user_email }}",
        "subject": "Video Edit Complete!",
        "emailType": "text",
        "text": "Tera edited video ready hai! Link: {{ $json.share_url }}",
        "options": {}
      },
      "id": "10",
      "name": "Email Node (Notify)",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        2000,
        300
      ],
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "IF Node (Prompt vs Reference)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Node (Prompt vs Reference)": {
      "main": [
        [
          {
            "node": "OpenAI Node (Prompt Analysis)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code Node (Video Analysis)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Node (Prompt Analysis)": {
      "main": [
        [
          {
            "node": "Merge Node",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code Node (Video Analysis)": {
      "main": [
        [
          {
            "node": "Merge Node",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Node": {
      "main": [
        [
          {
            "node": "Code Node (CapCut JSON Generate)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code Node (CapCut JSON Generate)": {
      "main": [
        [
          {
            "node": "HTTP Request Node (CapCut API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request Node (CapCut API)": {
      "main": [
        [
          {
            "node": "Execute Command Node (Run CapCut)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command Node (Run CapCut)": {
      "main": [
        [
          {
            "node": "Google Drive Node (Upload)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Drive Node (Upload)": {
      "main": [
        [
          {
            "node": "Email Node (Notify)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2025-10-25T00:00:00.000Z",
  "versionId": "1"
}