{
  "nodes": [
    {
      "id": "687c7261-d156-4de8-9d09-2d86d713674e",
      "name": "When New Video",
      "type": "n8n-nodes-base.rssFeedReadTrigger",
      "position": [
        176,
        160
      ],
      "parameters": {
        "feedUrl": "https://www.youtube.com/feeds/videos.xml?channel_id=123",
        "pollTimes": {
          "item": [
            {
              "hour": 10
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bb24f83a-4eff-47fc-b69c-fe593b21f531",
      "name": "Counter Init",
      "type": "n8n-nodes-base.set",
      "position": [
        624,
        160
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"counter\": 0\n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "3969f57a-82ec-4789-b2b9-5f9088d2dffb",
      "name": "Counter +1",
      "type": "n8n-nodes-base.set",
      "position": [
        1296,
        80
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={\n  \"my_field_1\": {{ $('Counter Init').item.json.counter +1 }} \n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "60f7d423-5948-45f4-b8f3-6ff90ada58f1",
      "name": "If MAX Reached",
      "type": "n8n-nodes-base.if",
      "position": [
        1744,
        256
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "154cd90a-9814-46bc-aa7d-1078fdc14d00",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $('Counter Init').item.json.counter }}",
              "rightValue": 10
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0c430d67-fecd-435b-8b7f-2a917fcb977a",
      "name": "If Completed",
      "type": "n8n-nodes-base.if",
      "position": [
        1520,
        80
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e9b91fbc-9116-425c-910b-116648c733ed",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Get Job Status').item.json.status }}",
              "rightValue": "completed"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "b9657926-f93d-462d-949d-ff590ba87c84",
      "name": "Send Failure EMail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1968,
        256
      ],
      "parameters": {
        "sendTo": "me@example.com",
        "message": "=Hi,\nThere is a problem with the creation of your clip for the video: {{ $('When New Video').item.json.link }}\n\nIt takes longer then planned, we invite you to look for more details in your 8n8 automation.",
        "options": {},
        "subject": "Oops..."
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ec4cbbbb-7c1b-4b52-a830-c1787a73d6f1",
      "name": "Send Clip Ready EMail",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1744,
        32
      ],
      "parameters": {
        "sendTo": "me@example.com",
        "message": "=Hello! Your clip is ready to be downloded. \n\nTitle: {{ $('Get Job Status').item.json.output[0].title }}  \n\nDownload it here: {{ $('Get Job Status').item.json.output[0].video_url }} \n\nDescription: {{ $('Get Job Status').item.json.output[0].caption }}\n\n",
        "options": {},
        "subject": "Your Clip is ready"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "96e99df0-74f5-4216-825f-1155d200591b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1392,
        352
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 112,
        "content": "## if MAX Reached\n\nExit after 10 check to avoid infinite loop"
      },
      "typeVersion": 1
    },
    {
      "id": "397177ca-9ed9-4a8e-b85a-92e351cfdf39",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -16,
        -80
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 176,
        "content": "##  When New Video\nSet the Feed URL to the YouTube channel you want to follow \nex: https://www.youtube.com/feeds/videos.xml?channel_id=UCAr20GBQayL-nFPWFnUHNAA\n"
      },
      "typeVersion": 1
    },
    {
      "id": "5f9a5b4a-dacb-40ea-8ff6-3b3010e1626a",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -720,
        -320
      ],
      "parameters": {
        "width": 624,
        "height": 816,
        "content": "## Try It Out!\n\n**This n8n template demonstrates how to use Reka API via HTTP to AI generate a clip automatically from a YouTube video and send an email notifications.**\n\n## How it works\n\n* Looking at the RSS feed of a YouTube channel, the flow will be triggered when a new video is published.\n* Using Reka\u2019s API, we will submit a request to create a clip using AI. You can customize:\n  * The template used\n  * The prompt to generate the clip\n  * If you want captions or not\n  * the minimum or maximum duration of the clip\n* Wait a little while, the magic happens.\n* Check if the job status is completed.\n  * If yes, it send an success email.\n  * If no, it will loop\n  * As a failsafe, after 10 iterations in the loop, it will send an error email.\n\n## Getting Started\n\nEdit those nodes with your settings and credentials.\n\n* When New Video: Set the Feed URL to the YouTube channel you want to follow (ex:\n* Create a clip: Add your credential. Change the prompt and adjust the setting to your preferences. See the details in the sticky note,\n* Send ___ EMail: Personalize the email the way you like.\n\n### Requirements\n\n* Reka AI API key (it\u2019s free! Get yours from here from [Reka](https://link.reka.ai/free)\n* Gmail account (feel free to change it to another email provider)\n\n## Need Help?\n\nJoin the [Discord](https://link.reka.ai/discord)\n\nHappy clipping!"
      },
      "typeVersion": 1
    },
    {
      "id": "1f54a8bf-0fdf-4bea-8010-9943313bbb5c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        864,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 432,
        "height": 192,
        "content": "## \ud83d\udca1 Waiting\nGenerating the clip can take time. The video need to be downloaded to your Reka's librart, analyzed, edit, then render. Adjust the waiting duration according the duration of your video. \n#### Example\nFor a 5-8 minutes videos wait 15 minutes."
      },
      "typeVersion": 1
    },
    {
      "id": "e9b9278f-cbc8-4675-a025-8881e1374c50",
      "name": "Create Reel Creation Job",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        400,
        160
      ],
      "parameters": {
        "url": "https://vision-agent.api.reka.ai/v1/creator/reels",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"video_urls\": [\"{{ $json.link }}\"],\n  \"prompt\": \"Create an engaging short video highlighting the best moments\",\n  \"generation_config\": {\n    \"template\": \"moments\",\n    \"num_generations\": 1,\n    \"min_duration_seconds\": 0,\n    \"max_duration_seconds\": 30\n  },\n  \"rendering_config\": {\n    \"subtitles\": true,\n    \"aspect_ratio\": \"9:16\"\n  }\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "8d9664e5-2868-438c-96b5-d4ff45c4ee0a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -32,
        336
      ],
      "parameters": {
        "color": 6,
        "width": 784,
        "height": 864,
        "content": "## Create Reel Creation Job\n\nThis API call will upload the video into your Reka's library and create a job for the clip.\n\n### Parameters\n- `video_urls` (string, required): URLs of input videos\n- `prompt` (string, required): Description of the reel to generate\n\n**generation_config**\n\n- `template` (\u201cmoments\u201d | \u201ccompilation\u201d, default: \u201cmoments\u201d)\n- `num_generations` (integer, default: 1)\n- `min_duration_seconds` (integer, optional)\n- `max_duration_seconds` (integer, optional)\n\n**rendering_config**\n\n- `subtitles` (boolean, default: true)\n- `aspect_ratio` (string, default: \u201c9:16\u201d) examples: \u201c9:16\u201d, \u201c16:9\u201d, \u201c1:1\u201d, \u201c4:5\u201d\n\n#### Example of a complete JSON\n\n```json\n{\n  \"video_urls\": [\"{{ $json.link }}\"],\n  \"prompt\": \"Create an engaging short video highlighting the best moments\",\n  \"generation_config\": {\n    \"template\": \"moments\",\n    \"num_generations\": 1,\n    \"min_duration_seconds\": 0,\n    \"max_duration_seconds\": 30\n  },\n  \"rendering_config\": {\n    \"subtitles\": true,\n    \"aspect_ratio\": \"9:16\"\n  }\n}\n```"
      },
      "typeVersion": 1
    },
    {
      "id": "4f597663-96f5-4727-b1ed-793c967511d5",
      "name": "Get Job Status",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        1072,
        80
      ],
      "parameters": {
        "url": "=https://vision-agent.api.reka.ai/v1/creator/reels/{{ $('Create Reel Creation Job').item.json.id }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "886c856e-f40a-41d7-973d-4733250d675e",
      "name": "Wait 10 minutes",
      "type": "n8n-nodes-base.wait",
      "position": [
        848,
        160
      ],
      "parameters": {
        "unit": "minutes",
        "amount": 10
      },
      "typeVersion": 1.1
    }
  ],
  "connections": {
    "Counter +1": {
      "main": [
        [
          {
            "node": "If Completed",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Counter Init": {
      "main": [
        [
          {
            "node": "Wait 10 minutes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Completed": {
      "main": [
        [
          {
            "node": "Send Clip Ready EMail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If MAX Reached",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Job Status": {
      "main": [
        [
          {
            "node": "Counter +1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If MAX Reached": {
      "main": [
        [
          {
            "node": "Send Failure EMail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 10 minutes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When New Video": {
      "main": [
        [
          {
            "node": "Create Reel Creation Job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 10 minutes": {
      "main": [
        [
          {
            "node": "Get Job Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Reel Creation Job": {
      "main": [
        [
          {
            "node": "Counter Init",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}