{
  "nodes": [
    {
      "parameters": {
        "triggerTimes": [
          {
            "mode": "everyX",
            "value": {
              "unit": "hours",
              "quantity": 6
            }
          }
        ]
      },
      "name": "Trigger: Every 6 Hours",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        200,
        100
      ]
    },
    {
      "name": "Set Prompt Types",
      "parameters": {
        "values": {
          "string": [],
          "array": [
            {
              "name": "promptTypes",
              "value": {
                "json": [
                  "plant_meditation",
                  "prophet_teaching",
                  "healing_scenario",
                  "reflection_intention"
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        400,
        100
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "Split Prompt Types",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        600,
        100
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "prompt",
              "value": "{{ $json.promptTypes }}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Prompt",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        700,
        100
      ]
    },
    {
      "parameters": {
        "authentication": "predefinedCredentialType",
        "httpMethod": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"model\": \"gpt-4\",\n  \"messages\": [{\"role\": \"user\", \"content\": \"{{$json.prompt}}\"}]\n}"
      },
      "name": "Generate Script (GPT-4)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1000,
        100
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "url": "https://api.replicate.com/v1/predictions",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"version\": \"wavespeedai/wan-2.1-t2v-720p\",\n  \"input\": {\n    \"prompt\": $json[\"script\"]\n  }\n}"
      },
      "name": "Text-to-Video (Replicate AI)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1200,
        100
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "url": "https://api.replicate.com/v1/predictions",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"version\": \"minimax/speech-02-hd\",\n  \"input\": {\n    \"text\": $json[\"script\"],\n    \"voice_id\": \"R8_KVA2GBM4\",\n    \"emotion\": \"happy\"\n  }\n}"
      },
      "name": "Generate Narration",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1400,
        100
      ]
    },
    {
      "parameters": {
        "directory": "/data/youtube-audio",
        "options": {}
      },
      "name": "Pull YouTube Audio from Folder",
      "type": "n8n-nodes-base.readBinaryFiles",
      "typeVersion": 1,
      "position": [
        1600,
        100
      ]
    },
    {
      "parameters": {
        "command": "ffmpeg -i input.mp4 -i input.mp3 -c:v copy -c:a aac output.mp4"
      },
      "name": "Merge Audio + Video",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1800,
        100
      ]
    },
    {
      "parameters": {
        "fileName": "final_output.mp4",
        "dataPropertyName": "mergedFile"
      },
      "name": "Save .mp4 File",
      "type": "n8n-nodes-base.writeBinaryFile",
      "typeVersion": 1,
      "position": [
        2000,
        100
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "metadata",
              "value": "{{ JSON.stringify({ prompt: $json.prompt, timestamp: new Date().toISOString() }) }}"
            }
          ]
        },
        "options": {}
      },
      "name": "Generate Metadata",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        2200,
        100
      ]
    }
  ],
  "connections": {
    "Trigger: Every 6 Hours": {
      "main": [
        [
          {
            "node": "Set Prompt Types",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Prompt Types": {
      "main": [
        [
          {
            "node": "Split Prompt Types",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Prompt Types": {
      "main": [
        [
          {
            "node": "Set Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Prompt": {
      "main": [
        [
          {
            "node": "Generate Script (GPT-4)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Script (GPT-4)": {
      "main": [
        [
          {
            "node": "Text-to-Video (Replicate AI)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text-to-Video (Replicate AI)": {
      "main": [
        [
          {
            "node": "Generate Narration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Narration": {
      "main": [
        [
          {
            "node": "Pull YouTube Audio from Folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pull YouTube Audio from Folder": {
      "main": [
        [
          {
            "node": "Merge Audio + Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Audio + Video": {
      "main": [
        [
          {
            "node": "Save .mp4 File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save .mp4 File": {
      "main": [
        [
          {
            "node": "Generate Metadata",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}