@praeko/cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/arauto.mjs +11 -0
- package/dist/chunks/adaptadores-X3NUBMLT.mjs +18 -0
- package/dist/chunks/buffer-5TUDOBVN.mjs +14 -0
- package/dist/chunks/chunk-6YARHJZ2.mjs +56 -0
- package/dist/chunks/chunk-IZEX746E.mjs +238 -0
- package/dist/chunks/chunk-LCFK6X55.mjs +16 -0
- package/dist/chunks/chunk-LLXYUCTT.mjs +184 -0
- package/dist/chunks/chunk-QDZLRBTP.mjs +1125 -0
- package/dist/chunks/chunk-SAHLBARV.mjs +415 -0
- package/dist/chunks/chunk-UK3UKRPR.mjs +363 -0
- package/dist/chunks/chunk-XQO6MI7C.mjs +851 -0
- package/dist/chunks/chunk-Z325UM27.mjs +34 -0
- package/dist/chunks/instagram-GNY73ESY.mjs +293 -0
- package/dist/chunks/instagram-meta-COY6BTNX.mjs +412 -0
- package/dist/chunks/local-EUJHQ76T.mjs +14 -0
- package/dist/chunks/registro-FL2CVMYM.mjs +12 -0
- package/dist/chunks/remoto-OAB5Y2MS.mjs +13 -0
- package/dist/chunks/tiktok-QOUHOWDU.mjs +311 -0
- package/dist/chunks/tiktok-api-36DV2H43.mjs +309 -0
- package/dist/chunks/youtube-RZ4XTUZW.mjs +199 -0
- package/dist/chunks/youtube-analytics-3KIW2ZIW.mjs +109 -0
- package/dist/chunks/youtube-api-Z2RP5D2V.mjs +94 -0
- package/dist/chunks/youtube-comunidade-OAK5GGK4.mjs +25 -0
- package/dist/praeko.mjs +11 -0
- package/package.json +48 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Segue [Keep a Changelog](https://keepachangelog.com/pt-BR/1.1.0/) e [SemVer](https://semver.org/lang/pt-BR/).
|
|
4
|
+
|
|
5
|
+
## [0.1.0] - não publicado
|
|
6
|
+
|
|
7
|
+
Primeira versão preparada para o npm.
|
|
8
|
+
- Pacote `@praeko/cli`: comandos `praeko` e `arauto`, empacotado em `dist/` com o core e o SDK embutidos (sem dependências); `--version`; `praeko studio` avisa quando o Studio não está instalado.
|
|
9
|
+
- Licença MIT (arquivo `LICENSE` no pacote) e repositório público de código-cliente (`Praeko/praeko-js`).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marcone Santos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @praeko/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Linha de comando do [Praeko](https://praeko.app): publica e agenda vídeos curtos no YouTube, Instagram e TikTok, e fala com a API do serviço (posts, fila, canais, chaves, insights). Comando `praeko` (o antigo `arauto` continua como apelido). Node 22 ou superior; `ffmpeg`/`ffprobe` só para os comandos que mexem em capa e vídeo.
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install -g @praeko/cli
|
|
9
|
+
yarn global add @praeko/cli
|
|
10
|
+
pnpm add -g @praeko/cli
|
|
11
|
+
bun add -g @praeko/cli
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Sem instalar:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npx @praeko/cli --help
|
|
18
|
+
pnpm dlx @praeko/cli --help
|
|
19
|
+
bunx @praeko/cli --help
|
|
20
|
+
yarn dlx @praeko/cli --help # yarn 2+
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Começando
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
praeko --version
|
|
27
|
+
praeko --help
|
|
28
|
+
export PRAEKO_SERVER=https://praeko.app
|
|
29
|
+
export PRAEKO_KEY=praeko_… # chave criada no painel (ou: echo $CHAVE | praeko key store)
|
|
30
|
+
praeko posts # lista os posts do serviço
|
|
31
|
+
praeko post ./meu-pacote --when "30/12 17:30" --networks yt,ig,tt # SIMULA (nada é enviado)
|
|
32
|
+
praeko post ./meu-pacote --when "30/12 17:30" --networks yt,ig,tt --send
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Nada é enviado, hospedado ou agendado sem `--send`.
|
|
36
|
+
|
|
37
|
+
## Autenticação
|
|
38
|
+
|
|
39
|
+
A chave vem de `PRAEKO_KEY`. Sem ela, a CLI procura no Chaveiro do macOS (só no Mac, item `praeko/chave`) e no arquivo `~/.config/praeko/segredos.json` (modo 600; mude com `PRAEKO_SEGREDOS`). No Linux e no Windows valem a variável e o arquivo. `PRAEKO_SEM_CHAVEIRO=1` ignora o Chaveiro. O endereço do serviço vem de `--server` ou `PRAEKO_SERVER`.
|
|
40
|
+
|
|
41
|
+
## Erros e códigos de saída
|
|
42
|
+
|
|
43
|
+
`0` sucesso; `1` erro (mensagem em português no stderr); `2` comando ou argumento inválido (mostra a ajuda).
|
|
44
|
+
|
|
45
|
+
## Praeko Studio
|
|
46
|
+
|
|
47
|
+
`praeko studio …` (gerador de vídeos) ainda não é distribuído pelo npm; fora do repositório o comando avisa e sai com `1`. Os demais comandos não dependem dele.
|
|
48
|
+
|
|
49
|
+
## Versionamento
|
|
50
|
+
|
|
51
|
+
[SemVer](https://semver.org/lang/pt-BR/); em `0.x` mudanças incompatíveis podem sair em versões menores, sempre no [CHANGELOG](./CHANGELOG.md). A CLI é publicada com o SDK embutido: não há dependências a instalar.
|
|
52
|
+
|
|
53
|
+
## Links
|
|
54
|
+
|
|
55
|
+
Documentação: <https://praeko.app/docs> · Código e issues: <https://github.com/Praeko/praeko-js> · SDK: [`@praeko/sdk`](https://www.npmjs.com/package/@praeko/sdk)
|
|
56
|
+
|
|
57
|
+
## Licença
|
|
58
|
+
|
|
59
|
+
[MIT](./LICENSE) © 2026 Marcone Santos.
|
package/dist/arauto.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
3
|
+
import "./chunks/chunk-XQO6MI7C.mjs";
|
|
4
|
+
import "./chunks/chunk-LLXYUCTT.mjs";
|
|
5
|
+
import "./chunks/chunk-UK3UKRPR.mjs";
|
|
6
|
+
import "./chunks/chunk-SAHLBARV.mjs";
|
|
7
|
+
import "./chunks/chunk-IZEX746E.mjs";
|
|
8
|
+
import "./chunks/chunk-6YARHJZ2.mjs";
|
|
9
|
+
import "./chunks/chunk-QDZLRBTP.mjs";
|
|
10
|
+
import "./chunks/chunk-Z325UM27.mjs";
|
|
11
|
+
import "./chunks/chunk-LCFK6X55.mjs";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
buffer_exports
|
|
4
|
+
} from "./chunk-SAHLBARV.mjs";
|
|
5
|
+
import {
|
|
6
|
+
local_exports
|
|
7
|
+
} from "./chunk-IZEX746E.mjs";
|
|
8
|
+
import "./chunk-6YARHJZ2.mjs";
|
|
9
|
+
import {
|
|
10
|
+
remoto_exports
|
|
11
|
+
} from "./chunk-QDZLRBTP.mjs";
|
|
12
|
+
import "./chunk-Z325UM27.mjs";
|
|
13
|
+
import "./chunk-LCFK6X55.mjs";
|
|
14
|
+
export {
|
|
15
|
+
buffer_exports as buffer,
|
|
16
|
+
local_exports as local,
|
|
17
|
+
remoto_exports as remoto
|
|
18
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
REF_CHAVE,
|
|
4
|
+
criar
|
|
5
|
+
} from "./chunk-SAHLBARV.mjs";
|
|
6
|
+
import "./chunk-IZEX746E.mjs";
|
|
7
|
+
import "./chunk-6YARHJZ2.mjs";
|
|
8
|
+
import "./chunk-QDZLRBTP.mjs";
|
|
9
|
+
import "./chunk-Z325UM27.mjs";
|
|
10
|
+
import "./chunk-LCFK6X55.mjs";
|
|
11
|
+
export {
|
|
12
|
+
REF_CHAVE,
|
|
13
|
+
criar
|
|
14
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
__export,
|
|
4
|
+
__glob
|
|
5
|
+
} from "./chunk-LCFK6X55.mjs";
|
|
6
|
+
|
|
7
|
+
// ../core/src/provedores/registro.mjs
|
|
8
|
+
var registro_exports = {};
|
|
9
|
+
__export(registro_exports, {
|
|
10
|
+
NOMES: () => NOMES,
|
|
11
|
+
carregar: () => carregar,
|
|
12
|
+
carregarTodos: () => carregarTodos
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// import("./**/*.mjs") in ../core/src/provedores/registro.mjs
|
|
16
|
+
var globImport_mjs = __glob({
|
|
17
|
+
"./instagram-meta.mjs": () => import("./instagram-meta-COY6BTNX.mjs"),
|
|
18
|
+
"./instagram.mjs": () => import("./instagram-GNY73ESY.mjs"),
|
|
19
|
+
"./registro.mjs": () => import("./registro-FL2CVMYM.mjs"),
|
|
20
|
+
"./tiktok-api.mjs": () => import("./tiktok-api-36DV2H43.mjs"),
|
|
21
|
+
"./tiktok.mjs": () => import("./tiktok-QOUHOWDU.mjs"),
|
|
22
|
+
"./youtube-analytics.mjs": () => import("./youtube-analytics-3KIW2ZIW.mjs"),
|
|
23
|
+
"./youtube-api.mjs": () => import("./youtube-api-Z2RP5D2V.mjs"),
|
|
24
|
+
"./youtube-comunidade.mjs": () => import("./youtube-comunidade-OAK5GGK4.mjs"),
|
|
25
|
+
"./youtube.mjs": () => import("./youtube-RZ4XTUZW.mjs")
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// ../core/src/provedores/registro.mjs
|
|
29
|
+
var NOMES = ["youtube", "instagram", "tiktok"];
|
|
30
|
+
async function carregar(nome) {
|
|
31
|
+
if (!NOMES.includes(nome)) throw new Error(`provedor desconhecido: ${nome}`);
|
|
32
|
+
try {
|
|
33
|
+
return await globImport_mjs(`./${nome}.mjs`);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (e.code === "ERR_MODULE_NOT_FOUND" && String(e.message).includes(`${nome}.mjs`)) throw new Error(`provedor "${nome}" ainda n\xE3o foi escrito`);
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function carregarTodos() {
|
|
40
|
+
const o = {};
|
|
41
|
+
for (const n of NOMES) {
|
|
42
|
+
try {
|
|
43
|
+
o[n] = await carregar(n);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
if (!/ainda não foi escrito/.test(e.message)) throw e;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return o;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
NOMES,
|
|
53
|
+
carregar,
|
|
54
|
+
carregarTodos,
|
|
55
|
+
registro_exports
|
|
56
|
+
};
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
carregarTodos
|
|
4
|
+
} from "./chunk-6YARHJZ2.mjs";
|
|
5
|
+
import {
|
|
6
|
+
PROVEDORES,
|
|
7
|
+
validarPedido
|
|
8
|
+
} from "./chunk-Z325UM27.mjs";
|
|
9
|
+
import {
|
|
10
|
+
__export,
|
|
11
|
+
__glob
|
|
12
|
+
} from "./chunk-LCFK6X55.mjs";
|
|
13
|
+
|
|
14
|
+
// ../core/src/adaptadores/local.mjs
|
|
15
|
+
var local_exports = {};
|
|
16
|
+
__export(local_exports, {
|
|
17
|
+
MODO_PADRAO: () => MODO_PADRAO,
|
|
18
|
+
criar: () => criar,
|
|
19
|
+
estadoDe: () => estadoDe
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// ../core/src/fila.mjs
|
|
23
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
24
|
+
import { dirname } from "node:path";
|
|
25
|
+
import { randomBytes } from "node:crypto";
|
|
26
|
+
|
|
27
|
+
// ../core/src/estado.mjs
|
|
28
|
+
import { existsSync } from "node:fs";
|
|
29
|
+
import { join } from "node:path";
|
|
30
|
+
var PASTA_ESTADO = ".praeko";
|
|
31
|
+
var PASTA_ESTADO_ANTIGA = ".arauto";
|
|
32
|
+
var pastaEstado = (raiz) => join(raiz, PASTA_ESTADO);
|
|
33
|
+
var caminhoEstado = (raiz, ...nome) => join(raiz, PASTA_ESTADO, ...nome);
|
|
34
|
+
function caminhoLeitura(raiz, ...nome) {
|
|
35
|
+
const novo = caminhoEstado(raiz, ...nome);
|
|
36
|
+
if (existsSync(novo)) return novo;
|
|
37
|
+
const velho = join(raiz, PASTA_ESTADO_ANTIGA, ...nome);
|
|
38
|
+
return existsSync(velho) ? velho : novo;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ../core/src/fila.mjs
|
|
42
|
+
var MAX_TENTATIVAS = 3;
|
|
43
|
+
var arquivoFila = (raiz) => caminhoEstado(raiz, "fila.json");
|
|
44
|
+
function lerFila(raiz) {
|
|
45
|
+
const f = caminhoLeitura(raiz, "fila.json");
|
|
46
|
+
return existsSync2(f) ? JSON.parse(readFileSync(f, "utf8")) : { itens: [] };
|
|
47
|
+
}
|
|
48
|
+
function salvarFila(raiz, fila) {
|
|
49
|
+
const f = arquivoFila(raiz);
|
|
50
|
+
mkdirSync(dirname(f), { recursive: true });
|
|
51
|
+
writeFileSync(f + ".tmp", JSON.stringify(fila, null, 2) + "\n");
|
|
52
|
+
renameSync(f + ".tmp", f);
|
|
53
|
+
}
|
|
54
|
+
function enfileirar(raiz, item) {
|
|
55
|
+
const fila = lerFila(raiz);
|
|
56
|
+
const it = { id: randomBytes(4).toString("hex"), estado: "pendente", tentativas: 0, criadoEm: (/* @__PURE__ */ new Date()).toISOString(), ...item };
|
|
57
|
+
fila.itens.push(it);
|
|
58
|
+
salvarFila(raiz, fila);
|
|
59
|
+
return it;
|
|
60
|
+
}
|
|
61
|
+
function liberarItem(raiz, id) {
|
|
62
|
+
const fila = lerFila(raiz), it = fila.itens.find((x) => x.id === id || x.id.startsWith(id));
|
|
63
|
+
if (!it) throw new Error(`item ${id} n\xE3o existe na fila`);
|
|
64
|
+
if (!it.manual) throw new Error(`item ${it.id} n\xE3o \xE9 manual`);
|
|
65
|
+
it.manual = false;
|
|
66
|
+
it.quando = (/* @__PURE__ */ new Date()).toISOString();
|
|
67
|
+
it.tentativas = 0;
|
|
68
|
+
it.estado = "pendente";
|
|
69
|
+
salvarFila(raiz, fila);
|
|
70
|
+
return it;
|
|
71
|
+
}
|
|
72
|
+
function cancelarItem(raiz, id) {
|
|
73
|
+
const fila = lerFila(raiz), it = fila.itens.find((x) => x.id === id || x.id.startsWith(id));
|
|
74
|
+
if (!it) throw new Error(`item ${id} n\xE3o existe na fila`);
|
|
75
|
+
if (it.estado === "enviado") throw new Error(`item ${it.id} j\xE1 foi enviado; desfa\xE7a pela pr\xF3pria rede`);
|
|
76
|
+
it.estado = "cancelado";
|
|
77
|
+
it.canceladoEm = (/* @__PURE__ */ new Date()).toISOString();
|
|
78
|
+
salvarFila(raiz, fila);
|
|
79
|
+
return it;
|
|
80
|
+
}
|
|
81
|
+
function proximaAcao(it, prov, agora) {
|
|
82
|
+
if (it.manual) return null;
|
|
83
|
+
if (!["pendente", "preparado"].includes(it.estado) || it.tentativas >= MAX_TENTATIVAS) return null;
|
|
84
|
+
const t = Date.parse(it.quando), ant = it.acao ? 0 : prov.antecedenciaMs ?? 0;
|
|
85
|
+
if (prov.imediato && !it.acao) return it.estado === "pendente" ? "publicar" : null;
|
|
86
|
+
if (it.estado === "pendente" && prov.preparar && +agora >= t - ant && +agora < t) return "preparar";
|
|
87
|
+
if (+agora >= t) return "publicar";
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
async function executar({ raiz, provedores, ctx, agora = /* @__PURE__ */ new Date(), simular = false, soIds = null, log = console.log }) {
|
|
91
|
+
const fila = lerFila(raiz), feitos = [];
|
|
92
|
+
for (const it of fila.itens) {
|
|
93
|
+
if (soIds && !soIds.includes(it.id)) continue;
|
|
94
|
+
const prov = provedores[it.provedor];
|
|
95
|
+
if (!prov) {
|
|
96
|
+
if (["pendente", "preparado"].includes(it.estado)) log(`\u26A0 ${it.id}: provedor "${it.provedor}" n\xE3o instalado`);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
let acao = proximaAcao(it, prov, agora);
|
|
100
|
+
while (acao) {
|
|
101
|
+
if (simular) {
|
|
102
|
+
log(`\u2022 ${it.id} ${it.rede} (${it.slug}): ${acao}`);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
if (acao === "preparar") {
|
|
107
|
+
it.prep = await prov.preparar({ item: it, ctx });
|
|
108
|
+
it.estado = "preparado";
|
|
109
|
+
log(`\u2713 ${it.id} ${it.rede}: preparado`);
|
|
110
|
+
} else {
|
|
111
|
+
it.resultado = await prov.publicar({ item: it, ctx });
|
|
112
|
+
it.estado = "enviado";
|
|
113
|
+
it.enviadoEm = (/* @__PURE__ */ new Date()).toISOString();
|
|
114
|
+
log(`\u2713 ${it.id} ${it.rede}${it.acao ? " (" + it.acao + ")" : ""}: enviado${it.resultado?.url ? " " + it.resultado.url : ""}`);
|
|
115
|
+
for (const s of it.resultado?.seguinte || []) fila.itens.push({ id: randomBytes(4).toString("hex"), estado: "pendente", tentativas: 0, criadoEm: (/* @__PURE__ */ new Date()).toISOString(), origem: it.id, ...s });
|
|
116
|
+
delete it.resultado.seguinte;
|
|
117
|
+
}
|
|
118
|
+
feitos.push(it.id);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
it.tentativas++;
|
|
121
|
+
it.erro = String(e.message || e).slice(0, 500);
|
|
122
|
+
if (it.tentativas >= MAX_TENTATIVAS) it.estado = "erro";
|
|
123
|
+
log(`\u2717 ${it.id} ${it.rede}: ${it.erro}${it.estado === "erro" ? " (desisti)" : ` (tentativa ${it.tentativas}/${MAX_TENTATIVAS})`}`);
|
|
124
|
+
}
|
|
125
|
+
salvarFila(raiz, fila);
|
|
126
|
+
acao = it.estado === "enviado" ? null : acao === "preparar" && it.estado === "preparado" ? proximaAcao(it, prov, agora) : null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { feitos, fila };
|
|
130
|
+
}
|
|
131
|
+
function plistLaunchd({ rotulo = "br.praeko.fila", node, praeko, arauto, cwd, minutos = 5, log }) {
|
|
132
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
133
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
134
|
+
<plist version="1.0"><dict>
|
|
135
|
+
<key>Label</key><string>${rotulo}</string>
|
|
136
|
+
<key>ProgramArguments</key><array><string>${node}</string><string>${praeko ?? arauto}</string><string>fila</string><string>executar</string></array>
|
|
137
|
+
<key>WorkingDirectory</key><string>${cwd}</string>
|
|
138
|
+
<key>StartInterval</key><integer>${minutos * 60}</integer>
|
|
139
|
+
<key>RunAtLoad</key><true/>
|
|
140
|
+
<key>StandardOutPath</key><string>${log}</string><key>StandardErrorPath</key><string>${log}</string>
|
|
141
|
+
</dict></plist>
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// import("./adaptadores/**/*.mjs") in ../core/src/publicador.mjs
|
|
146
|
+
var globImport_adaptadores_mjs = __glob({
|
|
147
|
+
"./adaptadores/buffer.mjs": () => import("./buffer-5TUDOBVN.mjs"),
|
|
148
|
+
"./adaptadores/index.mjs": () => import("./adaptadores-X3NUBMLT.mjs"),
|
|
149
|
+
"./adaptadores/local.mjs": () => import("./local-EUJHQ76T.mjs"),
|
|
150
|
+
"./adaptadores/remoto.mjs": () => import("./remoto-OAB5Y2MS.mjs")
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// ../core/src/publicador.mjs
|
|
154
|
+
async function criarPublicador({ config, provedor, ctx } = {}) {
|
|
155
|
+
const nome = provedor || config?.provedor || "buffer";
|
|
156
|
+
if (!PROVEDORES.includes(nome)) throw new Error(`provedor "${nome}" desconhecido (use ${PROVEDORES.join(", ")})`);
|
|
157
|
+
const mod = await globImport_adaptadores_mjs(`./adaptadores/${nome}.mjs`);
|
|
158
|
+
return mod.criar({ config, ctx });
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ../core/src/adaptadores/local.mjs
|
|
162
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
163
|
+
var MODO_PADRAO = { youtube: "privado", tiktok: "rascunho", instagram: "agora" };
|
|
164
|
+
function estadoDe(it) {
|
|
165
|
+
if (it.estado === "cancelado") return "cancelado";
|
|
166
|
+
if (it.estado === "erro") return "erro";
|
|
167
|
+
if (it.estado === "enviado") {
|
|
168
|
+
if (it.acao) return "enviado";
|
|
169
|
+
if (it.rede === "youtube" && it.resultado?.privacidade === "private" && !it.resultado?.publishAt) return "privado";
|
|
170
|
+
if (it.rede === "tiktok" && it.resultado?.modo === "rascunho") return "rascunho";
|
|
171
|
+
return it.rede === "youtube" && it.resultado?.publishAt ? "agendado" : "enviado";
|
|
172
|
+
}
|
|
173
|
+
return "agendado";
|
|
174
|
+
}
|
|
175
|
+
var itemDoContrato = (it) => ({ rede: it.rede, id: it.id, estado: estadoDe(it), quando: it.quando, ...it.acao ? { acao: it.acao } : {}, ...it.manual ? { manual: true } : {}, ...it.resultado?.url ? { url: it.resultado.url } : {}, ...it.resultado?.studio ? { studio: it.resultado.studio } : {}, ...it.erro ? { aviso: it.erro } : {} });
|
|
176
|
+
function criar({ config, ctx, provedores }) {
|
|
177
|
+
const todos = async () => provedores || carregarTodos();
|
|
178
|
+
const agora = () => ctx.agora ? ctx.agora() : /* @__PURE__ */ new Date();
|
|
179
|
+
const doPedido = (id) => lerFila(ctx.raiz).itens.filter((x) => x.pedido === id);
|
|
180
|
+
return {
|
|
181
|
+
nome: "local",
|
|
182
|
+
async publicar(pedido) {
|
|
183
|
+
const erros = validarPedido(pedido);
|
|
184
|
+
if (erros.length) throw new Error(`pedido inv\xE1lido: ${erros.join("; ")}`);
|
|
185
|
+
const id = pedido.id || `p${randomBytes2(3).toString("hex")}`, provs = await todos();
|
|
186
|
+
const faltam = pedido.destinos.filter((d) => !provs[d.rede]).map((d) => d.rede);
|
|
187
|
+
if (faltam.length) throw new Error(`provedor n\xE3o instalado: ${faltam.join(", ")}`);
|
|
188
|
+
const novos = pedido.destinos.map((d) => {
|
|
189
|
+
const op = { ...config[d.rede] || {}, ...pedido.opcoes?.[d.rede] || {} };
|
|
190
|
+
op.modo = d.modo || op.modo || MODO_PADRAO[d.rede];
|
|
191
|
+
return enfileirar(ctx.raiz, { pedido: id, slug: id, rede: d.rede, provedor: d.rede, quando: d.quando || agora().toISOString(), video: pedido.midia.video, capa: pedido.midia.capa || null, textos: pedido.textos[d.rede], opcoes: op, formato: pedido.opcoes?.formato || "short", titulo: pedido.titulo });
|
|
192
|
+
});
|
|
193
|
+
await executar({ raiz: ctx.raiz, provedores: provs, ctx, agora: agora(), soIds: novos.map((n) => n.id), log: ctx.log });
|
|
194
|
+
return { id, itens: doPedido(id).map(itemDoContrato) };
|
|
195
|
+
},
|
|
196
|
+
async status(id) {
|
|
197
|
+
const it = doPedido(id);
|
|
198
|
+
if (!it.length) throw new Error(`pedido ${id} n\xE3o existe na fila`);
|
|
199
|
+
return { id, itens: it.map(itemDoContrato) };
|
|
200
|
+
},
|
|
201
|
+
async cancelar(id) {
|
|
202
|
+
const cancelados = [], mantidos = [];
|
|
203
|
+
for (const it of doPedido(id)) {
|
|
204
|
+
if (["enviado", "cancelado"].includes(it.estado)) {
|
|
205
|
+
if (it.estado === "enviado") mantidos.push(itemDoContrato(it));
|
|
206
|
+
} else {
|
|
207
|
+
cancelarItem(ctx.raiz, it.id);
|
|
208
|
+
cancelados.push(it.id);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return { cancelados, mantidos };
|
|
212
|
+
},
|
|
213
|
+
async canais() {
|
|
214
|
+
const provs = await todos(), out = [];
|
|
215
|
+
for (const [rede, p] of Object.entries(provs)) {
|
|
216
|
+
const s = await p.status({ ctx });
|
|
217
|
+
out.push({ rede, conectado: s.conectado, detalhe: s.detalhe });
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export {
|
|
225
|
+
pastaEstado,
|
|
226
|
+
caminhoEstado,
|
|
227
|
+
caminhoLeitura,
|
|
228
|
+
lerFila,
|
|
229
|
+
liberarItem,
|
|
230
|
+
cancelarItem,
|
|
231
|
+
executar,
|
|
232
|
+
plistLaunchd,
|
|
233
|
+
MODO_PADRAO,
|
|
234
|
+
estadoDe,
|
|
235
|
+
criar,
|
|
236
|
+
local_exports,
|
|
237
|
+
criarPublicador
|
|
238
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __glob = (map) => (path) => {
|
|
4
|
+
var fn = map[path];
|
|
5
|
+
if (fn) return fn();
|
|
6
|
+
throw new Error("Module not found in bundle: " + path);
|
|
7
|
+
};
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
__glob,
|
|
15
|
+
__export
|
|
16
|
+
};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { createRequire as __cr } from 'node:module'; const require = __cr(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
API,
|
|
4
|
+
api,
|
|
5
|
+
canalId,
|
|
6
|
+
falha
|
|
7
|
+
} from "./chunk-UK3UKRPR.mjs";
|
|
8
|
+
|
|
9
|
+
// ../core/src/provedores/youtube-comunidade.mjs
|
|
10
|
+
var lerJson = async (r) => {
|
|
11
|
+
const t = await r.text();
|
|
12
|
+
if (!r.ok) throw falha(r.status, t);
|
|
13
|
+
return t ? JSON.parse(t) : {};
|
|
14
|
+
};
|
|
15
|
+
var ate = (n, max) => Math.max(1, Math.min(max, Math.floor(+n) || 20));
|
|
16
|
+
var resumoVideo = (v) => ({
|
|
17
|
+
id: v.id,
|
|
18
|
+
titulo: v.snippet?.title,
|
|
19
|
+
descricao: v.snippet?.description,
|
|
20
|
+
publicadoEm: v.snippet?.publishedAt,
|
|
21
|
+
privacidade: v.status?.privacyStatus,
|
|
22
|
+
publishAt: v.status?.publishAt || null,
|
|
23
|
+
duracao: v.contentDetails?.duration,
|
|
24
|
+
tags: v.snippet?.tags || [],
|
|
25
|
+
visualizacoes: v.statistics?.viewCount != null ? +v.statistics.viewCount : null,
|
|
26
|
+
curtidas: v.statistics?.likeCount != null ? +v.statistics.likeCount : null,
|
|
27
|
+
comentarios: v.statistics?.commentCount != null ? +v.statistics.commentCount : null,
|
|
28
|
+
url: `https://youtu.be/${v.id}`
|
|
29
|
+
});
|
|
30
|
+
async function listarVideos({ ctx, max = 20, pagina }) {
|
|
31
|
+
const cid = await canalId(ctx);
|
|
32
|
+
const c = await lerJson(await api(ctx, `${API}/channels?part=contentDetails&id=${cid}`));
|
|
33
|
+
const uploads = c.items?.[0]?.contentDetails?.relatedPlaylists?.uploads;
|
|
34
|
+
if (!uploads) throw new Error("o canal n\xE3o tem playlist de uploads");
|
|
35
|
+
const p = await lerJson(await api(ctx, `${API}/playlistItems?part=contentDetails&playlistId=${uploads}&maxResults=${ate(max, 50)}${pagina ? `&pageToken=${encodeURIComponent(pagina)}` : ""}`));
|
|
36
|
+
const ids = (p.items || []).map((i) => i.contentDetails?.videoId).filter(Boolean);
|
|
37
|
+
if (!ids.length) return { videos: [], proxima: p.nextPageToken || null };
|
|
38
|
+
const d = await lerJson(await api(ctx, `${API}/videos?part=snippet,status,statistics,contentDetails&id=${ids.join(",")}&maxResults=50`));
|
|
39
|
+
const porId = new Map((d.items || []).map((v) => [v.id, v]));
|
|
40
|
+
return { videos: ids.map((id) => porId.get(id)).filter(Boolean).map(resumoVideo), proxima: p.nextPageToken || null };
|
|
41
|
+
}
|
|
42
|
+
async function lerVideo({ ctx, videoId }) {
|
|
43
|
+
const d = await lerJson(await api(ctx, `${API}/videos?part=snippet,status,statistics,contentDetails&id=${encodeURIComponent(videoId)}`));
|
|
44
|
+
const v = d.items?.[0];
|
|
45
|
+
if (!v) throw Object.assign(new Error(`o v\xEDdeo ${videoId} n\xE3o existe neste canal`), { status: 404 });
|
|
46
|
+
return resumoVideo(v);
|
|
47
|
+
}
|
|
48
|
+
var CAMPOS_SNIPPET = ["title", "description", "tags", "categoryId", "defaultLanguage", "defaultAudioLanguage"];
|
|
49
|
+
var semAngulos = (s) => !/[<>]/.test(s);
|
|
50
|
+
async function apagarVideo({ ctx, videoId }) {
|
|
51
|
+
const r = await api(ctx, `${API}/videos?id=${encodeURIComponent(videoId)}`, { method: "DELETE" });
|
|
52
|
+
if (r.status === 404) return { id: videoId, apagado: false, jaNaoExistia: true };
|
|
53
|
+
if (r.status < 200 || r.status > 299) throw Object.assign(new Error(`o YouTube recusou apagar o v\xEDdeo (HTTP ${r.status})`), { status: r.status });
|
|
54
|
+
return { id: videoId, apagado: true };
|
|
55
|
+
}
|
|
56
|
+
async function editarVideo({ ctx, videoId, titulo, descricao, tags, simular = false }) {
|
|
57
|
+
if (titulo === void 0 && descricao === void 0 && tags === void 0) throw new Error("nada para mudar: informe titulo, descricao ou tags");
|
|
58
|
+
if (titulo !== void 0 && (!titulo.trim() || titulo.length > 100 || !semAngulos(titulo))) throw new Error("t\xEDtulo inv\xE1lido: de 1 a 100 caracteres e sem < ou >");
|
|
59
|
+
if (descricao !== void 0 && (descricao.length > 5e3 || !semAngulos(descricao))) throw new Error("descri\xE7\xE3o inv\xE1lida: at\xE9 5000 caracteres e sem < ou >");
|
|
60
|
+
if (tags !== void 0 && (!Array.isArray(tags) || tags.join(",").length > 500)) throw new Error("tags inv\xE1lidas: lista de at\xE9 500 caracteres no total");
|
|
61
|
+
const d = await lerJson(await api(ctx, `${API}/videos?part=snippet&id=${encodeURIComponent(videoId)}`));
|
|
62
|
+
const v = d.items?.[0];
|
|
63
|
+
if (!v) throw Object.assign(new Error(`o v\xEDdeo ${videoId} n\xE3o existe neste canal`), { status: 404 });
|
|
64
|
+
const atual = {};
|
|
65
|
+
for (const k of CAMPOS_SNIPPET) if (v.snippet?.[k] !== void 0) atual[k] = v.snippet[k];
|
|
66
|
+
const novo = { ...atual, ...titulo !== void 0 ? { title: titulo } : {}, ...descricao !== void 0 ? { description: descricao } : {}, ...tags !== void 0 ? { tags } : {} };
|
|
67
|
+
const antes = { titulo: atual.title, descricao: atual.description, tags: atual.tags || [] };
|
|
68
|
+
const depois = { titulo: novo.title, descricao: novo.description, tags: novo.tags || [] };
|
|
69
|
+
const mudou = JSON.stringify(antes) !== JSON.stringify(depois);
|
|
70
|
+
if (simular || !mudou) return { id: videoId, antes, depois, mudou, escrito: false };
|
|
71
|
+
await lerJson(await api(ctx, `${API}/videos?part=snippet`, { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify({ id: videoId, snippet: novo }) }));
|
|
72
|
+
return { id: videoId, antes, depois, mudou, escrito: true, url: `https://youtu.be/${videoId}` };
|
|
73
|
+
}
|
|
74
|
+
var comentarioDe = (c) => ({
|
|
75
|
+
id: c.id,
|
|
76
|
+
autor: c.snippet?.authorDisplayName,
|
|
77
|
+
autorCanal: c.snippet?.authorChannelId?.value || null,
|
|
78
|
+
texto: c.snippet?.textOriginal ?? c.snippet?.textDisplay,
|
|
79
|
+
publicadoEm: c.snippet?.publishedAt,
|
|
80
|
+
curtidas: c.snippet?.likeCount ?? 0
|
|
81
|
+
});
|
|
82
|
+
async function donoRespondeu(ctx, thread, cid) {
|
|
83
|
+
const total = thread.snippet?.totalReplyCount ?? 0;
|
|
84
|
+
if (!total) return false;
|
|
85
|
+
const vindas = (thread.replies?.comments || []).map(comentarioDe);
|
|
86
|
+
if (vindas.some((c) => c.autorCanal === cid)) return true;
|
|
87
|
+
if (vindas.length >= total) return false;
|
|
88
|
+
let pagina;
|
|
89
|
+
do {
|
|
90
|
+
const r = await lerJson(await api(ctx, `${API}/comments?part=snippet&parentId=${encodeURIComponent(thread.id)}&maxResults=100&textFormat=plainText${pagina ? `&pageToken=${encodeURIComponent(pagina)}` : ""}`));
|
|
91
|
+
if ((r.items || []).some((c) => c.snippet?.authorChannelId?.value === cid)) return true;
|
|
92
|
+
pagina = r.nextPageToken;
|
|
93
|
+
} while (pagina);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
async function listarComentarios({ ctx, videoId, semResposta = false, max = 20, pagina }) {
|
|
97
|
+
const cid = await canalId(ctx);
|
|
98
|
+
const alvo = videoId ? `videoId=${encodeURIComponent(videoId)}` : `allThreadsRelatedToChannelId=${cid}`;
|
|
99
|
+
const saida = [];
|
|
100
|
+
let prox = pagina || null, paginas = 0;
|
|
101
|
+
do {
|
|
102
|
+
const r = await lerJson(await api(ctx, `${API}/commentThreads?part=snippet,replies&${alvo}&maxResults=${ate(semResposta ? 100 : max, 100)}&order=time&textFormat=plainText${prox ? `&pageToken=${encodeURIComponent(prox)}` : ""}`));
|
|
103
|
+
paginas++;
|
|
104
|
+
prox = r.nextPageToken || null;
|
|
105
|
+
for (const t of r.items || []) {
|
|
106
|
+
const topo = comentarioDe(t.snippet?.topLevelComment || {});
|
|
107
|
+
const doDono = topo.autorCanal === cid;
|
|
108
|
+
const respondido = doDono ? false : await donoRespondeu(ctx, t, cid);
|
|
109
|
+
if (semResposta && (doDono || respondido)) continue;
|
|
110
|
+
saida.push({
|
|
111
|
+
id: t.id,
|
|
112
|
+
videoId: t.snippet?.videoId || videoId || null,
|
|
113
|
+
...topo,
|
|
114
|
+
doDono,
|
|
115
|
+
totalRespostas: t.snippet?.totalReplyCount ?? 0,
|
|
116
|
+
respondido,
|
|
117
|
+
respostas: (t.replies?.comments || []).map(comentarioDe)
|
|
118
|
+
});
|
|
119
|
+
if (saida.length >= max) return { comentarios: saida, proxima: prox };
|
|
120
|
+
}
|
|
121
|
+
} while (prox && semResposta && paginas < 10);
|
|
122
|
+
return { comentarios: saida, proxima: prox };
|
|
123
|
+
}
|
|
124
|
+
async function responderComentario({ ctx, parentId, texto }) {
|
|
125
|
+
if (!parentId) throw new Error("falta o id do coment\xE1rio (thread)");
|
|
126
|
+
if (!texto || !texto.trim() || texto.length > 1e4) throw new Error("texto inv\xE1lido: de 1 a 10000 caracteres");
|
|
127
|
+
const j = await lerJson(await api(ctx, `${API}/comments?part=snippet`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ snippet: { parentId, textOriginal: texto } }) }));
|
|
128
|
+
return { id: j.id, parentId, texto: j.snippet?.textOriginal ?? texto };
|
|
129
|
+
}
|
|
130
|
+
function trocarHashtags(descricao, novas) {
|
|
131
|
+
const nv = String(novas).trim().split(/\s+/).filter(Boolean).map((h) => h.startsWith("#") ? h : `#${h}`).join(" ");
|
|
132
|
+
if (!nv) throw new Error("informe ao menos uma hashtag");
|
|
133
|
+
const linhas = String(descricao || "").replace(/\s+$/, "").split("\n");
|
|
134
|
+
for (let i = linhas.length - 1; i >= 0; i--) {
|
|
135
|
+
if (!linhas[i].trim()) continue;
|
|
136
|
+
if (/^\s*(#\S+\s*)+$/.test(linhas[i])) {
|
|
137
|
+
linhas[i] = nv;
|
|
138
|
+
return linhas.join("\n");
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
return `${linhas.join("\n")}
|
|
143
|
+
|
|
144
|
+
${nv}`.replace(/^\n+/, "");
|
|
145
|
+
}
|
|
146
|
+
var num = (x) => x != null && x !== "" && !Number.isNaN(+x) ? +x : null;
|
|
147
|
+
async function estatisticasVideos({ ctx, ids }) {
|
|
148
|
+
const saida = /* @__PURE__ */ new Map(), unicos = [...new Set(ids)];
|
|
149
|
+
for (let i = 0; i < unicos.length; i += 50) {
|
|
150
|
+
const lote = unicos.slice(i, i + 50);
|
|
151
|
+
const d = await lerJson(await api(ctx, `${API}/videos?part=snippet,status,statistics&id=${lote.map(encodeURIComponent).join(",")}&maxResults=50`));
|
|
152
|
+
for (const v of d.items || []) {
|
|
153
|
+
saida.set(v.id, {
|
|
154
|
+
views: num(v.statistics?.viewCount),
|
|
155
|
+
curtidas: num(v.statistics?.likeCount),
|
|
156
|
+
comentarios: num(v.statistics?.commentCount),
|
|
157
|
+
privacidade: v.status?.privacyStatus || null,
|
|
158
|
+
publishAt: v.status?.publishAt || null,
|
|
159
|
+
publicadoEm: v.snippet?.publishedAt || null,
|
|
160
|
+
titulo: v.snippet?.title || null
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return saida;
|
|
165
|
+
}
|
|
166
|
+
async function estatisticasCanal({ ctx }) {
|
|
167
|
+
const d = await lerJson(await api(ctx, `${API}/channels?part=statistics&mine=true`));
|
|
168
|
+
const c = d.items?.[0];
|
|
169
|
+
if (!c) throw new Error("a conta autorizada n\xE3o tem canal do YouTube");
|
|
170
|
+
const s = c.statistics || {};
|
|
171
|
+
return { seguidores: s.hiddenSubscriberCount ? null : num(s.subscriberCount), totalViews: num(s.viewCount), totalVideos: num(s.videoCount) };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
listarVideos,
|
|
176
|
+
lerVideo,
|
|
177
|
+
apagarVideo,
|
|
178
|
+
editarVideo,
|
|
179
|
+
listarComentarios,
|
|
180
|
+
responderComentario,
|
|
181
|
+
trocarHashtags,
|
|
182
|
+
estatisticasVideos,
|
|
183
|
+
estatisticasCanal
|
|
184
|
+
};
|