{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "a0f7596f-7d8e-4e7f-b297-de004d6c2d57",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        8592,
        3472
      ],
      "parameters": {
        "width": 480,
        "height": 896,
        "content": "## Automated YouTube SEO, Thumbnail Generation & Video Upload via AI, Google Drive & LemonFox\n\n### How it works\n\n1. A Google Drive trigger initiates the workflow upon new file detection. 2. The system retrieves temporary access and sends the file to a transcription service. 3. Text content is cleaned, saved, and processed to extract key information. 4. An AI agent analyzes the content and generates a representative image. 5. The final output is uploaded to YouTube, followed by automated cleanup of temporary resources.\n\n### Setup steps\n\n- Configure the Google Drive Trigger with appropriate folder permissions.\n- Connect LemonFox credentials for the audio transcription service.\n- Set up Google Gemini credentials for the AI agent and image generation.\n- Configure YouTube API credentials for the final video upload.\n\n### Customization\n\nAdjust the AI prompt in the Gemini node to change the style of the generated imagery or to provide more specific summarization parameters."
      },
      "typeVersion": 1
    },
    {
      "id": "985fed9a-d459-48a6-9c37-6f0107e2f510",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        9152,
        3472
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 288,
        "content": "## Trigger and access setup\n\nHandles initial file trigger and provides temporary access."
      },
      "typeVersion": 1
    },
    {
      "id": "52171ddf-9e0b-4d23-84c1-94db359d4992",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        9840,
        3456
      ],
      "parameters": {
        "color": 7,
        "width": 416,
        "height": 304,
        "content": "## Transcribe and clean SRT\n\nTranscribes the video file and cleans the output."
      },
      "typeVersion": 1
    },
    {
      "id": "7e70a54d-4a6e-4a6f-97fc-633807b7595d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        10288,
        3472
      ],
      "parameters": {
        "color": 7,
        "width": 784,
        "height": 272,
        "content": "## Manage processed file content\n\nSaves text and retrieves file for processing."
      },
      "typeVersion": 1
    },
    {
      "id": "dffcd2f2-acf1-4561-814a-eb434c71b9b8",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        11088,
        3472
      ],
      "parameters": {
        "color": 7,
        "width": 608,
        "height": 480,
        "content": "## Process with AI agent\n\nUses AI to analyze content and generate imagery."
      },
      "typeVersion": 1
    },
    {
      "id": "45890858-3248-4257-b4ee-a255dcd715b0",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        11728,
        3456
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 304,
        "content": "## Upload and finalize results\n\nUploads the final media and cleans up resources."
      },
      "typeVersion": 1
    },
    {
      "id": "c9a133b1-66e0-4d20-81d8-cd2102b3fac1",
      "name": "Post Audio to Lemonfox",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        9888,
        3584
      ],
      "parameters": {
        "url": "https://api.lemonfox.ai/v1/audio/transcriptions",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "form-urlencoded",
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "file",
              "value": "=https://drive.google.com/uc?id={{ $('When File Added in Drive').item.json.id }}&export=download"
            },
            {
              "name": "language",
              "value": "english"
            },
            {
              "name": "response_format",
              "value": "srt"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth"
      },
      "typeVersion": 4.4
    },
    {
      "id": "c44c6d1f-23b3-43bd-b9e1-1d71696807fa",
      "name": "When File Added in Drive",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        9200,
        3600
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 1
    },
    {
      "id": "93c0db85-02ae-478d-8705-f2a0f56d310c",
      "name": "Grant Temp File Access",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        9648,
        3584
      ],
      "parameters": {
        "url": "=https://www.googleapis.com/drive/v3/files/{{ $json.id }}/permissions",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "role",
              "value": "reader"
            },
            {
              "name": "type",
              "value": "anyone"
            }
          ]
        },
        "nodeCredentialType": "googleDriveOAuth2Api"
      },
      "typeVersion": 4.4
    },
    {
      "id": "de9483e2-a087-49f4-8691-0d8ea6eb7b78",
      "name": "If Video Mime Type",
      "type": "n8n-nodes-base.if",
      "position": [
        9424,
        3600
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "1c5b08b2-616c-4802-b613-6ab4ce706487",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.mimeType }}",
              "rightValue": "video"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "94de4f1b-1d36-43d8-872d-a6aa6b54f4bb",
      "name": "Content Analysis Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        11200,
        3584
      ],
      "parameters": {
        "text": "=**You are an expert YouTube Content Strategist and SEO Specialist. Your task is to transform the provided video transcript into a fully optimized YouTube metadata package (Title, Description, Tags, and Hashtags) designed for high CTR and search discoverability.**\n\n---\n\n**Video Transcript:** `{{ $('Post Audio to Lemonfox').item.json.data }}`\n\n\n\n---\n\n### **Instructions:**\n\n1.  **Analyze the Transcript:** Identify the \"Big Idea,\" key takeaways, and the most clickable moment to form the basis of the title and hook.\n2.  **Video Title:** Create a compelling, high-CTR title (under 70 characters). Balance SEO keywords with psychological triggers (curiosity, urgency, or transformation).\n3.  **Video Description:**\n    * **The Hook:** A strong opening sentence that summarizes the value.\n    * **The Summary:** A concise, engaging breakdown of what the viewer will learn (150\u2013300 words).\n    * **Formatting:** Use clean spacing and bullet points for readability.\n    * **Call to Action:** Include a prompt for viewers to subscribe or comment on a specific topic from the video.\n4.  **Tags & Hashtags:** * Generate 15\u201320 relevant SEO tags (comma-separated).\n    * Generate 3\u20135 high-reach hashtags.\n5.  **Thumbnail Prompt:** Create a detailed AI image prompt for a 16:9 YouTube thumbnail. Focus on high contrast, \"face-to-camera\" emotion (if applicable), and bold text overlay suggestions.\n\n---\n\n**Sponsors:** `{{ $json.data }}`\n\n### **Sponsor Handling:**\n\n* Check the \"Sponsors\" input.\n* **If sponsors exist:** * Include a \"Sponsored By\" section at the top of the `video_description`.\n    * Extract and list their **name** and **email**.\n* **If no sponsors exist:** Return an empty array for the sponsors key.\n* And this sponsors had nothingh to do with the description or title so just extract the sponsor seperately.\n---\n\n### **Output Format:**\n\nReturn **strictly** a valid JSON object with the following structure:\n\n```json\n{\n  \"video_title\": \"Your optimized YouTube title here\",\n  \"video_description\": \"Your full SEO description including sponsor mentions...\",\n  \"tags\": \"tag1, tag2, tag3, tag4...\",\n  \"hashtags\": \"#hashtag1 #hashtag2 #hashtag3\",\n  \"thumbnail_prompt\": \"Detailed 16:9 AI image generation prompt here...\",\n  \"sponsors\": [\n    {\n      \"sponsor_name\": \"Sponsor Name\",\n      \"sponsor_email\": \"email@example.com\"\n    }\n  ]\n}\n```",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "fb304320-25b0-4f74-af42-0aa446604a27",
      "name": "Search Drive Files",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        10560,
        3584
      ],
      "parameters": {
        "limit": 1,
        "filter": {
          "driveId": {
            "mode": "list",
            "value": "My Drive"
          },
          "folderId": {
            "mode": "list",
            "value": "root",
            "cachedResultName": "/ (Root folder)"
          },
          "whatToSearch": "all"
        },
        "options": {},
        "resource": "fileFolder",
        "queryString": "={{ $('When File Added in Drive').item.json.name.replace(/\\.[^/.]+$/, '') }}_sponsors.txt"
      },
      "typeVersion": 3
    },
    {
      "id": "8a389f9e-6f18-451d-9237-961b4185f48e",
      "name": "Fetch File Details",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        10752,
        3584
      ],
      "parameters": {
        "url": "=https://www.googleapis.com/drive/v3/files/{{ $json.id }}",
        "options": {
          "redirect": {
            "redirect": {}
          },
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "filename.txt"
            }
          }
        },
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "alt",
              "value": "media"
            }
          ]
        },
        "nodeCredentialType": "googleDriveOAuth2Api"
      },
      "typeVersion": 4.4
    },
    {
      "id": "a1579be9-335e-44ac-bb77-e1d51949d65e",
      "name": "Extract Content from File",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        10928,
        3584
      ],
      "parameters": {
        "options": {},
        "operation": "text",
        "binaryPropertyName": "filename.txt"
      },
      "typeVersion": 1.1
    },
    {
      "id": "a06998d5-1eb0-45bf-a2ff-0f23a2a30e9b",
      "name": "Create Text File in Drive",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        10336,
        3584
      ],
      "parameters": {
        "name": "={{ $('When File Added in Drive').item.json.name.replace(/\\.[^/.]+$/, '') }}.srt",
        "content": "={{ $json.srt }}",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "options": {},
        "folderId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "operation": "createFromText"
      },
      "typeVersion": 3
    },
    {
      "id": "5e410c04-6bd0-4d7a-b06a-9e13491e2241",
      "name": "Clean SRT Content",
      "type": "n8n-nodes-base.code",
      "position": [
        10112,
        3584
      ],
      "parameters": {
        "jsCode": "// Get raw string\nlet raw = $json.data;\n\n// Step 1: Remove wrapping quotes if present\nif (raw.startsWith('\"') && raw.endsWith('\"')) {\n  raw = raw.slice(1, -1);\n}\n\n// Step 2: Unescape characters\nraw = raw\n  .replace(/\\\\\"/g, '\"')   // \\\" \u2192 \"\n  .replace(/\\\\n/g, '\\n'); // \\n \u2192 actual newline\n\n// Step 3: Clean extra blank lines (optional but nice)\nraw = raw.replace(/\\n{3,}/g, '\\n\\n').trim();\n\n// Return as clean SRT\nreturn [\n  {\n    json: {\n      srt: raw\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "7b25cb82-2de0-499f-a3ce-3ef9b9a41671",
      "name": "Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        11136,
        3808
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-3.1-flash-lite-preview"
      },
      "typeVersion": 1
    },
    {
      "id": "643b4eac-94b6-4326-970c-1e34d7351f42",
      "name": "Parse Structured Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        11392,
        3808
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{\n  \"video_title\": \"Your optimized YouTube title here\",\n  \"video_description\": \"Your full SEO description including sponsor mentions...\",\n  \"tags\": \"tag1, tag2, tag3, tag4...\",\n  \"hashtags\": \"#hashtag1 #hashtag2 #hashtag3\",\n  \"thumbnail_prompt\": \"Detailed 16:9 AI image generation prompt here...\",\n  \"sponsors\": [\n    {\n      \"sponsor_name\": \"Sponsor Name\",\n      \"sponsor_email\": \"user@example.com\"\n    }\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "fd9e4fe0-818a-4e08-96d9-35227012bf2d",
      "name": "Gemini Analysis Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        11328,
        4016
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-3.1-flash-lite-preview"
      },
      "typeVersion": 1
    },
    {
      "id": "6eb6c4c1-79e2-486e-ab3d-b0ef8e48f3e2",
      "name": "Generate Thumbnail Image",
      "type": "@n8n/n8n-nodes-langchain.googleGemini",
      "position": [
        11552,
        3584
      ],
      "parameters": {
        "prompt": "={{ $json.output.thumbnail_prompt }}",
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "models/gemini-2.5-flash-image",
          "cachedResultName": "models/gemini-2.5-flash-image (Nano Banana)"
        },
        "options": {},
        "resource": "image"
      },
      "typeVersion": 1.1
    },
    {
      "id": "8635863c-3c8e-44b8-bc4d-964aa07d11d5",
      "name": "Upload to YouTube API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        11776,
        3584
      ],
      "parameters": {
        "url": "https://api.upload-post.com/api/upload",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "video",
              "value": "=https://drive.google.com/uc?export=download&id={{ $('When File Added in Drive').item.json.id }}"
            },
            {
              "name": "title",
              "value": "={{ $('Content Analysis Agent').item.json.output.video_title }}"
            },
            {
              "name": "description",
              "value": "={{ $('Content Analysis Agent').item.json.output.video_description }}"
            },
            {
              "name": "user",
              "value": "enter-your-username"
            },
            {
              "name": "platform[]",
              "value": "youtube"
            },
            {
              "name": "thumbnail",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Apikey enter-your-api-key"
            }
          ]
        }
      },
      "typeVersion": 4.4
    },
    {
      "id": "01f4377d-4921-4764-9b9a-af9d88e5b2c4",
      "name": "Delete Original File permissions in Drive",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        11984,
        3584
      ],
      "parameters": {
        "url": "=https://www.googleapis.com/drive/v3/files/{{ $('When File Added in Drive').item.json.id }}/permissions/anyoneWithLink",
        "method": "DELETE",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleDriveOAuth2Api"
      },
      "typeVersion": 4.4
    }
  ],
  "connections": {
    "Clean SRT Content": {
      "main": [
        [
          {
            "node": "Create Text File in Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Content Analysis Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Fetch File Details": {
      "main": [
        [
          {
            "node": "Extract Content from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Video Mime Type": {
      "main": [
        [
          {
            "node": "Grant Temp File Access",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Drive Files": {
      "main": [
        [
          {
            "node": "Fetch File Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Analysis Model": {
      "ai_languageModel": [
        [
          {
            "node": "Parse Structured Output",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Upload to YouTube API": {
      "main": [
        [
          {
            "node": "Delete Original File permissions in Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Content Analysis Agent": {
      "main": [
        [
          {
            "node": "Generate Thumbnail Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Grant Temp File Access": {
      "main": [
        [
          {
            "node": "Post Audio to Lemonfox",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post Audio to Lemonfox": {
      "main": [
        [
          {
            "node": "Clean SRT Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Structured Output": {
      "ai_outputParser": [
        [
          {
            "node": "Content Analysis Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Generate Thumbnail Image": {
      "main": [
        [
          {
            "node": "Upload to YouTube API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When File Added in Drive": {
      "main": [
        [
          {
            "node": "If Video Mime Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Text File in Drive": {
      "main": [
        [
          {
            "node": "Search Drive Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Content from File": {
      "main": [
        [
          {
            "node": "Content Analysis Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}