@codearcade/subtitle-generator 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/init/index.js +67 -36
  2. package/package.json +1 -1
package/init/index.js CHANGED
@@ -92,49 +92,80 @@ const init = async () => {
92
92
  // Windows Setup
93
93
  const binaryDest = path.join(whisperDir, "whisper-cli.exe");
94
94
  if (!fs.existsSync(binaryDest)) {
95
- // Using latest pre-built x64 binaries from ggml-org
96
- const zipUrl =
97
- "https://github.com/ggerganov/whisper.cpp/releases/latest/download/whisper-bin-x64.zip";
95
+ console.log("Detecting Windows architecture...");
96
+ const arch = os.arch(); // Usually 'x64', 'ia32', or 'arm64'
97
+
98
+ let zipName;
99
+
100
+ if (arch === "x64") {
101
+ zipName = "whisper-bin-x64.zip";
102
+ } else if (arch === "ia32") {
103
+ zipName = "whisper-bin-Win32.zip";
104
+ } else if (arch === "arm64") {
105
+ // Windows ARM can emulate x64 executables
106
+ console.log(
107
+ "ARM64 architecture detected. Using x64 binary via Windows emulation...",
108
+ );
109
+ zipName = "whisper-bin-x64.zip";
110
+ } else {
111
+ throw new Error(
112
+ `Unsupported Windows architecture: ${arch}. Whisper.cpp does not provide pre-compiled binaries for this system.`,
113
+ );
114
+ }
115
+
116
+ // https://github.com/ggml-org/whisper.cpp/releases/download/v1.8.4/whisper-bin-Win32.zip
117
+ // https://github.com/ggml-org/whisper.cpp/releases/v1.8.4/download/whisper-bin-Win32.zip
118
+
119
+ const zipUrl = `https://github.com/ggml-org/whisper.cpp/releases/download/v1.8.4/${zipName}`;
98
120
  const zipPath = path.join(whisperDir, "whisper.zip");
99
121
 
100
- await downloadFile(zipUrl, zipPath, "Whisper Windows Binary");
122
+ await downloadFile(zipUrl, zipPath, `Whisper Windows Binary (${arch})`);
101
123
 
102
124
  console.log("Extracting binary...");
103
- // Windows 10+ has native tar for unzipping
104
- execSync(`tar -xf "${zipPath}" -C "${whisperDir}"`);
105
-
106
- // 1. Move everything out of the "Release" folder (or any other subfolder the zip might use)
107
- const possibleReleaseDir = path.join(whisperDir, "Release");
108
-
109
- if (fs.existsSync(possibleReleaseDir)) {
110
- // Read all files inside the Release folder
111
- const files = fs.readdirSync(possibleReleaseDir);
112
-
113
- // Move them up one level into the main whisperDir
114
- for (const file of files) {
115
- fs.renameSync(
116
- path.join(possibleReleaseDir, file),
117
- path.join(whisperDir, file),
118
- );
125
+
126
+ try {
127
+ // Use PowerShell instead of tar to avoid the Windows bsdtar decompression bug
128
+ execSync(
129
+ `powershell -command "Expand-Archive -Force -LiteralPath '${zipPath}' -DestinationPath '${whisperDir}'"`,
130
+ { stdio: "inherit" },
131
+ );
132
+
133
+ // 1. Move everything out of the "Release" folder
134
+ const possibleReleaseDir = path.join(whisperDir, "Release");
135
+
136
+ if (fs.existsSync(possibleReleaseDir)) {
137
+ const files = fs.readdirSync(possibleReleaseDir);
138
+
139
+ for (const file of files) {
140
+ fs.renameSync(
141
+ path.join(possibleReleaseDir, file),
142
+ path.join(whisperDir, file),
143
+ );
144
+ }
145
+ // Delete the now-empty Release folder
146
+ fs.rmdirSync(possibleReleaseDir);
119
147
  }
120
- // Delete the now-empty Release folder
121
- fs.rmdirSync(possibleReleaseDir);
122
- }
123
148
 
124
- // 2. Rename extracted main.exe to match our wrapper expectations
125
- const extractedMain = path.join(whisperDir, "main.exe");
126
- if (fs.existsSync(extractedMain)) {
127
- fs.renameSync(extractedMain, binaryDest);
128
- } else {
129
- console.error("Warning: Could not find main.exe after extraction.");
130
- }
149
+ // 2. Rename extracted main.exe to match our wrapper expectations
150
+ const extractedMain = path.join(whisperDir, "main.exe");
151
+ if (fs.existsSync(extractedMain)) {
152
+ fs.renameSync(extractedMain, binaryDest);
153
+ } else {
154
+ console.error("Warning: Could not find main.exe after extraction.");
155
+ }
131
156
 
132
- // 3. Clean up the zip file so it doesn't clutter the folder
133
- if (fs.existsSync(zipPath)) {
134
- fs.unlinkSync(zipPath);
135
- }
157
+ // 3. Clean up the zip file
158
+ if (fs.existsSync(zipPath)) {
159
+ fs.unlinkSync(zipPath);
160
+ }
136
161
 
137
- console.log("Whisper binary setup complete for Windows.");
162
+ console.log(`Whisper binary setup complete for Windows (${arch}).`);
163
+ } catch (error) {
164
+ console.error(
165
+ "Extraction failed. Please ensure PowerShell is available.",
166
+ error.message,
167
+ );
168
+ }
138
169
  } else {
139
170
  console.log("Whisper binary already exists for Windows.");
140
171
  }
@@ -151,7 +182,7 @@ const init = async () => {
151
182
  if (!fs.existsSync(repoDir)) {
152
183
  // Shallow clone to save time and bandwidth
153
184
  execSync(
154
- `git clone --depth 1 https://github.com/ggerganov/whisper.cpp.git "${repoDir}"`,
185
+ `git clone --depth 1 https://github.com/ggml-org/whisper.cpp.git "${repoDir}"`,
155
186
  { stdio: "inherit" },
156
187
  );
157
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codearcade/subtitle-generator",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",