@zfadhli/tokrec 0.15.0 → 0.16.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/README.md +126 -0
- package/dist/app/config.mjs.map +1 -1
- package/dist/app/job.mjs +39 -17
- package/dist/app/job.mjs.map +1 -1
- package/dist/app/logger.mjs +8 -16
- package/dist/app/logger.mjs.map +1 -1
- package/dist/app/loop.mjs +6 -3
- package/dist/app/loop.mjs.map +1 -1
- package/dist/app/recorder.d.mts.map +1 -1
- package/dist/app/recorder.mjs +25 -29
- package/dist/app/recorder.mjs.map +1 -1
- package/dist/core/plan.mjs.map +1 -1
- package/dist/core/verdict.d.mts +1 -1
- package/dist/core/verdict.mjs.map +1 -1
- package/dist/io/http.mjs +16 -24
- package/dist/io/http.mjs.map +1 -1
- package/dist/io/media/download.mjs +1 -1
- package/dist/io/media/ffmpeg.mjs +52 -6
- package/dist/io/media/ffmpeg.mjs.map +1 -1
- package/dist/io/tiktok/client.mjs +9 -12
- package/dist/io/tiktok/client.mjs.map +1 -1
- package/dist/io/tiktok/discovery/chain.mjs +14 -17
- package/dist/io/tiktok/discovery/chain.mjs.map +1 -1
- package/dist/io/tiktok/discovery/page.mjs +38 -52
- package/dist/io/tiktok/discovery/page.mjs.map +1 -1
- package/dist/io/tiktok/parse.mjs +24 -31
- package/dist/io/tiktok/parse.mjs.map +1 -1
- package/dist/io/tiktok/webcast.mjs +15 -29
- package/dist/io/tiktok/webcast.mjs.map +1 -1
- package/package.json +1 -1
- package/src/app/config.ts +5 -19
- package/src/app/job.ts +61 -27
- package/src/app/logger.ts +9 -23
- package/src/app/loop.ts +12 -11
- package/src/app/recorder.ts +44 -47
- package/src/core/plan.ts +1 -1
- package/src/core/verdict.ts +1 -1
- package/src/index.ts +1 -1
- package/src/io/http.ts +24 -49
- package/src/io/media/ffmpeg.ts +65 -7
- package/src/io/tiktok/client.ts +13 -24
- package/src/io/tiktok/discovery/chain.ts +15 -24
- package/src/io/tiktok/discovery/page.ts +51 -90
- package/src/io/tiktok/parse.ts +38 -48
- package/src/io/tiktok/webcast.ts +30 -41
- package/dist/app/abort.mjs +0 -14
- package/dist/app/abort.mjs.map +0 -1
- package/dist/app/events.mjs +0 -36
- package/dist/app/events.mjs.map +0 -1
- package/dist/io/media/convert.mjs +0 -60
- package/dist/io/media/convert.mjs.map +0 -1
- package/dist/io/media/normalize.mjs +0 -32
- package/dist/io/media/normalize.mjs.map +0 -1
- package/src/app/abort.ts +0 -18
- package/src/app/events.ts +0 -46
- package/src/io/media/convert.ts +0 -69
- package/src/io/media/normalize.ts +0 -64
package/src/app/events.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typed emitter over `node:events` — the four-channel recorder contract
|
|
3
|
-
* (`verdict`, `record`, `progress`, `failure`) with no listener bookkeeping of
|
|
4
|
-
* our own. `emit` swallows handler throws: a bad subscriber must not kill a
|
|
5
|
-
* recording.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { EventEmitter } from "node:events"
|
|
9
|
-
import type { RecorderEvent, RecorderEventHandler } from "./config"
|
|
10
|
-
|
|
11
|
-
export interface RecorderEventEmitter {
|
|
12
|
-
on<E extends RecorderEvent>(event: E, handler: RecorderEventHandler[E]): void
|
|
13
|
-
off<E extends RecorderEvent>(event: E, handler: RecorderEventHandler[E]): void
|
|
14
|
-
emit<E extends RecorderEvent>(event: E, ...args: Parameters<RecorderEventHandler[E]>): void
|
|
15
|
-
clear(): void
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function createEventEmitter(): RecorderEventEmitter {
|
|
19
|
-
const emitter = new EventEmitter()
|
|
20
|
-
const asListener = (handler: unknown) => handler as (...args: unknown[]) => void
|
|
21
|
-
|
|
22
|
-
function on<E extends RecorderEvent>(event: E, handler: RecorderEventHandler[E]): void {
|
|
23
|
-
emitter.on(event, asListener(handler))
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function off<E extends RecorderEvent>(event: E, handler: RecorderEventHandler[E]): void {
|
|
27
|
-
emitter.off(event, asListener(handler))
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function emit<E extends RecorderEvent>(
|
|
31
|
-
event: E,
|
|
32
|
-
...args: Parameters<RecorderEventHandler[E]>
|
|
33
|
-
): void {
|
|
34
|
-
try {
|
|
35
|
-
emitter.emit(event, ...args)
|
|
36
|
-
} catch {
|
|
37
|
-
// Never let an event handler crash the recorder.
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function clear(): void {
|
|
42
|
-
emitter.removeAllListeners()
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return { on, off, emit, clear }
|
|
46
|
-
}
|
package/src/io/media/convert.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converter — the media-processing capability `RecordingJob` depends on.
|
|
3
|
-
*
|
|
4
|
-
* Remux (TS → MP4) and segment both delegate to `ffmpeg-utils.runFfmpeg`, so
|
|
5
|
-
* the job never builds an FFmpeg command line.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { unlinkSync } from "node:fs"
|
|
9
|
-
import type { Logger } from "../../core/log"
|
|
10
|
-
import { runFfmpeg } from "./ffmpeg"
|
|
11
|
-
|
|
12
|
-
export interface Converter {
|
|
13
|
-
/** Convert a TS file to MP4 (stream copy). Deletes the original on success. */
|
|
14
|
-
convert: (input: string) => Promise<string>
|
|
15
|
-
/** Split a file into `<name>_partN.mp4`; returns FFmpeg's CSV segment listing. */
|
|
16
|
-
segment: (input: string, segmentSeconds: number, outputPattern: string) => Promise<string>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function createConverter(logger?: Logger, signal?: AbortSignal): Converter {
|
|
20
|
-
async function convert(input: string): Promise<string> {
|
|
21
|
-
const output = input.replace(/\.(flv|ts)$/i, ".mp4")
|
|
22
|
-
|
|
23
|
-
logger?.info(`Converting: ${input} → ${output}`)
|
|
24
|
-
|
|
25
|
-
await runFfmpeg(["-i", input, "-c", "copy", "-y", output], signal)
|
|
26
|
-
|
|
27
|
-
// Delete original TS
|
|
28
|
-
try {
|
|
29
|
-
unlinkSync(input)
|
|
30
|
-
logger?.info(`Deleted original: ${input}`)
|
|
31
|
-
} catch {
|
|
32
|
-
logger?.warn(`Could not delete original: ${input}`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
logger?.info(`Converted: ${output}`)
|
|
36
|
-
return output
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function segment(
|
|
40
|
-
input: string,
|
|
41
|
-
segmentSeconds: number,
|
|
42
|
-
outputPattern: string,
|
|
43
|
-
): Promise<string> {
|
|
44
|
-
return runFfmpeg(
|
|
45
|
-
[
|
|
46
|
-
"-i",
|
|
47
|
-
input,
|
|
48
|
-
"-c",
|
|
49
|
-
"copy",
|
|
50
|
-
"-f",
|
|
51
|
-
"segment",
|
|
52
|
-
"-segment_time",
|
|
53
|
-
String(segmentSeconds),
|
|
54
|
-
"-reset_timestamps",
|
|
55
|
-
"1",
|
|
56
|
-
"-segment_start_number",
|
|
57
|
-
"1",
|
|
58
|
-
"-segment_list",
|
|
59
|
-
"pipe:1",
|
|
60
|
-
"-segment_list_type",
|
|
61
|
-
"csv",
|
|
62
|
-
outputPattern,
|
|
63
|
-
],
|
|
64
|
-
signal,
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return { convert, segment }
|
|
69
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Audio normalizer — wraps peaknorm's EBU R128 loudness normalization.
|
|
3
|
-
* Runs after conversion/segmenting to normalize the final MP4 audio.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { NormalizeOptions, NormalizeResult } from "peaknorm"
|
|
7
|
-
import { normalizeFile } from "peaknorm"
|
|
8
|
-
import type { Logger } from "../../core/log"
|
|
9
|
-
|
|
10
|
-
export interface AudioNormalizer {
|
|
11
|
-
/** Normalize a single audio/video file. Returns the normalize result. */
|
|
12
|
-
normalize(file: string): Promise<NormalizeResult>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface AudioNormalizerOptions {
|
|
16
|
-
/** Target loudness in LUFS (default: -14). */
|
|
17
|
-
loudness: number
|
|
18
|
-
/** Audio codec for output (default: peaknorm's default, "libopus"). */
|
|
19
|
-
audioCodec?: string
|
|
20
|
-
/** Audio bitrate for output (default: peaknorm's default, "96k"). */
|
|
21
|
-
audioBitrate?: string
|
|
22
|
-
/** Called when a file starts normalization. */
|
|
23
|
-
onStart?: (file: string) => void
|
|
24
|
-
/** Called with progress updates (percent 0-100, phase "analyzing"|"normalizing"). */
|
|
25
|
-
onProgress?: (file: string, percent: number, phase: string) => void
|
|
26
|
-
/** Called when a file completes normalization successfully. */
|
|
27
|
-
onComplete?: (result: NormalizeResult) => void
|
|
28
|
-
/** Called when a file errors during normalization. */
|
|
29
|
-
onError?: (file: string, error: Error) => void
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function createAudioNormalizer(
|
|
33
|
-
opts: AudioNormalizerOptions,
|
|
34
|
-
logger?: Logger,
|
|
35
|
-
): AudioNormalizer {
|
|
36
|
-
return {
|
|
37
|
-
async normalize(file: string): Promise<NormalizeResult> {
|
|
38
|
-
logger?.info(`Normalizing audio: ${file}`)
|
|
39
|
-
opts.onStart?.(file)
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const normalizeOpts: NormalizeOptions = {
|
|
43
|
-
loudness: opts.loudness,
|
|
44
|
-
backup: false,
|
|
45
|
-
onFileProgress: (f, percent, phase) => {
|
|
46
|
-
opts.onProgress?.(f, percent, phase)
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
if (opts.audioCodec !== undefined) normalizeOpts.audioCodec = opts.audioCodec
|
|
50
|
-
if (opts.audioBitrate !== undefined) normalizeOpts.audioBitrate = opts.audioBitrate
|
|
51
|
-
const result = await normalizeFile(file, normalizeOpts)
|
|
52
|
-
|
|
53
|
-
logger?.info(`Audio normalized: ${result.output}`)
|
|
54
|
-
opts.onComplete?.(result)
|
|
55
|
-
return result
|
|
56
|
-
} catch (err) {
|
|
57
|
-
const error = err instanceof Error ? err : new Error(String(err))
|
|
58
|
-
logger?.error(`Audio normalization failed: ${error.message}`)
|
|
59
|
-
opts.onError?.(file, error)
|
|
60
|
-
throw error
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
}
|