@codearcade/subtitle-generator 1.0.1 → 1.0.2
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/init/index.js +57 -39
- package/package.json +1 -1
package/init/index.js
CHANGED
|
@@ -113,9 +113,6 @@ const init = async () => {
|
|
|
113
113
|
);
|
|
114
114
|
}
|
|
115
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
116
|
const zipUrl = `https://github.com/ggml-org/whisper.cpp/releases/download/v1.8.4/${zipName}`;
|
|
120
117
|
const zipPath = path.join(whisperDir, "whisper.zip");
|
|
121
118
|
|
|
@@ -123,48 +120,69 @@ const init = async () => {
|
|
|
123
120
|
|
|
124
121
|
console.log("Extracting binary...");
|
|
125
122
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
123
|
+
let extractionSuccess = false;
|
|
124
|
+
let maxRetries = 5;
|
|
125
|
+
let retryDelay = 1000; // 1 second
|
|
126
|
+
|
|
127
|
+
// 1. The Retry Loop for safe extraction
|
|
128
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
129
|
+
try {
|
|
130
|
+
execSync(
|
|
131
|
+
`powershell -command "Expand-Archive -Force -LiteralPath '${zipPath}' -DestinationPath '${whisperDir}'"`,
|
|
132
|
+
{ stdio: "inherit" },
|
|
133
|
+
);
|
|
134
|
+
extractionSuccess = true;
|
|
135
|
+
break; // It worked! Break out of the loop.
|
|
136
|
+
} catch (error) {
|
|
137
|
+
if (attempt === maxRetries) {
|
|
138
|
+
console.error(
|
|
139
|
+
`\nExtraction failed after ${maxRetries} attempts. File might be permanently locked or corrupted.`,
|
|
143
140
|
);
|
|
141
|
+
throw error;
|
|
144
142
|
}
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
console.log(
|
|
144
|
+
`\nFile locked by Windows (likely Antivirus). Retrying in 1 second... (Attempt ${attempt} of ${maxRetries})`,
|
|
145
|
+
);
|
|
146
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
147
147
|
}
|
|
148
|
+
}
|
|
148
149
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
150
|
+
// 2. The Cleanup Phase (Only runs if extraction worked)
|
|
151
|
+
if (extractionSuccess) {
|
|
152
|
+
try {
|
|
153
|
+
// Move everything out of the "Release" folder
|
|
154
|
+
const possibleReleaseDir = path.join(whisperDir, "Release");
|
|
155
|
+
|
|
156
|
+
if (fs.existsSync(possibleReleaseDir)) {
|
|
157
|
+
const files = fs.readdirSync(possibleReleaseDir);
|
|
158
|
+
|
|
159
|
+
for (const file of files) {
|
|
160
|
+
fs.renameSync(
|
|
161
|
+
path.join(possibleReleaseDir, file),
|
|
162
|
+
path.join(whisperDir, file),
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
// Delete the now-empty Release folder
|
|
166
|
+
fs.rmdirSync(possibleReleaseDir);
|
|
167
|
+
}
|
|
156
168
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
fs.
|
|
160
|
-
|
|
169
|
+
// Rename extracted main.exe to match our wrapper expectations
|
|
170
|
+
const extractedMain = path.join(whisperDir, "main.exe");
|
|
171
|
+
if (fs.existsSync(extractedMain)) {
|
|
172
|
+
fs.renameSync(extractedMain, binaryDest);
|
|
173
|
+
} else {
|
|
174
|
+
console.error("Warning: Could not find main.exe after extraction.");
|
|
175
|
+
}
|
|
161
176
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
// Clean up the zip file
|
|
178
|
+
if (fs.existsSync(zipPath)) {
|
|
179
|
+
fs.unlinkSync(zipPath);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
console.log(`Whisper binary setup complete for Windows (${arch}).`);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
console.error("Error during binary cleanup/renaming:", error.message);
|
|
185
|
+
}
|
|
168
186
|
}
|
|
169
187
|
} else {
|
|
170
188
|
console.log("Whisper binary already exists for Windows.");
|