{
  "name": "n8n YouTube Automation Free: Turn One Video Into a Week of Content",
  "nodes": [
    {
      "id": "0d1cb60b-26fc-42b5-afbf-4a880039b5d8",
      "name": "Video URL Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "formTitle": "One Video, A Week of Content",
        "formDescription": "Paste a YouTube video URL and get a thread, three short scripts and a newsletter draft.",
        "path": "video-to-week-of-content",
        "formFields": {
          "values": [
            {
              "fieldLabel": "YouTube URL",
              "fieldType": "text",
              "placeholder": "https://www.youtube.com/watch?v=...",
              "requiredField": true
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "16851c66-bad8-4032-a58d-850a3ecc331a",
      "name": "Create Assets Table",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        220,
        300
      ],
      "parameters": {
        "operation": "executeQuery",
        "query": "CREATE TABLE IF NOT EXISTS content_assets (id serial PRIMARY KEY, source_url text NOT NULL, asset_type text NOT NULL, title text, body text, created_at timestamptz DEFAULT now());",
        "options": {}
      }
    },
    {
      "id": "42b6f451-e9ad-4505-92cc-b8dca9119f8a",
      "name": "Download Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        500,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "http://ffmpeg-worker:8080/download",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ url: String($('Video URL Form').first().json['YouTube URL']).trim(), outDir: 'week-of-content/' + Date.now().toString(36), name: 'source' }) }}",
        "options": {
          "timeout": 600000
        }
      }
    },
    {
      "id": "8904b988-05e4-4ffe-a2f2-bf58af681c17",
      "name": "Extract Audio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        720,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "http://ffmpeg-worker:8080/extract-audio",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ input: $json.file, output: $json.file.replace(/[^/]+$/, 'audio.mp3'), base64: true }) }}",
        "options": {
          "timeout": 600000
        }
      }
    },
    {
      "id": "c160356f-32ca-42c5-ae42-d95636ee0eb5",
      "name": "Prepare Audio File",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        940,
        300
      ],
      "parameters": {
        "jsCode": "const d = $input.first().json;\nconst buf = Buffer.from(d.base64, 'base64');\nconst bin = await this.helpers.prepareBinaryData(buf, 'audio.mp3', 'audio/mpeg');\nreturn [{ json: { audioFile: d.file, audioSeconds: d.durationSeconds, audioBytes: buf.length }, binary: { audio: bin } }];"
      }
    },
    {
      "id": "93baf22b-d332-405b-95a5-eb30169e2b06",
      "name": "Transcribe with Speaches",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        1220,
        300
      ],
      "parameters": {
        "method": "POST",
        "url": "http://speaches:8000/v1/audio/transcriptions",
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "audio"
            },
            {
              "name": "model",
              "value": "Systran/faster-distil-whisper-large-v3"
            },
            {
              "name": "response_format",
              "value": "json"
            }
          ]
        },
        "options": {
          "timeout": 900000
        }
      }
    },
    {
      "id": "0add4d10-8ff2-4e19-91ee-4a78174be3fa",
      "name": "Extract Ideas with Ollama",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        1500,
        300
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ 'Transcript:\\n' + String($json.text).slice(0, 24000) }}",
        "hasOutputParser": false,
        "messages": {
          "messageValues": [
            {
              "message": "You are an editor who pulls the core ideas out of a video transcript. Use only what is in the transcript. Reply with JSON only, no markdown, in exactly this shape: {\"ideas\":[{\"title\":\"short title\",\"summary\":\"one or two sentences\"}],\"quotes\":[\"exact quotable line from the transcript\"],\"takeaways\":[\"one actionable takeaway\"]}. Give 3 to 6 ideas, up to 4 quotes and 3 to 5 takeaways. If the transcript is short, give fewer."
            }
          ]
        }
      }
    },
    {
      "id": "8ca8fc3d-d538-44a8-a869-f8eb68fc4f2b",
      "name": "Ollama Chat Model (Ideas)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        1500,
        520
      ],
      "parameters": {
        "model": "qwen2.5:14b-instruct-q5_K_M",
        "options": {
          "temperature": 0.3,
          "numCtx": 16384,
          "format": "json"
        }
      }
    },
    {
      "id": "800fb056-0499-4323-8d7e-0a16f07b94c8",
      "name": "Enforce Idea Structure",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1800,
        300
      ],
      "parameters": {
        "jsCode": "const out = $input.first().json;\nconst raw = typeof out.text === 'string' ? out.text : JSON.stringify(out);\nconst transcript = String($('Transcribe with Speaches').first().json.text || '');\nlet parsed;\ntry { parsed = JSON.parse(raw); }\ncatch (e) {\n  const m = raw.match(/\\{[\\s\\S]*\\}/);\n  if (!m) throw new Error('Ollama did not return JSON: ' + raw.slice(0, 200));\n  try { parsed = JSON.parse(m[0]); } catch (e2) { throw new Error('Could not repair the JSON: ' + raw.slice(0, 200)); }\n}\nconst pick = (...keys) => { for (const k of keys) if (parsed[k] !== undefined) return parsed[k]; return []; };\nconst toList = v => Array.isArray(v) ? v : (v ? [v] : []);\nconst clean = s => String(s || '').replace(/\\s+/g, ' ').trim();\nconst ideas = toList(pick('ideas', 'core_ideas', 'coreIdeas', 'key_points'))\n  .map(i => typeof i === 'string' ? { title: clean(i).slice(0, 80), summary: clean(i) }\n    : { title: clean(i.title || i.idea || i.name), summary: clean(i.summary || i.description || i.point || i.title) })\n  .filter(i => i.title && i.summary).slice(0, 8);\nconst quotes = toList(pick('quotes', 'quotable_lines', 'quotableLines'))\n  .map(q => clean(typeof q === 'string' ? q : (q.quote || q.text))).filter(Boolean).slice(0, 6);\nconst takeaways = toList(pick('takeaways', 'key_takeaways', 'keyTakeaways'))\n  .map(t => clean(typeof t === 'string' ? t : (t.takeaway || t.text))).filter(Boolean).slice(0, 6);\nif (!ideas.length) throw new Error('No ideas found in the model reply: ' + raw.slice(0, 200));\nconst norm = s => s.toLowerCase().replace(/[^a-z0-9 ]+/g, '').replace(/\\s+/g, ' ');\nconst t = norm(transcript);\nconst verifiedQuotes = quotes.filter(q => t.includes(norm(q))).length;\nreturn [{ json: { structured: { ideas, quotes, takeaways }, counts: { ideas: ideas.length, quotes: quotes.length, takeaways: takeaways.length, verifiedQuotes } } }];"
      }
    },
    {
      "id": "26c776c7-3b55-4d7a-9e7f-9f46856d18b1",
      "name": "Draft Content with Ollama",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        2080,
        300
      ],
      "parameters": {
        "promptType": "define",
        "text": "={{ 'Structured ideas from one video:\\n' + JSON.stringify($json.structured, null, 2) }}",
        "hasOutputParser": false,
        "messages": {
          "messageValues": [
            {
              "message": "You are a content writer who turns one video's ideas into a week of content for a solo creator. Use only the ideas given. Reply with JSON only, no markdown, in exactly this shape: {\"thread\":[\"post 1 (the hook)\",\"post 2\",\"...\"],\"short_scripts\":[{\"title\":\"...\",\"hook\":\"first line spoken\",\"script\":\"20 to 40 seconds of spoken script\"}],\"newsletter\":{\"subject\":\"...\",\"body\":\"full newsletter draft in plain text\"}}. The thread has 5 to 8 posts under 280 characters each. short_scripts has exactly 3 items. The newsletter body is 150 to 250 words."
            }
          ]
        }
      }
    },
    {
      "id": "a3fb0857-b7d2-4e67-aa99-2511413d5d9e",
      "name": "Ollama Chat Model (Draft)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        2080,
        520
      ],
      "parameters": {
        "model": "qwen2.5:14b-instruct-q5_K_M",
        "options": {
          "temperature": 0.7,
          "numCtx": 16384,
          "format": "json"
        }
      }
    },
    {
      "id": "aa43aa56-5b09-4548-b210-e3ac419580f9",
      "name": "Split Into Assets",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2380,
        300
      ],
      "parameters": {
        "jsCode": "const out = $input.first().json;\nconst raw = typeof out.text === 'string' ? out.text : JSON.stringify(out);\nconst sourceUrl = String($('Video URL Form').first().json['YouTube URL'] || '').trim();\nlet d;\ntry { d = JSON.parse(raw); }\ncatch (e) {\n  const m = raw.match(/\\{[\\s\\S]*\\}/);\n  if (!m) throw new Error('Ollama did not return JSON for the draft: ' + raw.slice(0, 200));\n  d = JSON.parse(m[0]);\n}\nconst str = v => String(v || '').trim();\nconst thread = (Array.isArray(d.thread) ? d.thread : [d.thread]).map(str).filter(Boolean);\nconst scripts = (Array.isArray(d.short_scripts) ? d.short_scripts : []).slice(0, 3);\nconst nl = d.newsletter || {};\nif (!thread.length || !scripts.length || !str(nl.body)) throw new Error('Draft is missing the thread, scripts or newsletter: ' + raw.slice(0, 200));\nconst NL = String.fromCharCode(10);\nconst assets = [\n  { assetType: 'thread', title: 'Social thread', body: thread.map((p, i) => (i + 1) + '/ ' + p).join(NL + NL) },\n  { assetType: 'short_scripts', title: 'Three short-form video scripts',\n    body: scripts.map((s, i) => 'SCRIPT ' + (i + 1) + ': ' + str(s.title) + NL + 'Hook: ' + str(s.hook) + NL + str(s.script)).join(NL + NL) },\n  { assetType: 'newsletter', title: 'Newsletter: ' + str(nl.subject), body: str(nl.body) },\n];\nreturn assets.map(a => ({ json: Object.assign({ sourceUrl }, a) }));"
      }
    },
    {
      "id": "2452858d-240b-4184-b03c-499b085fc633",
      "name": "Route by Asset Type",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        2640,
        300
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "a1510540-5bdb-4ff3-b62a-34da2981d860",
                    "leftValue": "={{ $json.assetType }}",
                    "rightValue": "thread",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Thread"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "675184e8-40e5-4d52-a23d-b08460e82677",
                    "leftValue": "={{ $json.assetType }}",
                    "rightValue": "short_scripts",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Short Scripts"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "52aef53f-5b5d-4262-ba9d-ffff9130db60",
                    "leftValue": "={{ $json.assetType }}",
                    "rightValue": "newsletter",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Newsletter"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "eeaac46e-1181-4f2f-8813-9252eda1893e",
      "name": "Save Thread",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2920,
        120
      ],
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO content_assets (source_url, asset_type, title, body) SELECT \"sourceUrl\", \"assetType\", title, body FROM json_to_recordset($1::json) AS x(\"sourceUrl\" text, \"assetType\" text, title text, body text) RETURNING id, asset_type, title;",
        "options": {
          "queryReplacement": "={{ JSON.stringify([$json]) }}"
        }
      }
    },
    {
      "id": "c69528ea-4e28-4d80-b8a1-e70888d48598",
      "name": "Save Short Scripts",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2920,
        300
      ],
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO content_assets (source_url, asset_type, title, body) SELECT \"sourceUrl\", \"assetType\", title, body FROM json_to_recordset($1::json) AS x(\"sourceUrl\" text, \"assetType\" text, title text, body text) RETURNING id, asset_type, title;",
        "options": {
          "queryReplacement": "={{ JSON.stringify([$json]) }}"
        }
      }
    },
    {
      "id": "44ef8d3a-2fa5-4895-b4f0-c90bfab78ce4",
      "name": "Save Newsletter",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        2920,
        480
      ],
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO content_assets (source_url, asset_type, title, body) SELECT \"sourceUrl\", \"assetType\", title, body FROM json_to_recordset($1::json) AS x(\"sourceUrl\" text, \"assetType\" text, title text, body text) RETURNING id, asset_type, title;",
        "options": {
          "queryReplacement": "={{ JSON.stringify([$json]) }}"
        }
      }
    },
    {
      "id": "2f9bcb63-eeaf-4c12-a41d-3ddba3410a8c",
      "name": "Combine Saved Assets",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3,
      "position": [
        3200,
        300
      ],
      "parameters": {
        "numberInputs": 3
      }
    },
    {
      "id": "3508d855-b627-4e87-9464-71d0984f45e1",
      "name": "Notify Discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "executeOnce": true,
      "position": [
        3460,
        300
      ],
      "parameters": {
        "authentication": "webhook",
        "content": "={{ 'Your week of content is ready for ' + $('Video URL Form').first().json['YouTube URL'] + ' - saved to the content_assets table: ' + $input.all().map(i => '#' + i.json.id + ' ' + i.json.title).join(' | ') }}",
        "options": {}
      }
    },
    {
      "id": "6d84928e-dc26-48bc-9a60-2cea552e43b6",
      "name": "Stage: 1 Form + setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        180
      ],
      "parameters": {
        "content": "## 1 Form + setup",
        "width": 520,
        "height": 300,
        "color": 7
      }
    },
    {
      "id": "a0ff75f6-4bb7-445c-bff4-b988ba4e18dc",
      "name": "Stage: 2 Download + audio",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        460,
        180
      ],
      "parameters": {
        "content": "## 2 Download + audio",
        "width": 660,
        "height": 300,
        "color": 5
      }
    },
    {
      "id": "c6e76ae8-5fd9-435d-a498-fe0f3c6bb950",
      "name": "Stage: 3 Transcribe",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1160,
        180
      ],
      "parameters": {
        "content": "## 3 Transcribe",
        "width": 300,
        "height": 300,
        "color": 4
      }
    },
    {
      "id": "6c239b7e-3e00-49c8-bfd1-cd538663a20e",
      "name": "Stage: 4 Find core ideas",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1460,
        180
      ],
      "parameters": {
        "content": "## 4 Find core ideas",
        "width": 560,
        "height": 480,
        "color": 3
      }
    },
    {
      "id": "822e93d6-d3ea-4f67-a583-f85e50212b61",
      "name": "Stage: 5 Draft content",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2040,
        180
      ],
      "parameters": {
        "content": "## 5 Draft content",
        "width": 560,
        "height": 480,
        "color": 6
      }
    },
    {
      "id": "0f456f74-18d3-44dd-a196-99f8a4af5e83",
      "name": "Stage: 6 Route + save + notify",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2620,
        40
      ],
      "parameters": {
        "content": "## 6 Route + save + notify",
        "width": 1000,
        "height": 620,
        "color": 2
      }
    }
  ],
  "connections": {
    "Video URL Form": {
      "main": [
        [
          {
            "node": "Create Assets Table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Assets Table": {
      "main": [
        [
          {
            "node": "Download Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video": {
      "main": [
        [
          {
            "node": "Extract Audio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Audio": {
      "main": [
        [
          {
            "node": "Prepare Audio File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Audio File": {
      "main": [
        [
          {
            "node": "Transcribe with Speaches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Transcribe with Speaches": {
      "main": [
        [
          {
            "node": "Extract Ideas with Ollama",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Ideas with Ollama": {
      "main": [
        [
          {
            "node": "Enforce Idea Structure",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enforce Idea Structure": {
      "main": [
        [
          {
            "node": "Draft Content with Ollama",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Draft Content with Ollama": {
      "main": [
        [
          {
            "node": "Split Into Assets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Into Assets": {
      "main": [
        [
          {
            "node": "Route by Asset Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat Model (Ideas)": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Ideas with Ollama",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat Model (Draft)": {
      "ai_languageModel": [
        [
          {
            "node": "Draft Content with Ollama",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Route by Asset Type": {
      "main": [
        [
          {
            "node": "Save Thread",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Short Scripts",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Newsletter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Thread": {
      "main": [
        [
          {
            "node": "Combine Saved Assets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Short Scripts": {
      "main": [
        [
          {
            "node": "Combine Saved Assets",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Save Newsletter": {
      "main": [
        [
          {
            "node": "Combine Saved Assets",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Combine Saved Assets": {
      "main": [
        [
          {
            "node": "Notify Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}
