{
  "name": "Burn captions into a video with AwesomeVideo",
  "nodes": [
    {
      "parameters": {},
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e01",
      "name": "Run it",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a1",
              "name": "videoUrl",
              "value": "https://awesomevideoeditor.com/samples/cc0-interview-es.mp4",
              "type": "string"
            },
            {
              "id": "a2",
              "name": "preset",
              "value": "builtin:karaoke",
              "type": "string"
            },
            {
              "id": "a3",
              "name": "platform",
              "value": "tiktok",
              "type": "string"
            },
            {
              "id": "a4",
              "name": "translateTo",
              "value": "",
              "type": "string"
            },
            {
              "id": "a5",
              "name": "maxCredits",
              "value": 50,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e02",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.awesomevideoeditor.com/v1/captions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify(Object.assign({ sourceUrl: $json.videoUrl, preset: $json.preset, platform: $json.platform, maxCredits: $json.maxCredits }, $json.translateTo ? { translateTo: $json.translateTo } : {})) }}",
        "options": {}
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e03",
      "name": "Caption the video",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "amount": 5,
        "unit": "seconds"
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e04",
      "name": "Wait 5 s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        660,
        0
      ],
      "webhookId": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e0a"
    },
    {
      "parameters": {
        "url": "=https://api.awesomevideoeditor.com/v1/jobs/{{ $('Caption the video').first().json.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e05",
      "name": "Check the job",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        880,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.status }}",
              "rightValue": "succeeded",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e06",
      "name": "Done?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1100,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "r1",
              "name": "videoUrl",
              "value": "={{ $json.result.files.find(f => f.name === 'mp4').url }}",
              "type": "string"
            },
            {
              "id": "r2",
              "name": "srt",
              "value": "={{ $json.result.files.find(f => f.name === 'srt').text }}",
              "type": "string"
            },
            {
              "id": "r3",
              "name": "vtt",
              "value": "={{ $json.result.files.find(f => f.name === 'vtt').text }}",
              "type": "string"
            },
            {
              "id": "r4",
              "name": "language",
              "value": "={{ $json.result.language }}",
              "type": "string"
            },
            {
              "id": "r5",
              "name": "creditsCharged",
              "value": "={{ $json.result.creditsCharged }}",
              "type": "number"
            },
            {
              "id": "r6",
              "name": "jobId",
              "value": "={{ $json.id }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e07",
      "name": "Captioned video",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1320,
        -100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "c2",
              "leftValue": "={{ $json.status }}",
              "rightValue": "failed",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "c3",
              "leftValue": "={{ $runIndex }}",
              "rightValue": 120,
              "operator": {
                "type": "number",
                "operation": "gte"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e08",
      "name": "Failed or too long?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1320,
        100
      ]
    },
    {
      "parameters": {
        "errorMessage": "={{ $json.status === 'failed' ? 'Job ' + $json.id + ' failed (refunded): ' + JSON.stringify($json.error) : 'Job ' + $json.id + ' still ' + $json.status + ' after ' + $runIndex + ' checks' }}"
      },
      "id": "8f0d1a52-1b8e-4d3c-9a51-0c5b8f7a6e09",
      "name": "Stop with the reason",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1540,
        100
      ]
    }
  ],
  "connections": {
    "Run it": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Caption the video",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Caption the video": {
      "main": [
        [
          {
            "node": "Wait 5 s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 5 s": {
      "main": [
        [
          {
            "node": "Check the job",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check the job": {
      "main": [
        [
          {
            "node": "Done?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Done?": {
      "main": [
        [
          {
            "node": "Captioned video",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Failed or too long?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Failed or too long?": {
      "main": [
        [
          {
            "node": "Stop with the reason",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 5 s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
