{
  "name": "Vorlux AI | YouTube Shorts Creator",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "youtube-shorts",
        "options": { "responseMode": "lastNode" }
      },
      "id": "webhook-trigger",
      "name": "Shorts Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/studio/transcripts",
        "method": "GET",
        "qs": { "videoId": "={{ $input.first().json.body?.videoId || $input.first().json.videoId }}" },
        "options": { "timeout": 15000 }
      },
      "id": "fetch-transcript",
      "name": "Fetch Video Transcript",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/ai/completion",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ prompt: 'Analyze this transcript and identify the 3 best moments for YouTube Shorts (< 60 seconds each). For each, provide: startTime (seconds), endTime (seconds), title, and a hook caption. Return as JSON array. Transcript: ' + JSON.stringify($json.transcript || $json.data || '').substring(0, 4000), model: 'gpt-4o-mini' }) }}",
        "options": { "timeout": 60000 }
      },
      "id": "find-clips",
      "name": "AI Find Best Clips",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [700, 300]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const videoId = $('Shorts Webhook').first().json.body?.videoId || $('Shorts Webhook').first().json.videoId;\nconst aiResponse = $input.first().json.text || $input.first().json.content || '[]';\nlet clips;\ntry { clips = JSON.parse(aiResponse); } catch { clips = []; }\n\nconst shorts = (Array.isArray(clips) ? clips : []).map((clip, i) => ({\n  index: i + 1,\n  sourceVideoId: videoId,\n  startTime: clip.startTime || 0,\n  endTime: clip.endTime || 60,\n  title: clip.title || `Short #${i+1}`,\n  caption: clip.hook || clip.caption || '',\n  status: 'queued'\n}));\n\nreturn [{ json: { videoId, shorts, count: shorts.length } }];"
      },
      "id": "format-shorts",
      "name": "Format Shorts Queue",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [960, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/studio/video/create",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ type: 'shorts', sourceVideoId: $json.videoId, clips: $json.shorts }) }}",
        "options": { "timeout": 60000 }
      },
      "id": "queue-shorts",
      "name": "Queue Shorts Creation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1200, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$env.DISCORD_CONTENT_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ content: '🎬 **YouTube Shorts Queued**\\nSource Video: ' + $('Format Shorts Queue').first().json.videoId + '\\nShorts Created: ' + $('Format Shorts Queue').first().json.count + '\\n' + $('Format Shorts Queue').first().json.shorts.map(s => '• ' + s.title).join('\\n') }) }}"
      },
      "id": "discord-notify",
      "name": "Discord Notify",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1440, 300]
    }
  ],
  "connections": {
    "Shorts Webhook": { "main": [[{ "node": "Fetch Video Transcript", "type": "main", "index": 0 }]] },
    "Fetch Video Transcript": { "main": [[{ "node": "AI Find Best Clips", "type": "main", "index": 0 }]] },
    "AI Find Best Clips": { "main": [[{ "node": "Format Shorts Queue", "type": "main", "index": 0 }]] },
    "Format Shorts Queue": { "main": [[{ "node": "Queue Shorts Creation", "type": "main", "index": 0 }]] },
    "Queue Shorts Creation": { "main": [[{ "node": "Discord Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
