@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.
Files changed (2) hide show
  1. package/init/index.js +57 -39
  2. 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
- 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),
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
- // Delete the now-empty Release folder
146
- fs.rmdirSync(possibleReleaseDir);
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
- // 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
- }
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
- // 3. Clean up the zip file
158
- if (fs.existsSync(zipPath)) {
159
- fs.unlinkSync(zipPath);
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
- 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
- );
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.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codearcade/subtitle-generator",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",