{
  "name": "Product Ad Machine",
  "nodes": [
    {
      "parameters": {},
      "id": "n0",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -256,
        -64
      ]
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "returnAll": true,
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "YOUR_PRODUCTS_FOLDER_ID"
          },
          "whatToSearch": "folders"
        },
        "options": {
          "fields": [
            "id",
            "name"
          ]
        }
      },
      "id": "n1",
      "name": "List Product Folders",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        160,
        112
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "options": {}
      },
      "id": "n2",
      "name": "Read Ledger",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        368,
        112
      ],
      "alwaysOutputData": true,
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const known=new Set($input.all().map(r=>String(r.json.folderId||'')).filter(Boolean));\nconst folders=$('List Product Folders').all().map(r=>r.json);\nconst fresh=folders.filter(f=>!known.has(String(f.id)));\nreturn [{json:{fresh, freshCount:fresh.length}}];"
      },
      "id": "n3",
      "name": "Find New",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        576,
        112
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 1
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.freshCount }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "n4",
      "name": "Any New?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        784,
        112
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "fresh",
        "options": {}
      },
      "id": "n5",
      "name": "Split New",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        992,
        112
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "folderId": "={{ $json.id }}",
            "productName": "={{ $json.name }}",
            "status": "queue",
            "createdAt": "={{ $now.toISO() }}"
          }
        },
        "options": {}
      },
      "id": "n6",
      "name": "Append Rows",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1200,
        112
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "status",
              "lookupValue": "queue"
            }
          ]
        },
        "options": {}
      },
      "id": "n7",
      "name": "Read Pending",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        160,
        480
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {},
      "id": "n8",
      "name": "Pick One",
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        368,
        480
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "folderId": "={{ $json.folderId }}",
            "status": "prepping-images"
          },
          "matchingColumns": [
            "folderId"
          ]
        },
        "options": {}
      },
      "id": "n9",
      "name": "Mark Processing",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        576,
        480
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "fileFolder",
        "returnAll": true,
        "filter": {
          "folderId": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $('Pick One').item.json.folderId }}"
          },
          "whatToSearch": "files"
        },
        "options": {
          "fields": [
            "id",
            "name",
            "mimeType"
          ]
        }
      },
      "id": "n10",
      "name": "List Product Files",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        784,
        480
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const files=$input.all().map(r=>r.json);\nconst row=$('Pick One').item.json;\nconst logo=files.find(f=>/^logo\\./i.test(f.name));\nconst prod=files.find(f=>/^product\\d*\\./i.test(f.name) && !/scene/i.test(f.name));\nconst instr=files.find(f=>/^instructions\\.txt$/i.test(f.name));\nif(!logo||!prod) throw new Error('missing logo.* or product.* in folder '+row.productName);\nconst dl=id=>`https://drive.google.com/uc?export=download&id=${id}`;\nconst MUSIC=[\"https://drive.google.com/uc?export=download&id=1CICEFD2NiGq_k__U0eJI5zQlh4faxaVO\", \"https://drive.google.com/uc?export=download&id=1TbQIJrquDgVRQSw4uVyP04Kly-uCQLzq\", \"https://drive.google.com/uc?export=download&id=1uzGd-2-paNGGtz5Gb8biCy2YwagODxHz\", \"https://drive.google.com/uc?export=download&id=1hke14OpMbvoh68-Y-ZJYNMbE-ZM3nVKI\", \"https://drive.google.com/uc?export=download&id=123BjRDk6Sse_B_WLq9zLjqUpCFtT8r2j\"];\nconst music=MUSIC[Math.floor(Math.random()*MUSIC.length)];\nreturn [{json:{folderId:row.folderId, productName:row.productName, logoId:logo.id, prodId:prod.id,\n  instrId:instr?instr.id:null, logoUrl:dl(logo.id), prodUrl:dl(prod.id), musicUrl:music}}];"
      },
      "id": "n11",
      "name": "Resolve Assets",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        992,
        480
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://www.googleapis.com/drive/v3/files/{{ $json.logoId }}/permissions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleDriveOAuth2Api",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\"role\":\"reader\",\"type\":\"anyone\"}",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "n12",
      "name": "Share Logo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        480
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://www.googleapis.com/drive/v3/files/{{ $('Resolve Assets').item.json.prodId }}/permissions",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleDriveOAuth2Api",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\"role\":\"reader\",\"type\":\"anyone\"}",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "n13",
      "name": "Share Product",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1424,
        480
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://www.googleapis.com/drive/v3/files/{{ $('Resolve Assets').item.json.instrId || 'none' }}?alt=media",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "googleDriveOAuth2Api",
        "options": {
          "response": {
            "response": {
              "neverError": true
            }
          }
        }
      },
      "id": "n14",
      "name": "Get Instructions",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1632,
        480
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const a=$('Resolve Assets').item.json;\nlet txt='';\ntry{ if(a.instrId){ const d=$input.item.json; txt=typeof d==='string'?d:(d.data||''); } }catch(e){}\nconst sec={logo:'',product:'',morph:''};\nlet cur=null;\nfor(const line of String(txt).split(/\\r?\\n/)){\n  const m=line.match(/^\\s*\\[(logo|product|morph)\\]\\s*$/i);\n  if(m){cur=m[1].toLowerCase();continue;}\n  if(cur&&line.trim()) sec[cur]+=(sec[cur]?' ':'')+line.trim();\n}\nconst keepColors=/keep.{0,12}colou?rs?/i.test(sec.logo);\nconst plateUrl='https://drive.google.com/uc?export=download&id=1PPSrOW6ipzqOBkv8ILd-x5zkzAivs6ON';\nreturn [{json:{...a, keepColors, addLogo:sec.logo, addProduct:sec.product, addMorph:sec.morph}}];"
      },
      "id": "n15",
      "name": "Parse Instructions",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1840,
        480
      ]
    },
    {
      "parameters": {
        "jsCode": "const a=$json;\nconst plateUrl='https://drive.google.com/uc?export=download&id=1Tt4hnWV0ZpEqvOXdJemhBlpCLBeuoV6B';\nconst recolor=a.keepColors?'':'lutrgb=r=255:g=255:b=255,';\nconst logoFilter=`[1:v]format=rgba,${recolor}scale=840:-1[l];[0:v][l]overlay=(W-w)/2:(H-h)/2`;\nreturn [{json:{...a, plateUrl, logoFilter}}];"
      },
      "id": "n16",
      "name": "Build Logo Job",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        160,
        848
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://fal.run/fal-ai/imageutils/rembg",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({image_url: $('Parse Instructions').item.json.prodUrl, crop_to_bbox: true}) }}",
        "options": {}
      },
      "id": "n22",
      "name": "BiRefNet Cutout",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        160,
        1216
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const cutUrl=$json.image.url;\nconst plateUrl='https://drive.google.com/uc?export=download&id=1Tt4hnWV0ZpEqvOXdJemhBlpCLBeuoV6B';\nconst prodFilter=`[1:v]format=rgba,scale=1080:1267:force_original_aspect_ratio=decrease[p];[0:v][p]overlay=(W-w)/2:(H-h)/2`;\nreturn [{json:{plateUrl, cutUrl, prodFilter}}];"
      },
      "id": "n23",
      "name": "Build Product Job",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        368,
        1216
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "folderId": "={{ $('Parse Instructions').item.json.folderId }}",
            "status": "animating"
          },
          "matchingColumns": [
            "folderId"
          ]
        },
        "options": {}
      },
      "id": "n29",
      "name": "Mark Animating",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1632,
        1216
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const base=\"@Image1 shows a flat brand logo centred on a dark studio background. The logo begins rotating slowly and smoothly around its vertical axis, gaining gentle depth \\u2014 the SAME letters and shapes, unchanged in outline and colour, becoming solid extruded letterforms with slight thickness and softly bevelled edges. BEFORE it turns more than a quarter turn \\u2014 around 45 to 90 degrees, while the logo is still clearly facing the viewer \\u2014 the metamorphosis begins: the letterforms bend, melt and re-form, their surface material stretching and evolving directly into the product's material and shape, so @Image2, the hero product, visibly grows out of the logo's own substance in one continuous, gradual, unhurried shape-shift. The logo never completes a full rotation, never spins away, never slides out of frame, and is never replaced by something appearing behind it. Well before the end, the product's own motion and internal physics \\u2014 liquid, cloth, dangling parts, wobble \\u2014 fully settle into a steady state, so the product hangs still and at rest in the exact centre of the frame, while the camera's gentle movement eases gradually to a complete stop by the final frame. The single subject stays alone in a clean, minimal, uncluttered scene for the whole clip. Slow, cinematic, smooth easing, photorealistic.\";\nconst add=($('Parse Instructions').item.json.addMorph||'').trim();\nconst prompt = add ? (add.startsWith('!') ? add.slice(1).trim() : base+' '+add) : base;\nreturn [{json:{morph:{start_image_url:$('Logo URL').item.json.url, end_image_url:$('Product URL').item.json.url, duration:'7', prompt}}}];"
      },
      "id": "n30",
      "name": "Build Morph",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        160,
        1584
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://queue.fal.run/fal-ai/kling-video/o1/image-to-video",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.morph) }}",
        "options": {}
      },
      "id": "n31",
      "name": "Kling Submit",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        368,
        1584
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 15
      },
      "id": "n32",
      "name": "Wait Kling",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        576,
        1584
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Kling Submit').item.json.status_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "n33",
      "name": "Poll Kling",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        784,
        1584
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 1
          },
          "conditions": [
            {
              "id": "c",
              "leftValue": "={{ $json.status }}",
              "rightValue": "COMPLETED",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "n34",
      "name": "Kling Done?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        992,
        1584
      ]
    },
    {
      "parameters": {
        "url": "={{ $('Kling Submit').item.json.response_url }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "n35",
      "name": "Kling Result",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        1584
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "folderId": "={{ $('Parse Instructions').item.json.folderId }}",
            "status": "scoring"
          },
          "matchingColumns": [
            "folderId"
          ]
        },
        "options": {}
      },
      "id": "n36",
      "name": "Mark Scoring",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1632,
        1584
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const klingUrl=$('Kling Result').item.json.video.url;\nconst musicUrl=$('Parse Instructions').item.json.musicUrl;\nconst vf='scale=1080:1920:force_original_aspect_ratio=decrease,pad=1080:1920:(ow-iw)/2:(oh-ih)/2,setsar=1,tpad=stop_mode=clone:stop_duration=3';\nreturn [{json:{klingUrl, musicUrl, vf}}];"
      },
      "id": "n37",
      "name": "Build Score Job",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        160,
        1952
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "n43",
      "name": "DL Final",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        160,
        2320
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "name": "final.mp4",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Parse Instructions').item.json.folderId }}"
        },
        "options": {}
      },
      "id": "n44",
      "name": "Upload final.mp4",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        368,
        2320
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $('Build Score Job').item.json.klingUrl }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "n45",
      "name": "DL Morph",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        576,
        2320
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "name": "morph.mp4",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Parse Instructions').item.json.folderId }}"
        },
        "options": {}
      },
      "id": "n46",
      "name": "Upload morph.mp4",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        784,
        2320
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $('Logo URL').item.json.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "n47",
      "name": "DL LogoScene",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        992,
        848
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "name": "logo-scene-9x16.png",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Parse Instructions').item.json.folderId }}"
        },
        "options": {}
      },
      "id": "n48",
      "name": "Upload logo-scene",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1200,
        848
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "url": "={{ $('Product URL').item.json.url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "n49",
      "name": "DL ProdScene",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1200,
        1216
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "parameters": {
        "name": "product-scene-9x16.png",
        "driveId": {
          "__rl": true,
          "mode": "list",
          "value": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Parse Instructions').item.json.folderId }}"
        },
        "options": {}
      },
      "id": "n50",
      "name": "Upload product-scene",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        1424,
        1216
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleDriveOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "folderId": "={{ $('Parse Instructions').item.json.folderId }}",
            "status": "done",
            "videoUrl": "={{ $('Upload final.mp4').item.json.webViewLink }}",
            "completedAt": "={{ $now.toISO() }}"
          },
          "matchingColumns": [
            "folderId"
          ]
        },
        "options": {}
      },
      "id": "n51",
      "name": "Mark Done",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        992,
        2320
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "path": "product-ad-machine",
        "options": {}
      },
      "id": "tmpwh",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -256,
        112
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "YOUR_LEDGER_SHEET_ID"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Sheet1"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "folderId": "={{ $('Pick One').item.json.folderId }}",
            "status": "error"
          },
          "matchingColumns": [
            "folderId"
          ]
        },
        "options": {}
      },
      "id": "xMarkError",
      "name": "Mark Error",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        160,
        3072
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 1
          },
          "conditions": [
            {
              "id": "f",
              "leftValue": "={{ $json.status }}",
              "rightValue": "FAILED",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "xKlingFailed",
      "name": "Kling Failed?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1424,
        1584
      ]
    },
    {
      "parameters": {
        "inputs": {
          "input": [
            {
              "url": "={{ $json.plateUrl }}"
            },
            {
              "url": "={{ $json.logoUrl }}"
            }
          ]
        },
        "outputFormat": "png",
        "options": {
          "option": [
            {
              "option": "-frames:v",
              "argument": "1"
            }
          ]
        },
        "filters": {
          "filter": [
            {
              "filter": "={{ $json.logoFilter }}"
            }
          ]
        }
      },
      "name": "Compose Logo",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        368,
        848
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "id": "e25d1c4c-4fdc-4c95-a188-a3f509c98761",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "wait",
        "jobId": "={{ $('Compose Logo').item.json.id }}",
        "pollInterval": 5,
        "timeout": 600
      },
      "name": "Wait Logo",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        576,
        848
      ],
      "id": "e4d69fdf-ec96-411d-9ddb-ddd1e9e3b60d",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "operation": "getDownloadUrl",
        "jobId": "={{ $('Compose Logo').item.json.id }}"
      },
      "name": "Logo URL",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        784,
        848
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "id": "3671d973-474d-4557-9272-6bc48adffaed",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "inputs": {
          "input": [
            {
              "url": "={{ $json.plateUrl }}"
            },
            {
              "url": "={{ $json.cutUrl }}"
            }
          ]
        },
        "outputFormat": "png",
        "options": {
          "option": [
            {
              "option": "-frames:v",
              "argument": "1"
            }
          ]
        },
        "filters": {
          "filter": [
            {
              "filter": "={{ $json.prodFilter }}"
            }
          ]
        }
      },
      "name": "Compose Product",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        576,
        1216
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "id": "4fca6066-e853-48e3-b78a-873806615a28",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "wait",
        "jobId": "={{ $('Compose Product').item.json.id }}",
        "pollInterval": 5,
        "timeout": 600
      },
      "name": "Wait Product",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        784,
        1216
      ],
      "id": "28032116-8746-4475-9d5a-833f44d0250e",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "operation": "getDownloadUrl",
        "jobId": "={{ $('Compose Product').item.json.id }}"
      },
      "name": "Product URL",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        992,
        1216
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "id": "4d64fded-0335-40fa-8852-075af9459364",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "inputs": {
          "input": [
            {
              "url": "={{ $json.klingUrl }}"
            },
            {
              "url": "={{ $json.musicUrl }}"
            }
          ]
        },
        "options": {
          "option": [
            {
              "option": "-vf",
              "argument": "={{ $json.vf }}"
            },
            {
              "option": "-map",
              "argument": "0:v"
            },
            {
              "option": "-map",
              "argument": "1:a"
            },
            {
              "option": "-c:v",
              "argument": "libx264"
            },
            {
              "option": "-crf",
              "argument": "18"
            },
            {
              "option": "-c:a",
              "argument": "aac"
            },
            {
              "option": "-pix_fmt",
              "argument": "yuv420p"
            },
            {
              "option": "-shortest"
            }
          ]
        }
      },
      "name": "Score",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        368,
        1952
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "id": "a1877a1a-1a0b-41a6-b0b2-8971bdb9fe1d",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "wait",
        "jobId": "={{ $('Score').item.json.id }}",
        "pollInterval": 5,
        "timeout": 600
      },
      "name": "Wait Score",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        576,
        1952
      ],
      "id": "5c353f4d-6068-489d-b742-226f9fd9a015",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "operation": "getDownloadUrl",
        "jobId": "={{ $('Score').item.json.id }}"
      },
      "name": "Final URL",
      "type": "@ffmpeg-micro/n8n-nodes-ffmpeg-micro.ffmpegMicro",
      "typeVersion": 1,
      "position": [
        784,
        1952
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000,
      "id": "db4ce8f1-da33-44d8-a6e7-b295044081bf",
      "credentials": {
        "ffmpegMicroApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "uploadVideo",
        "user": "YOUR_UPLOAD_POST_PROFILE",
        "platform": [
          "instagram",
          "x",
          "youtube"
        ],
        "title": "={{ $('Parse Instructions').item.json.productName }}",
        "video": "={{ $('Final URL').item.json.url }}",
        "youtubePrivacyStatus": "unlisted"
      },
      "name": "Post to Socials",
      "type": "n8n-nodes-upload-post.uploadPost",
      "typeVersion": 1,
      "position": [
        160,
        2704
      ],
      "id": "566c6d74-e76b-4c2a-a442-6d1a495e3bf9",
      "credentials": {
        "uploadPostApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      },
      "name": "Every 30 min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -256,
        288
      ],
      "id": "3e218149-57d0-4870-9968-8f42a25a7ae6",
      "disabled": true
    },
    {
      "parameters": {
        "content": "# 1. Find new products\nSearch Drive folders, add new ones to the ledger",
        "height": 310,
        "width": 1420,
        "color": 4
      },
      "name": "\u00a7 1 Find new products",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        0
      ],
      "id": "c3a998ae-0d7b-46b7-aa5e-67cb69dde963"
    },
    {
      "parameters": {
        "content": "# 2. Pick & prep one\nGrab one pending product and share its assets",
        "height": 310,
        "width": 2050,
        "color": 3
      },
      "name": "\u00a7 2 Pick & prep one",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        384
      ],
      "id": "1aae9ab7-7bd1-4584-940c-41ecfd5458c8"
    },
    {
      "parameters": {
        "content": "# 3. Logo keyframe\nRecolor + composite the logo on the backdrop",
        "height": 310,
        "width": 1420,
        "color": 5
      },
      "name": "\u00a7 3 Logo keyframe",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        752
      ],
      "id": "90edf333-79ff-4a63-a9a9-86fd2d3721b8"
    },
    {
      "parameters": {
        "content": "# 4. Product keyframe\nfal.ai cutout + composite the product",
        "height": 310,
        "width": 1840,
        "color": 6
      },
      "name": "\u00a7 4 Product keyframe",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        1120
      ],
      "id": "72c6c106-64fa-41e3-8d6e-646faf67aa06"
    },
    {
      "parameters": {
        "content": "# 5. Morph\nfal.ai (Kling) animates logo into product",
        "height": 310,
        "width": 1840,
        "color": 7
      },
      "name": "\u00a7 5 Morph",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        1488
      ],
      "id": "3f5b7ea9-245b-4a56-8926-262d98dbf77a"
    },
    {
      "parameters": {
        "content": "# 6. Score\nFFmpeg Micro: music + 1080x1920",
        "height": 310,
        "width": 1000,
        "color": 2
      },
      "name": "\u00a7 6 Score",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        1856
      ],
      "id": "fcb036c1-b5ba-4b3b-b992-1d523b77f4a0"
    },
    {
      "parameters": {
        "content": "# 7. Deliver\nSave final.mp4 + assets to Drive, mark done",
        "height": 310,
        "width": 1210
      },
      "name": "\u00a7 7 Deliver",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        2224
      ],
      "id": "0374f6e7-af1c-4a57-808d-47e3682bc4b8"
    },
    {
      "parameters": {
        "content": "# 8. Distribute\nPost to socials (Upload-Post)",
        "height": 310,
        "width": 560,
        "color": 5
      },
      "name": "\u00a7 8 Distribute",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        2592
      ],
      "id": "d63122ec-b931-450d-acc9-239f333f2c3a"
    },
    {
      "parameters": {
        "content": "# 9. Error\nAny stage failure lands here",
        "height": 310,
        "width": 560,
        "color": 7
      },
      "name": "\u00a7 9 Error",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        32,
        2960
      ],
      "id": "418b6aea-d9e8-4733-9c7c-1572af1d9569"
    }
  ],
  "connections": {
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "List Product Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Product Folders": {
      "main": [
        [
          {
            "node": "Read Ledger",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Ledger": {
      "main": [
        [
          {
            "node": "Find New",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find New": {
      "main": [
        [
          {
            "node": "Any New?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Any New?": {
      "main": [
        [
          {
            "node": "Split New",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Read Pending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split New": {
      "main": [
        [
          {
            "node": "Append Rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Rows": {
      "main": [
        [
          {
            "node": "Read Pending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Pending": {
      "main": [
        [
          {
            "node": "Pick One",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick One": {
      "main": [
        [
          {
            "node": "Mark Processing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark Processing": {
      "main": [
        [
          {
            "node": "List Product Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Product Files": {
      "main": [
        [
          {
            "node": "Resolve Assets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Resolve Assets": {
      "main": [
        [
          {
            "node": "Share Logo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Share Logo": {
      "main": [
        [
          {
            "node": "Share Product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Share Product": {
      "main": [
        [
          {
            "node": "Get Instructions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Instructions": {
      "main": [
        [
          {
            "node": "Parse Instructions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Instructions": {
      "main": [
        [
          {
            "node": "Build Logo Job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Logo Job": {
      "main": [
        [
          {
            "node": "Compose Logo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "BiRefNet Cutout": {
      "main": [
        [
          {
            "node": "Build Product Job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Product Job": {
      "main": [
        [
          {
            "node": "Compose Product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark Animating": {
      "main": [
        [
          {
            "node": "Build Morph",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Morph": {
      "main": [
        [
          {
            "node": "Kling Submit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kling Submit": {
      "main": [
        [
          {
            "node": "Poll Kling",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Poll Kling": {
      "main": [
        [
          {
            "node": "Kling Done?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kling Done?": {
      "main": [
        [
          {
            "node": "Kling Result",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Kling Failed?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait Kling": {
      "main": [
        [
          {
            "node": "Poll Kling",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kling Result": {
      "main": [
        [
          {
            "node": "Mark Scoring",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark Scoring": {
      "main": [
        [
          {
            "node": "Build Score Job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Score Job": {
      "main": [
        [
          {
            "node": "Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DL Final": {
      "main": [
        [
          {
            "node": "Upload final.mp4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload final.mp4": {
      "main": [
        [
          {
            "node": "DL Morph",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DL Morph": {
      "main": [
        [
          {
            "node": "Upload morph.mp4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload morph.mp4": {
      "main": [
        [
          {
            "node": "Mark Done",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DL LogoScene": {
      "main": [
        [
          {
            "node": "Upload logo-scene",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload logo-scene": {
      "main": [
        [
          {
            "node": "BiRefNet Cutout",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "DL ProdScene": {
      "main": [
        [
          {
            "node": "Upload product-scene",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload product-scene": {
      "main": [
        [
          {
            "node": "Mark Animating",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kling Failed?": {
      "main": [
        [
          {
            "node": "Mark Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait Kling",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose Logo": {
      "main": [
        [
          {
            "node": "Wait Logo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait Logo": {
      "main": [
        [
          {
            "node": "Logo URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Logo URL": {
      "main": [
        [
          {
            "node": "DL LogoScene",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose Product": {
      "main": [
        [
          {
            "node": "Wait Product",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait Product": {
      "main": [
        [
          {
            "node": "Product URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Product URL": {
      "main": [
        [
          {
            "node": "DL ProdScene",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score": {
      "main": [
        [
          {
            "node": "Wait Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait Score": {
      "main": [
        [
          {
            "node": "Final URL",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Mark Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Final URL": {
      "main": [
        [
          {
            "node": "DL Final",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mark Done": {
      "main": [
        [
          {
            "node": "Post to Socials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every 30 min": {
      "main": [
        [
          {
            "node": "List Product Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "List Product Folders",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}