@zfadhli/tokrec 0.18.1 → 0.18.3
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/dist/app/config.mjs +11 -0
- package/dist/app/config.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/config.ts +3 -0
- package/src/index.ts +2 -1
package/dist/app/config.mjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { TikTokError } from "../core/errors.mjs";
|
|
1
2
|
import "../io/http.mjs";
|
|
2
3
|
//#region src/app/config.ts
|
|
4
|
+
/**
|
|
5
|
+
* Config — types, defaults, and normalization for the recorder.
|
|
6
|
+
* The single source of truth for every user-facing option.
|
|
7
|
+
*/
|
|
3
8
|
/** Apply defaults once, at the entry point; nothing downstream re-reads `??`. */
|
|
4
9
|
function resolveConfig(config) {
|
|
10
|
+
validateConfig(config);
|
|
5
11
|
return {
|
|
6
12
|
user: config.user,
|
|
7
13
|
outputDir: config.outputDir ?? ".",
|
|
@@ -21,6 +27,11 @@ function resolveConfig(config) {
|
|
|
21
27
|
debug: config.debug ?? false
|
|
22
28
|
};
|
|
23
29
|
}
|
|
30
|
+
function validateConfig(config) {
|
|
31
|
+
if (!config.user || config.user.trim().length === 0) throw new TikTokError("config-error", "--user is required");
|
|
32
|
+
if (config.interval !== void 0 && config.interval < 1) throw new TikTokError("config-error", "--interval must be >= 1 minute");
|
|
33
|
+
if (config.duration !== void 0 && config.duration < 0) throw new TikTokError("config-error", "--duration must be >= 0 seconds");
|
|
34
|
+
}
|
|
24
35
|
//#endregion
|
|
25
36
|
export { resolveConfig };
|
|
26
37
|
|
package/dist/app/config.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/app/config.ts"],"sourcesContent":["/**\n * Config — types, defaults, and normalization for the recorder.\n * The single source of truth for every user-facing option.\n */\n\nimport { TikTokError } from \"../core/errors\"\nimport type { Verdict } from \"../core/verdict\"\n\n/**\n * TikTok cookie key-value pairs extracted from Firefox or cookies.json.\n * Includes session cookies (sessionid_ss) and any WAF bypass cookies needed to\n * avoid Slardar challenges on www.tiktok.com. Routing hints TikTok computes per\n * session (`tt-target-idc`, `tt-target-idc-sign`) are dropped before sending —\n * see `splitCookies` in `io/http.ts`.\n */\nexport type CookieAuth = Record<string, string>\n\n/**\n * Re-exported so callers who build `cookies` themselves — the CLI among them —\n * can warn about a hint we refuse to send without hardcoding its name. `io/`\n * is outside the barrel's bands, and this type is the cookie surface.\n */\nexport { splitCookies } from \"../io/http\"\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\"\n\n/**\n * Machine-readable reason for a LIVE status verdict — lives in `core/verdict.ts`.\n */\nexport type { LiveReason } from \"../core/verdict\"\n\nexport interface RecorderConfig {\n /** TikTok username (required) */\n user: string\n /** Output directory for recordings (default: ./recordings) */\n outputDir?: string\n /** Polling interval in minutes (default: 3) */\n interval?: number\n /** Max recording duration in seconds (default: 0 — unlimited). CLI accepts minutes, converted internally. */\n duration?: number\n /** HTTP proxy URL (e.g. http://127.0.0.1:8080) */\n proxy?: string\n /** Path to cookies.json (default: ./cookies.json) */\n cookiesPath?: string\n /** Cookie auth loaded from cookies.json */\n cookies?: CookieAuth\n /** Log level (default: info) */\n logLevel?: LogLevel\n /** Whether to print logs to console (default: true). Set false when using Display-based UI. */\n logConsole?: boolean\n /** Segment duration in minutes (default: 0 — disabled). When >= 1, the recording is split into segments of this length. */\n segmentMinutes?: number\n /** Normalize audio loudness via EBU R128 (default: false). */\n normalizeAudio?: boolean\n /** Target loudness in LUFS (default: -14). */\n normalizeLoudness?: number\n /** Audio codec for normalized output (default: peaknorm's default, \"libopus\"). */\n normalizeCodec?: string\n /** Audio bitrate for normalized output (default: peaknorm's default, \"96k\"). */\n normalizeBitrate?: string\n /**\n * Max API requests per second (default: 5).\n * Prevents TikTok WAF triggering on rapid polling or URL refresh loops.\n * Set to 0 for unlimited (not recommended).\n */\n ratePerSecond?: number\n /** Show API debug logging on stderr (default: false). */\n debug?: boolean\n}\n\nexport interface RecorderController {\n /** Start the polling loop */\n start(): Promise<void>\n /** Gracefully stop (joins active recording, then exits) */\n stop(): Promise<void>\n /** Snapshot of current state */\n getStatus(): RecorderStatus\n /** Subscribe to events */\n on<E extends keyof RecorderEventHandler>(event: E, handler: RecorderEventHandler[E]): void\n /** Unsubscribe a previously registered event handler */\n off<E extends keyof RecorderEventHandler>(event: E, handler: RecorderEventHandler[E]): void\n}\n\nexport type Phase = \"idle\" | \"polling\" | \"recording\" | \"segmenting\" | \"converting\" | \"stopped\"\n\nexport interface RecorderStatus {\n state: Phase\n user: string\n currentFile?: string\n sessionDuration?: number\n lastPollTime?: string\n lastError?: string\n}\n\nexport type RecorderEvent = keyof RecorderEventHandler\n\nexport interface RecordedFile {\n file: string\n duration: number\n size: number\n}\n\n/** One recording lifecycle channel: start → download → processing → end. */\nexport type RecordEvent =\n | { phase: \"start\"; user: string; file: string }\n | ({ phase: \"download\" } & RecordedFile)\n | { phase: \"segment\"; status: \"start\"; input: string; outputPattern: string }\n | { phase: \"segment\"; status: \"end\"; segments: number }\n | { phase: \"convert\"; status: \"start\"; input: string }\n | { phase: \"convert\"; status: \"done\"; input: string; output: string }\n | { phase: \"normalize\"; status: \"start\"; file: string }\n | { phase: \"normalize\"; status: \"done\"; input: string; output: string }\n | { phase: \"normalize\"; status: \"error\"; input: string; error: string }\n | ({ phase: \"end\" } & RecordedFile)\n\n/** One download progress sample. The finished-download shape is `RecordedFile`. */\nexport interface DownloadProgress {\n bytes: number\n elapsed: number\n speed: number\n}\n\n/** Download and normalize progress share one spinner in the CLI. */\nexport type ProgressEvent =\n | ({ kind: \"download\" } & DownloadProgress)\n | { kind: \"normalize\"; file: string; percent: number; phase: \"analyzing\" | \"normalizing\" }\n\nexport interface RecorderEventHandler {\n verdict: (verdict: Verdict) => void\n record: (event: RecordEvent) => void\n progress: (event: ProgressEvent) => void\n failure: (err: TikTokError) => void\n}\n\n/** A `RecorderConfig` with every default applied — what the recorder runs on. */\nexport type ResolvedConfig = Required<\n Omit<RecorderConfig, \"proxy\" | \"cookies\" | \"cookiesPath\" | \"normalizeCodec\" | \"normalizeBitrate\">\n> &\n Pick<RecorderConfig, \"proxy\" | \"cookies\" | \"cookiesPath\" | \"normalizeCodec\" | \"normalizeBitrate\">\n\n/** Apply defaults once, at the entry point; nothing downstream re-reads `??`. */\nexport function resolveConfig(config: RecorderConfig): ResolvedConfig {\n return {\n user: config.user,\n outputDir: config.outputDir ?? \".\",\n interval: config.interval ?? 3,\n duration: config.duration ?? 0,\n proxy: config.proxy,\n cookies: config.cookies,\n cookiesPath: config.cookiesPath,\n logLevel: config.logLevel ?? \"info\",\n logConsole: config.logConsole ?? true,\n segmentMinutes: config.segmentMinutes ?? 0,\n normalizeAudio: config.normalizeAudio ?? false,\n normalizeLoudness: config.normalizeLoudness ?? -14,\n normalizeCodec: config.normalizeCodec,\n normalizeBitrate: config.normalizeBitrate,\n ratePerSecond: config.ratePerSecond ?? 5,\n debug: config.debug ?? false,\n }\n}\n\nexport function validateConfig(config: RecorderConfig): void {\n if (!config.user || config.user.trim().length === 0) {\n throw new TikTokError(\"config-error\", \"--user is required\")\n }\n if (config.interval !== undefined && config.interval < 1) {\n throw new TikTokError(\"config-error\", \"--interval must be >= 1 minute\")\n }\n if (config.duration !== undefined && config.duration < 0) {\n throw new TikTokError(\"config-error\", \"--duration must be >= 0 seconds\")\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.mjs","names":[],"sources":["../../src/app/config.ts"],"sourcesContent":["/**\n * Config — types, defaults, and normalization for the recorder.\n * The single source of truth for every user-facing option.\n */\n\nimport { TikTokError } from \"../core/errors\"\nimport type { Verdict } from \"../core/verdict\"\n\n/**\n * TikTok cookie key-value pairs extracted from Firefox or cookies.json.\n * Includes session cookies (sessionid_ss) and any WAF bypass cookies needed to\n * avoid Slardar challenges on www.tiktok.com. Routing hints TikTok computes per\n * session (`tt-target-idc`, `tt-target-idc-sign`) are dropped before sending —\n * see `splitCookies` in `io/http.ts`.\n */\nexport type CookieAuth = Record<string, string>\n\n/**\n * Re-exported so callers who build `cookies` themselves — the CLI among them —\n * can warn about a hint we refuse to send without hardcoding its name. `io/`\n * is outside the barrel's bands, and this type is the cookie surface.\n */\nexport { splitCookies } from \"../io/http\"\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\"\n\n/**\n * Machine-readable reason for a LIVE status verdict — lives in `core/verdict.ts`.\n */\nexport type { LiveReason } from \"../core/verdict\"\n\nexport interface RecorderConfig {\n /** TikTok username (required) */\n user: string\n /** Output directory for recordings (default: ./recordings) */\n outputDir?: string\n /** Polling interval in minutes (default: 3) */\n interval?: number\n /** Max recording duration in seconds (default: 0 — unlimited). CLI accepts minutes, converted internally. */\n duration?: number\n /** HTTP proxy URL (e.g. http://127.0.0.1:8080) */\n proxy?: string\n /** Path to cookies.json (default: ./cookies.json) */\n cookiesPath?: string\n /** Cookie auth loaded from cookies.json */\n cookies?: CookieAuth\n /** Log level (default: info) */\n logLevel?: LogLevel\n /** Whether to print logs to console (default: true). Set false when using Display-based UI. */\n logConsole?: boolean\n /** Segment duration in minutes (default: 0 — disabled). When >= 1, the recording is split into segments of this length. */\n segmentMinutes?: number\n /** Normalize audio loudness via EBU R128 (default: false). */\n normalizeAudio?: boolean\n /** Target loudness in LUFS (default: -14). */\n normalizeLoudness?: number\n /** Audio codec for normalized output (default: peaknorm's default, \"libopus\"). */\n normalizeCodec?: string\n /** Audio bitrate for normalized output (default: peaknorm's default, \"96k\"). */\n normalizeBitrate?: string\n /**\n * Max API requests per second (default: 5).\n * Prevents TikTok WAF triggering on rapid polling or URL refresh loops.\n * Set to 0 for unlimited (not recommended).\n */\n ratePerSecond?: number\n /** Show API debug logging on stderr (default: false). */\n debug?: boolean\n}\n\nexport interface RecorderController {\n /** Start the polling loop */\n start(): Promise<void>\n /** Gracefully stop (joins active recording, then exits) */\n stop(): Promise<void>\n /** Snapshot of current state */\n getStatus(): RecorderStatus\n /** Subscribe to events */\n on<E extends keyof RecorderEventHandler>(event: E, handler: RecorderEventHandler[E]): void\n /** Unsubscribe a previously registered event handler */\n off<E extends keyof RecorderEventHandler>(event: E, handler: RecorderEventHandler[E]): void\n}\n\nexport type Phase = \"idle\" | \"polling\" | \"recording\" | \"segmenting\" | \"converting\" | \"stopped\"\n\nexport interface RecorderStatus {\n state: Phase\n user: string\n currentFile?: string\n sessionDuration?: number\n lastPollTime?: string\n lastError?: string\n}\n\nexport type RecorderEvent = keyof RecorderEventHandler\n\nexport interface RecordedFile {\n file: string\n duration: number\n size: number\n}\n\n/** One recording lifecycle channel: start → download → processing → end. */\nexport type RecordEvent =\n | { phase: \"start\"; user: string; file: string }\n | ({ phase: \"download\" } & RecordedFile)\n | { phase: \"segment\"; status: \"start\"; input: string; outputPattern: string }\n | { phase: \"segment\"; status: \"end\"; segments: number }\n | { phase: \"convert\"; status: \"start\"; input: string }\n | { phase: \"convert\"; status: \"done\"; input: string; output: string }\n | { phase: \"normalize\"; status: \"start\"; file: string }\n | { phase: \"normalize\"; status: \"done\"; input: string; output: string }\n | { phase: \"normalize\"; status: \"error\"; input: string; error: string }\n | ({ phase: \"end\" } & RecordedFile)\n\n/** One download progress sample. The finished-download shape is `RecordedFile`. */\nexport interface DownloadProgress {\n bytes: number\n elapsed: number\n speed: number\n}\n\n/** Download and normalize progress share one spinner in the CLI. */\nexport type ProgressEvent =\n | ({ kind: \"download\" } & DownloadProgress)\n | { kind: \"normalize\"; file: string; percent: number; phase: \"analyzing\" | \"normalizing\" }\n\nexport interface RecorderEventHandler {\n verdict: (verdict: Verdict) => void\n record: (event: RecordEvent) => void\n progress: (event: ProgressEvent) => void\n failure: (err: TikTokError) => void\n}\n\n/** A `RecorderConfig` with every default applied — what the recorder runs on. */\nexport type ResolvedConfig = Required<\n Omit<RecorderConfig, \"proxy\" | \"cookies\" | \"cookiesPath\" | \"normalizeCodec\" | \"normalizeBitrate\">\n> &\n Pick<RecorderConfig, \"proxy\" | \"cookies\" | \"cookiesPath\" | \"normalizeCodec\" | \"normalizeBitrate\">\n\n/** Apply defaults once, at the entry point; nothing downstream re-reads `??`. */\nexport function resolveConfig(config: RecorderConfig): ResolvedConfig {\n // The library's trust boundary: a caller that builds its own config gets the\n // same refusal the CLI does instead of a recorder polling `--user \"\"`.\n validateConfig(config)\n return {\n user: config.user,\n outputDir: config.outputDir ?? \".\",\n interval: config.interval ?? 3,\n duration: config.duration ?? 0,\n proxy: config.proxy,\n cookies: config.cookies,\n cookiesPath: config.cookiesPath,\n logLevel: config.logLevel ?? \"info\",\n logConsole: config.logConsole ?? true,\n segmentMinutes: config.segmentMinutes ?? 0,\n normalizeAudio: config.normalizeAudio ?? false,\n normalizeLoudness: config.normalizeLoudness ?? -14,\n normalizeCodec: config.normalizeCodec,\n normalizeBitrate: config.normalizeBitrate,\n ratePerSecond: config.ratePerSecond ?? 5,\n debug: config.debug ?? false,\n }\n}\n\nexport function validateConfig(config: RecorderConfig): void {\n if (!config.user || config.user.trim().length === 0) {\n throw new TikTokError(\"config-error\", \"--user is required\")\n }\n if (config.interval !== undefined && config.interval < 1) {\n throw new TikTokError(\"config-error\", \"--interval must be >= 1 minute\")\n }\n if (config.duration !== undefined && config.duration < 0) {\n throw new TikTokError(\"config-error\", \"--duration must be >= 0 seconds\")\n }\n}\n"],"mappings":";;;;;;;;AA6IA,SAAgB,cAAc,QAAwC;CAGpE,eAAe,MAAM;CACrB,OAAO;EACL,MAAM,OAAO;EACb,WAAW,OAAO,aAAa;EAC/B,UAAU,OAAO,YAAY;EAC7B,UAAU,OAAO,YAAY;EAC7B,OAAO,OAAO;EACd,SAAS,OAAO;EAChB,aAAa,OAAO;EACpB,UAAU,OAAO,YAAY;EAC7B,YAAY,OAAO,cAAc;EACjC,gBAAgB,OAAO,kBAAkB;EACzC,gBAAgB,OAAO,kBAAkB;EACzC,mBAAmB,OAAO,qBAAqB;EAC/C,gBAAgB,OAAO;EACvB,kBAAkB,OAAO;EACzB,eAAe,OAAO,iBAAiB;EACvC,OAAO,OAAO,SAAS;CACzB;AACF;AAEA,SAAgB,eAAe,QAA8B;CAC3D,IAAI,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,GAChD,MAAM,IAAI,YAAY,gBAAgB,oBAAoB;CAE5D,IAAI,OAAO,aAAa,KAAA,KAAa,OAAO,WAAW,GACrD,MAAM,IAAI,YAAY,gBAAgB,gCAAgC;CAExE,IAAI,OAAO,aAAa,KAAA,KAAa,OAAO,WAAW,GACrD,MAAM,IAAI,YAAY,gBAAgB,iCAAiC;AAE3E"}
|
package/package.json
CHANGED
package/src/app/config.ts
CHANGED
|
@@ -140,6 +140,9 @@ export type ResolvedConfig = Required<
|
|
|
140
140
|
|
|
141
141
|
/** Apply defaults once, at the entry point; nothing downstream re-reads `??`. */
|
|
142
142
|
export function resolveConfig(config: RecorderConfig): ResolvedConfig {
|
|
143
|
+
// The library's trust boundary: a caller that builds its own config gets the
|
|
144
|
+
// same refusal the CLI does instead of a recorder polling `--user ""`.
|
|
145
|
+
validateConfig(config)
|
|
143
146
|
return {
|
|
144
147
|
user: config.user,
|
|
145
148
|
outputDir: config.outputDir ?? ".",
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* import { createRecorder } from '@zfadhli/tokrec'
|
|
6
6
|
*
|
|
7
7
|
* const recorder = createRecorder({ user: 'username', outputDir: './videos' })
|
|
8
|
-
* recorder.on('
|
|
8
|
+
* recorder.on('verdict', (v) => { if (v.reason === 'live') console.log('LIVE', v.room?.id) })
|
|
9
|
+
* recorder.on('record', (e) => { if (e.phase === 'end') console.log('Done:', e.file) })
|
|
9
10
|
* await recorder.start()
|
|
10
11
|
* ```
|
|
11
12
|
*/
|