{
  "name": "Canal dark com Darkvi — roteiro → narração MP3 + legenda SRT",
  "nodes": [
    {
      "parameters": {},
      "id": "d49d3834-1989-4447-aed3-f8010be7bde3",
      "name": "Iniciar manualmente",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 9
            }
          ]
        }
      },
      "id": "ceb605b2-e02b-4ce6-a93c-6e82370979b6",
      "name": "Todo dia às 9h (opcional)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        500
      ],
      "disabled": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "49e63e77-e815-4939-b364-a042f64c4788",
              "name": "titulo",
              "value": "A voz no telefone",
              "type": "string"
            },
            {
              "id": "4b75d253-f856-4046-9397-d6b16836a3d4",
              "name": "roteiro",
              "value": "Às três da manhã, o telefone fixo da casa da minha avó tocou. Ninguém usava aquele aparelho havia anos. A linha tinha sido cortada muito antes de ela morrer. Mesmo assim, eu atendi. Do outro lado, uma voz de criança sussurrou o meu nome e disse: hoje, não desce para o porão. Eu ri de nervoso e desliguei. Foi aí que eu ouvi, lá de baixo, alguém subindo a escada do porão. Devagar. Um degrau de cada vez.",
              "type": "string"
            },
            {
              "id": "83f0a988-f364-4eb2-a4e9-b052a080236d",
              "name": "voz",
              "value": "d028299c-65b1-434e-84d7-b0e16a193783",
              "type": "string"
            },
            {
              "id": "10b71d00-6de0-449a-a0d9-415d01ee744d",
              "name": "nomeArquivo",
              "value": "a-voz-no-telefone",
              "type": "string"
            },
            {
              "id": "61af0530-3979-4a80-bcaf-87e63c5a564e",
              "name": "maxTentativas",
              "value": 30,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "a2c200e4-572c-49e5-b2f6-e54a6d087ed9",
      "name": "Roteiro e voz",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        400
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://darkvi.com/api/tts",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.roteiro, voice: $json.voz, title: $json.titulo }) }}",
        "options": {}
      },
      "id": "3d1673b7-2aa7-4e59-b1f4-9e63058a9f65",
      "name": "Criar áudio na Darkvi",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        400
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": null,
          "name": "Darkvi API"
        }
      }
    },
    {
      "parameters": {
        "resume": "timeInterval",
        "amount": 10,
        "unit": "seconds"
      },
      "id": "3384a8d5-2272-4cb6-9648-31506ad54aae",
      "name": "Aguardar 10 s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        720,
        400
      ],
      "webhookId": "b416f5e1-302c-44ae-ba57-aefb73b66b99"
    },
    {
      "parameters": {
        "url": "=https://darkvi.com/api/tts/{{ $('Criar áudio na Darkvi').first().json.data.created.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "adfa3b56-da3b-4c04-b1f4-1c569f31608c",
      "name": "Consultar status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        940,
        400
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": null,
          "name": "Darkvi API"
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "8a9334d8-829e-4b7d-9d07-c1b179820d7e",
              "leftValue": "={{ $json.status }}",
              "rightValue": "DONE",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "ade1f3d1-b93b-4551-be56-efded705d3c9",
      "name": "Pronto (DONE)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1160,
        400
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "714719dc-d448-4a7e-ae13-1694ff51b7e3",
              "leftValue": "={{ $json.status }}",
              "rightValue": "ERROR",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "e3afcea0-9c73-417e-a118-41be48f09e53",
      "name": "Deu erro (ERROR)?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1380,
        560
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "conditions": [
            {
              "id": "912c6583-29e6-442b-82ae-5c167046d830",
              "leftValue": "={{ $runIndex + 1 }}",
              "rightValue": "={{ $('Roteiro e voz').first().json.maxTentativas }}",
              "operator": {
                "type": "number",
                "operation": "lt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {
          "looseTypeValidation": true
        }
      },
      "id": "3881a6b2-e193-45b4-bd93-d1a7946b3841",
      "name": "Ainda dá para esperar?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        1600,
        720
      ]
    },
    {
      "parameters": {
        "errorMessage": "=A Darkvi marcou o áudio {{ $json.id }} como ERROR. Revise o texto e a voz e rode de novo."
      },
      "id": "fb9d0715-9f9b-43a1-b023-10942d5cfcdf",
      "name": "Falha na geração",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1600,
        520
      ]
    },
    {
      "parameters": {
        "errorMessage": "=O áudio {{ $('Criar áudio na Darkvi').first().json.data.created.id }} ainda está {{ $json.status }} depois de {{ $('Roteiro e voz').first().json.maxTentativas }} consultas. Aumente \"maxTentativas\" em \"Roteiro e voz\" (roteiros longos demoram mais) ou consulte depois pelo painel."
      },
      "id": "fe625398-df92-4841-9954-ef347f5d51ae",
      "name": "Tempo esgotado",
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        1820,
        820
      ]
    },
    {
      "parameters": {
        "url": "=https://darkvi.com/api/tts/audios/{{ $('Criar áudio na Darkvi').first().json.data.created.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $('Roteiro e voz').first().json.nomeArquivo }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "audio"
            }
          }
        }
      },
      "id": "15fff8f5-160d-4338-bca8-d05cc7e89cb5",
      "name": "Baixar MP3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1380,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": null,
          "name": "Darkvi API"
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "url": "=https://darkvi.com/api/tts/srt/{{ $('Criar áudio na Darkvi').first().json.data.created.id }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "titulo",
              "value": "={{ $('Roteiro e voz').first().json.nomeArquivo }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "file",
              "outputPropertyName": "legenda"
            }
          }
        }
      },
      "id": "80c18f0d-07ce-4281-9c98-94bf706039c8",
      "name": "Baixar legenda SRT",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1600,
        300
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": null,
          "name": "Darkvi API"
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "jsCode": "// Junta os dois downloads num único item com 2 arquivos binários: \"audio\" (MP3) e \"legenda\" (SRT).\nconst criado = $('Criar áudio na Darkvi').first().json.data.created;\nconst nome = $('Roteiro e voz').first().json.nomeArquivo || criado.id;\nconst mp3 = { ...$('Baixar MP3').first().binary.audio, fileName: nome + '.mp3', fileExtension: 'mp3', mimeType: 'audio/mpeg' };\nconst srt = { ...$input.first().binary.legenda, fileName: nome + '.srt', fileExtension: 'srt', mimeType: 'application/x-subrip' };\n\nreturn [{\n  json: { id: criado.id, titulo: criado.titulo ?? null, status: 'DONE', arquivos: [mp3.fileName, srt.fileName] },\n  binary: { audio: mp3, legenda: srt },\n}];"
      },
      "id": "ab2f9770-0e7c-4cf8-939b-534bf0370d89",
      "name": "Juntar MP3 + SRT",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1820,
        300
      ]
    },
    {
      "parameters": {
        "name": "={{ $binary.audio.fileName }}",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list",
          "cachedResultName": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "root",
          "mode": "list",
          "cachedResultName": "/ (Root folder)"
        },
        "inputDataFieldName": "audio",
        "options": {}
      },
      "id": "bc4ad3f4-5106-46f3-b0fa-cf01bcc8acea",
      "name": "Enviar MP3 ao Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2060,
        200
      ],
      "disabled": true,
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": null,
          "name": "Google Drive"
        }
      }
    },
    {
      "parameters": {
        "name": "={{ $binary.legenda.fileName }}",
        "driveId": {
          "__rl": true,
          "value": "My Drive",
          "mode": "list",
          "cachedResultName": "My Drive"
        },
        "folderId": {
          "__rl": true,
          "value": "root",
          "mode": "list",
          "cachedResultName": "/ (Root folder)"
        },
        "inputDataFieldName": "legenda",
        "options": {}
      },
      "id": "8ba78bbe-74b2-4e25-b15a-236c539ead6a",
      "name": "Enviar SRT ao Google Drive",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        2060,
        400
      ],
      "disabled": true,
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": null,
          "name": "Google Drive"
        }
      }
    },
    {
      "parameters": {
        "url": "https://darkvi.com/api/tts/voices",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "9c690010-d54e-43cb-9a10-f61b0c1a05da",
      "name": "Listar vozes (utilitário)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        240,
        900
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": null,
          "name": "Darkvi API"
        }
      }
    },
    {
      "parameters": {
        "url": "https://darkvi.com/api/v1/auth/validate",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "8f5d3b02-eda2-4f94-ae7e-84628c159fb7",
      "name": "Testar chave de API (utilitário)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        900
      ],
      "credentials": {
        "httpHeaderAuth": {
          "id": null,
          "name": "Darkvi API"
        }
      }
    },
    {
      "parameters": {
        "content": "## Canal dark no automático — Darkvi + n8n\nRoteiro → narração (MP3) → legenda (SRT), pela API oficial da Darkvi.\n\n**1. Chave de API** — gere em darkvi.com/settings.\nCrie uma credencial **Header Auth** chamada `Darkvi API`:\n- Name: `Authorization`\n- Value: `Bearer SUA_CHAVE_DE_API`\n\n**2. Edite \"Roteiro e voz\"** — título, roteiro e o id da voz (campo `idApi` da lista de vozes; rode o nó \"Listar vozes\" para ver todos).\n\n**3. Clique em \"Execute workflow\".** O áudio sai em ~20 s a 1 min, dependendo do tamanho do texto.\n\nCada geração consome saldo de TTS da sua conta Darkvi.",
        "height": 560,
        "width": 560,
        "color": 4
      },
      "id": "d4cb90a7-309b-42dd-bf09-c77abe2176be",
      "name": "Nota: como usar",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -360,
        -40
      ]
    },
    {
      "parameters": {
        "content": "### Espera o áudio ficar pronto\nA cada 10 s consulta o status: `PENDING` → `PROCESSING` → `DONE` (ou `ERROR`). Para depois de `maxTentativas` consultas (30 × 10 s = 5 min). Roteiros longos: aumente `maxTentativas`.",
        "height": 180,
        "width": 1040,
        "color": 5
      },
      "id": "50a25f28-87f7-49c2-85c7-46a24bd01ffc",
      "name": "Nota: espera",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        700,
        180
      ]
    },
    {
      "parameters": {
        "content": "### Saída\nUm item com 2 arquivos: `audio` (MP3) e `legenda` (SRT), prontos para o editor de vídeo.\nQuer no Google Drive? Ative os 2 nós do Drive (clique direito → Activate) e conecte sua conta Google.",
        "height": 200,
        "width": 480,
        "color": 6
      },
      "id": "e0883ac4-a863-4bd9-a486-f87e7b491a8d",
      "name": "Nota: saída",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1800,
        -40
      ]
    },
    {
      "parameters": {
        "content": "### Utilitários (rodam sozinhos)\nSelecione o nó e clique em **Execute step**:\n- **Listar vozes**: todas as vozes ativas — copie o `idApi` da voz para o campo `voz`.\n- **Testar chave**: responde `{ \"valid\": true }` se a chave estiver certa.",
        "height": 280,
        "width": 520,
        "color": 7
      },
      "id": "c335b480-0720-455b-8cc7-476e418ce885",
      "name": "Nota: utilitários",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        200,
        780
      ]
    }
  ],
  "connections": {
    "Iniciar manualmente": {
      "main": [
        [
          {
            "node": "Roteiro e voz",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Todo dia às 9h (opcional)": {
      "main": [
        [
          {
            "node": "Roteiro e voz",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Roteiro e voz": {
      "main": [
        [
          {
            "node": "Criar áudio na Darkvi",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Criar áudio na Darkvi": {
      "main": [
        [
          {
            "node": "Aguardar 10 s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aguardar 10 s": {
      "main": [
        [
          {
            "node": "Consultar status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Consultar status": {
      "main": [
        [
          {
            "node": "Pronto (DONE)?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pronto (DONE)?": {
      "main": [
        [
          {
            "node": "Baixar MP3",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Deu erro (ERROR)?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Deu erro (ERROR)?": {
      "main": [
        [
          {
            "node": "Falha na geração",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ainda dá para esperar?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ainda dá para esperar?": {
      "main": [
        [
          {
            "node": "Aguardar 10 s",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Tempo esgotado",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Baixar MP3": {
      "main": [
        [
          {
            "node": "Baixar legenda SRT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Baixar legenda SRT": {
      "main": [
        [
          {
            "node": "Juntar MP3 + SRT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Juntar MP3 + SRT": {
      "main": [
        [
          {
            "node": "Enviar MP3 ao Google Drive",
            "type": "main",
            "index": 0
          },
          {
            "node": "Enviar SRT ao Google Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "active": false,
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
