@drakulavich/parakeet-cli 0.7.2 → 0.7.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/package.json +1 -1
- package/src/__tests__/audio.test.ts +36 -0
- package/src/audio.ts +32 -2
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, test, expect } from "bun:test";
|
|
2
|
+
import { getFfmpegInstallHint, assertFfmpegExists, resetFfmpegCheck } from "../audio";
|
|
3
|
+
|
|
4
|
+
describe("getFfmpegInstallHint", () => {
|
|
5
|
+
test("returns a non-empty string", () => {
|
|
6
|
+
const hint = getFfmpegInstallHint();
|
|
7
|
+
expect(hint).toBeTruthy();
|
|
8
|
+
expect(typeof hint).toBe("string");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("contains install keyword", () => {
|
|
12
|
+
const hint = getFfmpegInstallHint();
|
|
13
|
+
expect(hint).toMatch(/install|ffmpeg\.org/i);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe("assertFfmpegExists", () => {
|
|
18
|
+
test("includes install hint when ffmpeg is missing", () => {
|
|
19
|
+
// Save and override Bun.which to simulate missing ffmpeg
|
|
20
|
+
const originalWhich = Bun.which;
|
|
21
|
+
Bun.which = ((cmd: string) => {
|
|
22
|
+
if (cmd === "ffmpeg") return null;
|
|
23
|
+
return originalWhich(cmd);
|
|
24
|
+
}) as typeof Bun.which;
|
|
25
|
+
|
|
26
|
+
// Reset the cached check so assertFfmpegExists re-checks
|
|
27
|
+
resetFfmpegCheck();
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
expect(() => assertFfmpegExists()).toThrow(/Install it:/);
|
|
31
|
+
} finally {
|
|
32
|
+
Bun.which = originalWhich;
|
|
33
|
+
resetFfmpegCheck();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
package/src/audio.ts
CHANGED
|
@@ -61,10 +61,40 @@ async function convertAudioWithFfmpeg(
|
|
|
61
61
|
return tmpPath;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
function
|
|
64
|
+
export function getFfmpegInstallHint(): string {
|
|
65
|
+
const platform = process.platform;
|
|
66
|
+
|
|
67
|
+
if (platform === "darwin") {
|
|
68
|
+
if (Bun.which("brew")) return " brew install ffmpeg";
|
|
69
|
+
if (Bun.which("port")) return " sudo port install ffmpeg";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (platform === "linux") {
|
|
73
|
+
if (Bun.which("apt")) return " sudo apt install ffmpeg";
|
|
74
|
+
if (Bun.which("dnf")) return " sudo dnf install ffmpeg-free";
|
|
75
|
+
if (Bun.which("pacman")) return " sudo pacman -S ffmpeg";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (platform === "win32") {
|
|
79
|
+
if (Bun.which("choco")) return " choco install ffmpeg";
|
|
80
|
+
if (Bun.which("scoop")) return " scoop install ffmpeg";
|
|
81
|
+
if (Bun.which("winget")) return " winget install ffmpeg";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return " https://ffmpeg.org/download.html";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function assertFfmpegExists(): void {
|
|
65
88
|
if (ffmpegChecked) return;
|
|
66
89
|
if (!Bun.which("ffmpeg")) {
|
|
67
|
-
|
|
90
|
+
const hint = getFfmpegInstallHint();
|
|
91
|
+
throw new Error(
|
|
92
|
+
`ffmpeg is required but not found in PATH.\n\nInstall it:\n${hint}`
|
|
93
|
+
);
|
|
68
94
|
}
|
|
69
95
|
ffmpegChecked = true;
|
|
70
96
|
}
|
|
97
|
+
|
|
98
|
+
export function resetFfmpegCheck(): void {
|
|
99
|
+
ffmpegChecked = false;
|
|
100
|
+
}
|