@praeko/cli 0.0.0-stage → 0.1.1
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 +13 -0
- package/LICENSE +21 -0
- package/README.md +58 -2
- package/dist/chunks/adaptadores-ESUZ36N2.mjs +18 -0
- package/dist/chunks/buffer-SP52FWTI.mjs +14 -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-TTGQU5CG.mjs +238 -0
- package/dist/chunks/chunk-UK3UKRPR.mjs +363 -0
- package/dist/chunks/chunk-VJRMAQCR.mjs +56 -0
- package/dist/chunks/chunk-Z325UM27.mjs +34 -0
- package/dist/chunks/chunk-ZZKGFOPH.mjs +415 -0
- package/dist/chunks/instagram-GNY73ESY.mjs +293 -0
- package/dist/chunks/instagram-meta-COY6BTNX.mjs +412 -0
- package/dist/chunks/local-FMMUWECN.mjs +14 -0
- package/dist/chunks/registro-5PYVQ5LJ.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 +854 -0
- package/package.json +47 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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.1] - 2026-11-07
|
|
6
|
+
|
|
7
|
+
- Um só comando, `praeko` (o alias `arauto` saiu do pacote). Com dois comandos o `npx @praeko/cli` não sabia qual rodar e falhava com "could not determine executable to run"; agora `npx @praeko/cli --help` funciona. Quem usou a 0.1.0 pode rodar `npx -p @praeko/cli praeko`.
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-11-07
|
|
10
|
+
|
|
11
|
+
Primeira versão preparada para o npm.
|
|
12
|
+
- Pacote `@praeko/cli`: comando `praeko`, empacotado em `dist/` com o core e o SDK embutidos (sem dependências); `--version`; `praeko studio` avisa quando o Studio não está instalado.
|
|
13
|
+
- 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` (antes chamado `arauto`). 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.
|
|
@@ -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-ZZKGFOPH.mjs";
|
|
5
|
+
import {
|
|
6
|
+
local_exports
|
|
7
|
+
} from "./chunk-TTGQU5CG.mjs";
|
|
8
|
+
import "./chunk-VJRMAQCR.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-ZZKGFOPH.mjs";
|
|
6
|
+
import "./chunk-TTGQU5CG.mjs";
|
|
7
|
+
import "./chunk-VJRMAQCR.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,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
|
+
};
|