{
  "nodes": [
    {
      "parameters": {
        "amount": 30
      },
      "id": "971ac830-b98d-45f2-bd51-4f1bb0fd9cf7",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        1460,
        400
      ],
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a21fe2d1-533b-4f09-94aa-9312c3dd05b8",
              "name": "=prompt",
              "type": "string",
              "value": "=Analyze the Reels video: 1. What is the video about, in one sentence 2. What is the hook of the video - e.g. first 5 seconds usually, maybe the first text on the screen, maybe the first words of the author - this is the thing that is made to grab attention of the viewer, also capture any sound effect possible, transition effect also. 3. What is going on in the video - write me a whole script, that I can easily replicate, include the whole text of the author (if there is any text at all), include all the important details. Structure your output like this: 1. Idea: ..., 2. Hook: ..., 3. Script: ... - WRITE NOTHING ELSE EXCEPT FOR THIS 3 BULLETS, NO EXTRA WORDS AT THE BEGINNING."
            }
          ]
        },
        "options": {}
      },
      "id": "86eade0c-cd16-4152-a3a6-898ff64c31c2",
      "name": "Set Prompt",
      "type": "n8n-nodes-base.set",
      "position": [
        1620,
        400
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/upload/v1beta/files",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "YOUR_GOOGLE_API_KEY"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "X-Goog-Upload-Protocol",
              "value": "resumable"
            },
            {
              "name": "X-Goog-Upload-Command",
              "value": "start"
            },
            {
              "name": "X-Goog-Upload-Header-Content-Length",
              "value": "={{ $json.Video[0].size }}"
            },
            {
              "name": "X-Goog-Upload-Header-Content-Type",
              "value": "={{ $json.Video[0].type }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n\"file\": {\n\"display_name\": \"{{ $json.Video[0].filename }}\"\n}\n}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true
            }
          }
        }
      },
      "id": "31b6158d-71a5-466b-a32f-d9ca68f99ab4",
      "name": "Gemini - Generate Upload URL",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        340,
        400
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Gemini - Generate Upload URL').item.json.headers['x-goog-upload-url'] }}",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "YOUR_GOOGLE_API_KEY"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Length",
              "value": "={{ $('Get Video').item.json.Video[0].size }}"
            },
            {
              "name": "X-Goog-Upload-Offset",
              "value": "0"
            },
            {
              "name": "X-Goog-Upload-Command",
              "value": "upload, finalize"
            }
          ]
        },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "data",
        "options": {
          "response": {}
        }
      },
      "id": "82850d27-04c2-46e7-b155-b8680356ef69",
      "name": "Gemini - Upload File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1040,
        400
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "YOUR_GOOGLE_API_KEY"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n   \"contents\": [\n      {\n         \"parts\": [\n            {\n               \"text\": \"{{ $json.prompt }}\"\n            },\n            {\n               \"file_data\": {\n                  \"mime_type\": \"{{ $('Save Values').item.json.mimeType }}\",\n                  \"file_uri\": \"{{ $('Save Values').item.json.gemini_file_url }}\"\n               }\n            }\n         ]\n      }\n   ]\n}\n",
        "options": {
          "response": {}
        }
      },
      "id": "7b99023b-f901-4c4e-bcad-e6a2d58abf2a",
      "name": "Gemini - Ask Questions",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1820,
        400
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4fb7b732-17f9-41a2-986d-5d62b1331242",
              "name": "gemini_file_url",
              "type": "string",
              "value": "={{ $json.file.uri }}"
            },
            {
              "id": "5f3018b4-571f-433c-a07b-2fb86f63b9b6",
              "name": "mimeType",
              "type": "string",
              "value": "={{ $json.file.mimeType }}"
            },
            {
              "id": "c5532f11-ec31-49f8-aa26-7f42b7d24fa4",
              "name": "airtable_rec_id",
              "type": "string",
              "value": "={{ $('Get Video').item.json.id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "7ebf3beb-198a-4711-a71b-fdde76d733c2",
      "name": "Save Values",
      "type": "n8n-nodes-base.set",
      "position": [
        1300,
        400
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/apify~instagram-scraper/run-sync-get-dataset-items",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "token",
              "value": "YOUR_APIFY_TOKEN"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n    \"addParentData\": false,\n    \"directUrls\": [\n        \"https://www.instagram.com/{{ $json['Instagram Username'] }}/\"\n    ],\n    \"enhanceUserSearchWithFacebookPage\": false,\n    \"isUserReelFeedURL\": false,\n    \"isUserTaggedFeedURL\": false,\n    \"onlyPostsNewerThan\": \"{{ new Date(new Date().setDate(new Date().getDate() - 7)).toISOString().slice(0, 10) }}\",\n    \"resultsLimit\": 20,\n    \"resultsType\": \"stories\"\n}",
        "options": {}
      },
      "id": "edc3743f-ecba-45e9-ac49-0878cb69c677",
      "name": "Apify - Fetch Reels",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        60,
        100
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "views",
              "order": "descending"
            }
          ]
        },
        "options": {}
      },
      "id": "f341548e-0408-4505-9245-fa04cab3af08",
      "name": "Sort",
      "type": "n8n-nodes-base.sort",
      "position": [
        1140,
        100
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "maxItems": 3
      },
      "id": "2cebec73-9b20-429f-bb19-053a42000a19",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        1340,
        100
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={\n  \"url\": {{ JSON.stringify($json.videoUrl) }}\n,\n  \"views\": {{ $json.videoViewCount }},\n\"caption\": {{ JSON.stringify($json.caption) }}\n,\n\"creator\": \"{{ $('Loop Over Items').item.json.Name }}\"\n}",
        "options": {}
      },
      "id": "c32e58f2-9b99-4080-a278-29b7f6f03aa5",
      "name": "Save Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        700,
        100
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "2f2892e4-9d3d-49e3-ba55-e062392658c2",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -200,
        100
      ],
      "typeVersion": 3
    },
    {
      "parameters": {
        "url": "={{ $('Get Video').item.json.Video[0].url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "a0833ae2-d2d8-4a9e-9b4a-bbf3088e9e2e",
      "name": "Download File",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        700,
        400
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "base": {
          "__rl": true,
          "value": "appvVxU9AsFfIqtVR",
          "mode": "list",
          "cachedResultName": "Viral Fashion Reels",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR"
        },
        "table": {
          "__rl": true,
          "value": "tbllWMXkRYTI9WiFW",
          "mode": "list",
          "cachedResultName": "Videos",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR/tbllWMXkRYTI9WiFW"
        },
        "id": "={{ $json.id }}",
        "options": {}
      },
      "id": "6ff13f49-ef35-4d99-ace4-5a4dde9d67fe",
      "name": "Get Video",
      "type": "n8n-nodes-base.airtable",
      "position": [
        -80,
        400
      ],
      "typeVersion": 2.1,
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "base": {
          "__rl": true,
          "value": "appvVxU9AsFfIqtVR",
          "mode": "list",
          "cachedResultName": "Viral Fashion Reels",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR"
        },
        "table": {
          "__rl": true,
          "value": "tbllWMXkRYTI9WiFW",
          "mode": "list",
          "cachedResultName": "Videos",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR/tbllWMXkRYTI9WiFW"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "id": "={{ $('Get Video').first().json.id }}",
            "Guideline": "={{ $json.candidates[0].content.parts[0].text }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": true,
              "display": true,
              "type": "string",
              "readOnly": true
            },
            {
              "id": "Caption",
              "displayName": "Caption",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "Creator",
              "displayName": "Creator",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "Video",
              "displayName": "Video",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "array",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "Creation Date",
              "displayName": "Creation Date",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "dateTime",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "Views",
              "displayName": "Views",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "Guideline",
              "displayName": "Guideline",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "962b9b14-e56e-465b-b904-a23d0a336e9a",
      "name": "Set Guideline",
      "type": "n8n-nodes-base.airtable",
      "position": [
        2000,
        400
      ],
      "typeVersion": 2.1,
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "search",
        "base": {
          "__rl": true,
          "value": "appvVxU9AsFfIqtVR",
          "mode": "list",
          "cachedResultName": "Viral Fashion Reels",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR"
        },
        "table": {
          "__rl": true,
          "value": "tblp31TvkFft8LGhP",
          "mode": "list",
          "cachedResultName": "Creators",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR/tblp31TvkFft8LGhP"
        },
        "returnAll": false,
        "limit": null,
        "options": {}
      },
      "id": "075d9315-4d0b-44d1-b17e-c30aa22c496a",
      "name": "Search Creators",
      "type": "n8n-nodes-base.airtable",
      "position": [
        -420,
        100
      ],
      "typeVersion": 2.1,
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtHour": 5
            }
          ]
        }
      },
      "id": "d27d9c79-eab7-423a-9ffd-8dfec4ac5e90",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -640,
        100
      ],
      "typeVersion": 1.2
    },
    {
      "parameters": {
        "content": "### Replace Apify token",
        "height": 80,
        "width": 220,
        "color": 6
      },
      "id": "c390993a-398c-47f7-8e78-8843ca35a43e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Replace Google token",
        "height": 80,
        "width": 200,
        "color": 6
      },
      "id": "47543f9a-970e-4270-871c-ce26f76d1583",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Replace Google token",
        "height": 80,
        "width": 200,
        "color": 6
      },
      "id": "c49565b5-93be-4aa9-ac0e-4c89be1f8bb8",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Replace Google token",
        "height": 80,
        "width": 200,
        "color": 6
      },
      "id": "bd789b11-eb1d-40b3-a870-c672991a7cb1",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1140,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Set your own prompt for analysis",
        "height": 80,
        "width": 200,
        "color": 6
      },
      "id": "e817f4d9-737a-4519-883e-a156910ae0bd",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        920,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "options": {
          "reset": "={{ $node['Loop Over Items1'].context[\"done\"] }}"
        }
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -540,
        380
      ],
      "id": "3b7f1cf6-2598-456d-94c1-072437f09cf0",
      "name": "Loop Over Items1"
    },
    {
      "parameters": {
        "operation": "create",
        "base": {
          "__rl": true,
          "value": "appvVxU9AsFfIqtVR",
          "mode": "list",
          "cachedResultName": "Viral Fashion Reels",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR"
        },
        "table": {
          "__rl": true,
          "value": "tbllWMXkRYTI9WiFW",
          "mode": "list",
          "cachedResultName": "Videos",
          "cachedResultUrl": "https://airtable.com/appvVxU9AsFfIqtVR/tbllWMXkRYTI9WiFW"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Views": "={{ $json.views }}",
            "Caption": "={{ $json.caption }}",
            "Creator": "={{ $json.creator }}",
            "Video": "={{ [ {\"url\":$json.url} ] }}",
            "Creation Date": "={{ new Date().toISOString().split('T')[0] }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Caption",
              "displayName": "Caption",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Creator",
              "displayName": "Creator",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Video",
              "displayName": "Video",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "array",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Creation Date",
              "displayName": "Creation Date",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "dateTime",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Views",
              "displayName": "Views",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "Guideline",
              "displayName": "Guideline",
              "required": false,
              "defaultMatch": false,
              "canBeUsedToMatch": true,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "typecast": true
        }
      },
      "type": "n8n-nodes-base.airtable",
      "typeVersion": 2.1,
      "position": [
        -280,
        380
      ],
      "id": "eb162183-2d7d-4c46-9d3f-deab3507a1d7",
      "name": "Airtable",
      "credentials": {
        "airtableTokenApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "amount": 15
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        520,
        400
      ],
      "id": "94daaf35-0405-4e44-899a-6c184c594028",
      "name": "Wait1"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        860,
        400
      ],
      "id": "c273dc02-294f-4e68-ae1a-0294eb4303c5",
      "name": "Wait2"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "f85d9e06-6bcd-4649-8f2b-73eb73e84ce3",
              "leftValue": "={{ $json.error }}",
              "rightValue": "no_items",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        280,
        100
      ],
      "id": "508308bd-6189-4433-a279-fc5e28062275",
      "name": "If"
    }
  ],
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Set Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Prompt": {
      "main": [
        [
          {
            "node": "Gemini - Ask Questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini - Generate Upload URL": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini - Upload File": {
      "main": [
        [
          {
            "node": "Save Values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini - Ask Questions": {
      "main": [
        [
          {
            "node": "Set Guideline",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Values": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apify - Fetch Reels": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Fields": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Apify - Fetch Reels",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Wait2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Video": {
      "main": [
        [
          {
            "node": "Gemini - Generate Upload URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Guideline": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Creators": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Search Creators",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Airtable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Airtable": {
      "main": [
        [
          {
            "node": "Get Video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait2": {
      "main": [
        [
          {
            "node": "Gemini - Upload File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}