{
  "name": "02-Video-Producer",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "produce-video",
        "responseMode": "responseNode",
        "options": {}
      },
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "number": [
            {
              "name": "idea_id",
              "value": "={{ $json.body.idea_id }}"
            }
          ],
          "string": [
            {
              "name": "language",
              "value": "={{ $json.body.language || 'pt-BR' }}"
            }
          ]
        }
      },
      "name": "Extract Parameters",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "command": "cd /app && python scripts/02_script_writing/write_script.py --idea-id {{ $json.idea_id }} --language {{ $json.language }}"
      },
      "name": "Write Script",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Extract script ID from command output\nconst output = items[0].json.stdout;\nconst match = output.match(/Script ID: (\\d+)/);\nconst scriptId = match ? parseInt(match[1]) : 0;\n\nreturn [{\n  json: {\n    script_id: scriptId,\n    language: items[0].json.language\n  }\n}];"
      },
      "name": "Parse Script ID",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "command": "cd /app && python scripts/03_voiceover/generate_audio.py --script-id {{ $json.script_id }}"
      },
      "name": "Generate Audio",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1050,
        200
      ]
    },
    {
      "parameters": {
        "command": "cd /app && python scripts/04_visual_generation/generate_images.py --script-id {{ $json.script_id }}"
      },
      "name": "Generate Visuals",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1050,
        400
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineAll"
      },
      "name": "Wait for Both",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2,
      "position": [
        1250,
        300
      ]
    },
    {
      "parameters": {
        "command": "cd /app && python scripts/05_video_editing/compose_video.py --script-id {{ $json.script_id }}"
      },
      "name": "Compose Video",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1450,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Extract video ID from command output\nconst output = items[0].json.stdout;\nconst match = output.match(/Video ID: (\\d+)/);\nconst videoId = match ? parseInt(match[1]) : 0;\n\nreturn [{\n  json: {\n    video_id: videoId,\n    script_id: items[0].json.script_id,\n    language: items[0].json.language,\n    status: 'completed',\n    timestamp: new Date().toISOString()\n  }\n}];"
      },
      "name": "Parse Video ID",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        1650,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "name": "Respond Success",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1850,
        300
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Extract Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Parameters": {
      "main": [
        [
          {
            "node": "Write Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write Script": {
      "main": [
        [
          {
            "node": "Parse Script ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Script ID": {
      "main": [
        [
          {
            "node": "Generate Audio",
            "type": "main",
            "index": 0
          },
          {
            "node": "Generate Visuals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Audio": {
      "main": [
        [
          {
            "node": "Wait for Both",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Visuals": {
      "main": [
        [
          {
            "node": "Wait for Both",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Wait for Both": {
      "main": [
        [
          {
            "node": "Compose Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose Video": {
      "main": [
        [
          {
            "node": "Parse Video ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Video ID": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2025-01-01T00:00:00.000Z",
  "versionId": "1"
}