{
  "name": "MindFrame Psychology - FREE Complete Workflow",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 14 * * *"
            }
          ]
        }
      },
      "id": "trigger-daily",
      "name": "Daily Trigger 2PM Dubai",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        260,
        340
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"llama-3.3-70b-versatile\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are a psychology content expert creating trending YouTube Shorts topics.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Generate 5 trending psychology facts topics for YouTube Shorts. Return ONLY valid JSON: [{\\\"topic\\\": \\\"specific topic\\\", \\\"trend_score\\\": 8, \\\"why_trending\\\": \\\"reason\\\"}]\"\n    }\n  ],\n  \"temperature\": 0.9\n}"
      },
      "id": "generate-ideas",
      "name": "Generate 5 Ideas",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        340
      ]
    },
    {
      "parameters": {
        "jsCode": "const response = $input.first().json;\nconst content = response.choices[0].message.content;\n\nlet cleanContent = content.trim()\n  .replace(/```json\\n?/g, '')\n  .replace(/```\\n?/g, '');\n\nlet ideas;\ntry {\n  ideas = JSON.parse(cleanContent);\n} catch (e) {\n  const jsonMatch = cleanContent.match(/\\[.*\\]/s);\n  ideas = JSON.parse(jsonMatch[0]);\n}\n\nconst bestIdea = ideas.sort((a, b) => b.trend_score - a.trend_score)[0];\n\nreturn {\n  json: {\n    chosenTopic: bestIdea.topic,\n    trendScore: bestIdea.trend_score,\n    whyTrending: bestIdea.why_trending,\n    timestamp: new Date().toISOString()\n  }\n};"
      },
      "id": "pick-best",
      "name": "Pick Best Idea",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        340
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"llama-3.3-70b-versatile\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"Create curiosity-driven YouTube titles. Maximum 60 characters.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Create 1 YouTube Shorts title for: {{ $json.chosenTopic }}. Max 60 chars. Return ONLY the title.\"\n    }\n  ],\n  \"temperature\": 0.7\n}"
      },
      "id": "generate-title",
      "name": "Generate Title",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        920,
        340
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"llama-3.3-70b-versatile\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"Create educational YouTube Shorts scripts. Each scene: 10 seconds, 20-25 words narration.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Create 50-second YouTube Shorts script about: {{ $('Pick Best Idea').first().json.chosenTopic }}\\n\\nREQUIREMENTS:\\n- 5 scenes (10 sec each)\\n- Each narration: 20-25 words\\n- Scene 1: Hook\\n- Scenes 2-4: Facts\\n- Scene 5: CTA\\n\\nReturn ONLY JSON:\\n{\\n  \\\"scenes\\\": [\\n    {\\n      \\\"scene_number\\\": 1,\\n      \\\"duration\\\": 10,\\n      \\\"narration\\\": \\\"text here\\\",\\n      \\\"search_keywords\\\": \\\"brain neuroscience abstract\\\",\\n      \\\"scene_type\\\": \\\"hook\\\"\\n    }\\n  ]\\n}\"\n    }\n  ],\n  \"temperature\": 0.8\n}"
      },
      "id": "generate-script",
      "name": "Generate Script",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1140,
        340
      ]
    },
    {
      "parameters": {
        "jsCode": "const response = $input.first().json;\nconst content = response.choices[0].message.content;\n\nlet cleanContent = content.trim()\n  .replace(/```json\\n?/g, '')\n  .replace(/```\\n?/g, '');\n\nlet scriptData;\ntry {\n  scriptData = JSON.parse(cleanContent);\n} catch (e) {\n  const jsonMatch = cleanContent.match(/\\{[\\s\\S]*\\}/);\n  scriptData = JSON.parse(jsonMatch[0]);\n}\n\nif (!scriptData.scenes || scriptData.scenes.length !== 5) {\n  throw new Error('Script must have 5 scenes');\n}\n\nconst fullNarration = scriptData.scenes.map(s => s.narration).join(' ');\n\nconst titleResponse = $('Generate Title').first().json;\nconst cleanTitle = titleResponse.choices[0].message.content.trim().replace(/^\"+|\"+$/g, '');\n\nreturn {\n  json: {\n    scenes: scriptData.scenes,\n    fullNarration: fullNarration,\n    title: cleanTitle,\n    topic: $('Pick Best Idea').first().json.chosenTopic\n  }\n};"
      },
      "id": "parse-script",
      "name": "Parse Script",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1360,
        340
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.elevenlabs.io/v1/text-to-speech/21m00Tcm4TlvDq8ikWAM",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "xi-api-key",
              "value": "YOUR_ELEVENLABS_API_KEY_HERE"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"text\": {{ JSON.stringify($json.fullNarration) }},\n  \"model_id\": \"eleven_monolingual_v1\",\n  \"voice_settings\": {\n    \"stability\": 0.5,\n    \"similarity_boost\": 0.75\n  }\n}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "generate-voice",
      "name": "Generate Voice",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1580,
        240
      ]
    },
    {
      "parameters": {
        "name": "=audio_{{ $now.format('YYYYMMDD_HHmmss') }}.mp3",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root"
        }
      },
      "id": "save-audio",
      "name": "Save Audio to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1800,
        240
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "audioFileId",
              "value": "={{ $json.id }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "audioUrl",
              "value": "=https://drive.google.com/uc?export=download&id={{ $json.id }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "store-audio",
      "name": "Store Audio URL",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        2020,
        240
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "scenes",
        "options": {}
      },
      "id": "split-scenes",
      "name": "Split Into Scenes",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        1580,
        440
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "=https://api.pexels.com/videos/search?query={{ encodeURIComponent($json.search_keywords || 'abstract psychology brain') }}&per_page=3&orientation=portrait",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "YOUR_PEXELS_API_KEY_HERE"
            }
          ]
        }
      },
      "id": "search-video",
      "name": "Search Pexels Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1800,
        440
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{ $json.videos && $json.videos[0] ? ($json.videos[0].video_files.find(f => f.width === 1080 && f.height === 1920) || $json.videos[0].video_files.find(f => f.height > f.width) || $json.videos[0].video_files[0]).link : 'https://player.vimeo.com/external/436289993.hd.mp4?s=5b7c95c53d5b6d3b4b7b8c8d8f8b8c8d8f8b8c8d' }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          },
          "timeout": 60000
        }
      },
      "id": "download-video",
      "name": "Download Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2020,
        440
      ]
    },
    {
      "parameters": {
        "name": "=scene_{{ $('Split Into Scenes').item.json.scene_number }}_{{ $now.format('HHmmss') }}.mp4",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root"
        }
      },
      "id": "save-clip",
      "name": "Save Clip to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2240,
        440
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "clipUrl",
              "value": "=https://drive.google.com/uc?export=download&id={{ $json.id }}",
              "type": "string"
            },
            {
              "id": "2",
              "name": "sceneNumber",
              "value": "={{ $('Split Into Scenes').item.json.scene_number }}",
              "type": "number"
            },
            {
              "id": "3",
              "name": "narration",
              "value": "={{ $('Split Into Scenes').item.json.narration }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "store-clip",
      "name": "Store Clip Info",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        2460,
        440
      ]
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "id": "aggregate-clips",
      "name": "Aggregate Clips",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        2680,
        440
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "combinationMode": "mergeByPosition"
      },
      "id": "merge-data",
      "name": "Merge Audio + Clips",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        2900,
        340
      ]
    },
    {
      "parameters": {
        "jsCode": "const audioUrl = $input.first().json.audioUrl;\nconst allInputs = $input.all();\nconst clipsData = allInputs.filter(item => item.json.sceneNumber);\nconst sortedClips = clipsData.sort((a, b) => a.json.sceneNumber - b.json.sceneNumber);\n\nconst elements = sortedClips.map((clip, index) => ({\n  id: `scene${index + 1}`,\n  source: clip.json.clipUrl,\n  track: 1,\n  time: index * 10,\n  duration: 10,\n  animations: [\n    {\n      type: \"fade\",\n      fade: \"in\",\n      duration: 0.5\n    },\n    {\n      type: \"fade\",\n      fade: \"out\",\n      duration: 0.5\n    }\n  ]\n}));\n\nelements.push({\n  id: \"audio\",\n  source: audioUrl,\n  track: 2,\n  volume: 1\n});\n\nreturn {\n  json: {\n    elements: elements,\n    duration: 50,\n    width: 1080,\n    height: 1920,\n    frameRate: 30\n  }\n};"
      },
      "id": "prepare-creatomate",
      "name": "Prepare Creatomate JSON",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        3120,
        340
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.creatomate.com/v1/renders",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_CREATOMATE_API_KEY_HERE"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"template_id\": null,\n  \"elements\": {{ JSON.stringify($json.elements) }},\n  \"width\": 1080,\n  \"height\": 1920,\n  \"frame_rate\": 30,\n  \"duration\": 50\n}"
      },
      "id": "render-video",
      "name": "Render Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3340,
        340
      ]
    },
    {
      "parameters": {
        "amount": 15
      },
      "id": "wait-render",
      "name": "Wait for Render",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        3560,
        340
      ]
    },
    {
      "parameters": {
        "url": "=https://api.creatomate.com/v1/renders/{{ $('Render Video').item.json.id }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_CREATOMATE_API_KEY_HERE"
            }
          ]
        }
      },
      "id": "check-status",
      "name": "Check Render Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        3780,
        340
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "operation": "equals",
              "value2": "succeeded"
            }
          ]
        }
      },
      "id": "check-done",
      "name": "Is Done?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        4000,
        340
      ]
    },
    {
      "parameters": {
        "amount": 10
      },
      "id": "wait-retry",
      "name": "Wait & Retry",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        3780,
        540
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "download-final",
      "name": "Download Final Video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        4220,
        340
      ]
    },
    {
      "parameters": {
        "name": "=mindframe_{{ $now.format('YYYYMMDD_HHmmss') }}.mp4",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": "root"
        }
      },
      "id": "save-final",
      "name": "Save Final to Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        4440,
        340
      ]
    },
    {
      "parameters": {
        "chatId": "7396144253",
        "text": "=\ud83c\udfac *NEW MINDFRAME VIDEO READY!*\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\n\n\ud83d\udcfa *Title:* {{ $('Parse Script').first().json.title }}\n\n\ud83d\udcca *Details:*\n\u2022 Topic: {{ $('Parse Script').first().json.topic }}\n\u2022 Duration: 50 seconds\n\u2022 Resolution: 1080x1920 (9:16)\n\u2022 Scenes: 5 AI-curated clips\n\n\ud83c\udfa5 *DOWNLOAD:*\nhttps://drive.google.com/file/d/{{ $json.id }}/view\n\n\u23f0 Created: {{ $now.format('MMM DD, YYYY - hh:mm A') }} GST\n\n\u2705 Ready to upload to YouTube!\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501",
        "additionalFields": {}
      },
      "id": "send-telegram",
      "name": "Send Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        4660,
        340
      ]
    }
  ],
  "connections": {
    "Daily Trigger 2PM Dubai": {
      "main": [
        [
          {
            "node": "Generate 5 Ideas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate 5 Ideas": {
      "main": [
        [
          {
            "node": "Pick Best Idea",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick Best Idea": {
      "main": [
        [
          {
            "node": "Generate Title",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Title": {
      "main": [
        [
          {
            "node": "Generate Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Script": {
      "main": [
        [
          {
            "node": "Parse Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Script": {
      "main": [
        [
          {
            "node": "Generate Voice",
            "type": "main",
            "index": 0
          },
          {
            "node": "Split Into Scenes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Voice": {
      "main": [
        [
          {
            "node": "Save Audio to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Audio to Drive": {
      "main": [
        [
          {
            "node": "Store Audio URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Audio URL": {
      "main": [
        [
          {
            "node": "Merge Audio + Clips",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Into Scenes": {
      "main": [
        [
          {
            "node": "Search Pexels Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Pexels Video": {
      "main": [
        [
          {
            "node": "Download Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Video": {
      "main": [
        [
          {
            "node": "Save Clip to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Clip to Drive": {
      "main": [
        [
          {
            "node": "Store Clip Info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store Clip Info": {
      "main": [
        [
          {
            "node": "Aggregate Clips",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate Clips": {
      "main": [
        [
          {
            "node": "Merge Audio + Clips",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Audio + Clips": {
      "main": [
        [
          {
            "node": "Prepare Creatomate JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Creatomate JSON": {
      "main": [
        [
          {
            "node": "Render Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Render Video": {
      "main": [
        [
          {
            "node": "Wait for Render",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Render": {
      "main": [
        [
          {
            "node": "Check Render Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Render Status": {
      "main": [
        [
          {
            "node": "Is Done?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Done?": {
      "main": [
        [
          {
            "node": "Download Final Video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait & Retry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait & Retry": {
      "main": [
        [
          {
            "node": "Check Render Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Final Video": {
      "main": [
        [
          {
            "node": "Save Final to Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Final to Drive": {
      "main": [
        [
          {
            "node": "Send Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2024-01-01T00:00:00.000Z",
  "versionId": "1"
}