{
  "name": "Video Automation Pipeline",
  "nodes": [
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000001",
      "name": "Schedule (Daily)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [-680, 300],
      "parameters": { "rule": { "interval": [{ "field": "cronExpression", "expression": "0 9 * * 1-5" }] } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000002",
      "name": "Google Sheets (Read Queue)",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [-480, 300],
      "parameters": { "operation": "get", "resource": "sheet", "sheetName": "Video Queue", "options": { "returnAll": true } },
      "credentials": { "googleSheetsOAuth2Api": { "id": null, "name": "Google Sheets OAuth2" } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000003",
      "name": "Filter Pending",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [-280, 300],
      "parameters": {
        "jsCode": "const items = $input.all();\nconst pending = items.filter(i => i.json.status === 'pending' || !i.json.status);\nif (!pending.length) throw new Error('No pending');\nreturn [pending[0]];"
      }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000004",
      "name": "Google Drive (Get Assets)",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [-80, 300],
      "parameters": { "operation": "list", "folderId": "={{$json.assetsFolderId}}" },
      "credentials": { "googleDriveOAuth2Api": { "id": null, "name": "Google Drive OAuth2" } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000005",
      "name": "Set Job Params",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [120, 300],
      "parameters": { "values": { "string": [
        { "name": "videoTitle", "value": "={{$node['Google Sheets (Read Queue)'].json.title}}" },
        { "name": "imageUrls", "value": "={{$json.map(i => i.url).join(',')}}" }
      ]} }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000006",
      "name": "Generate Video (API)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [320, 300],
      "parameters": {
        "url": "https://api.runwayml.com/v1/videos",
        "method": "POST",
        "sendBody": true,
        "bodyParameters": { "parameters": [
          { "name": "title", "value": "={{$json.videoTitle}}" },
          { "name": "images", "value": "={{$json.imageUrls}}" }
        ]}
      },
      "credentials": { "httpHeaderAuth": { "id": null, "name": "Video API Key" } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000007",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 2,
      "position": [520, 300],
      "parameters": { "waitType": "defined", "resume": { "amount": 30, "unit": "seconds" } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000008",
      "name": "Check Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [720, 300],
      "parameters": { "url": "={{'https://api.runwayml.com/v1/videos/' + $node['Generate Video (API)'].json.id}}", "method": "GET" },
      "credentials": { "httpHeaderAuth": { "id": null, "name": "Video API Key" } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000009",
      "name": "IF Completed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [920, 300],
      "parameters": { "conditions": { "string": [{ "value1": "={{$json.status}}", "operation": "equal", "value2": "completed" }] } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000010",
      "name": "Upload to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [1120, 180],
      "parameters": { "operation": "upload", "name": "={{'Output - ' + $node['Set Job Params'].json.videoTitle + '.mp4'}}" },
      "credentials": { "googleDriveOAuth2Api": { "id": null, "name": "Google Drive OAuth2" } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000011",
      "name": "Mark Complete",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [1120, 380],
      "parameters": { "operation": "update", "resource": "sheet", "sheetName": "Video Queue" },
      "credentials": { "googleSheetsOAuth2Api": { "id": null, "name": "Google Sheets OAuth2" } }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000012",
      "name": "Loop Back",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [1120, 580],
      "parameters": {}
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000013",
      "name": "Aggregate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1340, 300],
      "parameters": { "jsCode": "return [{ json: { done: true } }];" }
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000014",
      "name": "Error Handler",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [1120, 760],
      "parameters": {}
    },
    {
      "id": "f6a7b8c9-6666-4000-8000-000000000015",
      "name": "Slack Notify",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2,
      "position": [1340, 760],
      "parameters": { "operation": "post", "resource": "message", "channel": "C0XXXXXXX" },
      "credentials": { "slackApi": { "id": null, "name": "Slack API" } }
    }
  ],
  "connections": {
    "Schedule (Daily)": { "main": [[{ "node": "Google Sheets (Read Queue)", "type": "main", "index": 0 }]] },
    "Google Sheets (Read Queue)": { "main": [[{ "node": "Filter Pending", "type": "main", "index": 0 }]] },
    "Filter Pending": { "main": [[{ "node": "Google Drive (Get Assets)", "type": "main", "index": 0 }]] },
    "Google Drive (Get Assets)": { "main": [[{ "node": "Set Job Params", "type": "main", "index": 0 }]] },
    "Set Job Params": { "main": [[{ "node": "Generate Video (API)", "type": "main", "index": 0 }]] },
    "Generate Video (API)": { "main": [[{ "node": "Wait", "type": "main", "index": 0 }]] },
    "Wait": { "main": [[{ "node": "Check Status", "type": "main", "index": 0 }]] },
    "Check Status": { "main": [[{ "node": "IF Completed?", "type": "main", "index": 0 }]] },
    "IF Completed?": {
      "main": [
        [{ "node": "Upload to Drive", "type": "main", "index": 0 }],
        [{ "node": "Loop Back", "type": "main", "index": 0 }]
      ]
    },
    "Upload to Drive": { "main": [[{ "node": "Mark Complete", "type": "main", "index": 0 }]] },
    "Mark Complete": { "main": [[{ "node": "Aggregate", "type": "main", "index": 0 }]] },
    "Loop Back": { "main": [[{ "node": "Wait", "type": "main", "index": 0 }]] },
    "Aggregate": { "main": [[{ "node": "Slack Notify", "type": "main", "index": 0 }]] },
    "Error Handler": { "main": [[{ "node": "Slack Notify", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" },
  "staticData": null,
  "pinData": {},
  "triggerCount": 1,
  "meta": { "templateCredsSetupCompleted": true }
}
