image-video-optimizer 3.3.33 ā 3.4.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/.image-video-optimizer.conf +9 -4
- package/README.md +7 -2
- package/bin/cli.js +11 -6
- package/package.json +1 -1
- package/src/index.js +35 -7
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
# Image Video Optimizer Configuration
|
|
2
|
+
# Generated automatically
|
|
3
|
+
|
|
4
|
+
img_max_width=1080 # Maximum width for images (pixels)
|
|
5
|
+
img_format=jpg # Target format for image conversion
|
|
6
|
+
video_max_width=720 # Maximum width for videos (pixels)
|
|
7
|
+
video_encode=h264 # Video encoding format
|
|
8
|
+
audio_ext=mp3 # Audio extension for audio files
|
|
9
|
+
pdf_compress=true # Enable/disable PDF compression
|
package/README.md
CHANGED
|
@@ -25,7 +25,12 @@ npm install -g image-video-optimizer
|
|
|
25
25
|
### Basic Usage
|
|
26
26
|
|
|
27
27
|
```bash
|
|
28
|
-
image-video-optimizer
|
|
28
|
+
image-video-optimizer . # will proceed the current directory
|
|
29
|
+
image-video-optimizer /path/to/directory # will proceed the specified directory
|
|
30
|
+
image-video-optimizer /path/to/directory/file.jpg # will proceed the specified image file
|
|
31
|
+
image-video-optimizer /path/to/directory/file.pdf # will proceed the specified pdf file
|
|
32
|
+
image-video-optimizer /path/to/directory/file.mp4 # will proceed the specified video file
|
|
33
|
+
image-video-optimizer /path/to/directory/file.mp3 # will proceed the specified audio file
|
|
29
34
|
```
|
|
30
35
|
|
|
31
36
|
### Options
|
|
@@ -34,7 +39,7 @@ image-video-optimizer /path/to/directory
|
|
|
34
39
|
image-video-optimizer /path/to/directory [options]
|
|
35
40
|
```
|
|
36
41
|
|
|
37
|
-
- `<
|
|
42
|
+
- `<target>`: Target directory or file to optimize (required)
|
|
38
43
|
- `-r, --reset`: Reset status file and start fresh
|
|
39
44
|
- `-v, --verbose`: Enable verbose logging
|
|
40
45
|
- `-V, --version`: Show version number
|
package/bin/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { Command } = require('commander');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
5
6
|
const { optimize, resetStatus } = require('../src/index');
|
|
6
7
|
|
|
7
8
|
const program = new Command();
|
|
@@ -9,25 +10,29 @@ const program = new Command();
|
|
|
9
10
|
program
|
|
10
11
|
.name('image-video-optimizer')
|
|
11
12
|
.description('CLI tool to optimize and compress images, videos, audio, and PDFs')
|
|
12
|
-
.version('3.
|
|
13
|
+
.version('3.4.0');
|
|
13
14
|
|
|
14
15
|
program
|
|
15
|
-
.argument('[
|
|
16
|
+
.argument('[target]', 'Target directory or file to optimize', process.cwd())
|
|
16
17
|
.option('-r, --reset', 'Reset status file and start fresh')
|
|
17
18
|
.option('-v, --verbose', 'Show detailed processing information')
|
|
18
|
-
.action(async (
|
|
19
|
+
.action(async (target, options) => {
|
|
19
20
|
try {
|
|
20
|
-
const
|
|
21
|
+
const targetPath = path.resolve(target);
|
|
21
22
|
|
|
22
23
|
if (options.reset) {
|
|
24
|
+
// For reset, we need to determine if it's a file or directory
|
|
25
|
+
const targetDir = fs.existsSync(targetPath) && fs.statSync(targetPath).isDirectory()
|
|
26
|
+
? targetPath
|
|
27
|
+
: path.dirname(targetPath);
|
|
23
28
|
resetStatus(targetDir);
|
|
24
29
|
return;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
console.log('\nš Image Video Optimizer\n');
|
|
28
|
-
console.log('Target
|
|
33
|
+
console.log('Target: ' + targetPath);
|
|
29
34
|
|
|
30
|
-
await optimize(
|
|
35
|
+
await optimize(targetPath, options.verbose);
|
|
31
36
|
|
|
32
37
|
console.log('\nā
Optimization complete!\n');
|
|
33
38
|
} catch (error) {
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -178,15 +178,19 @@ function markFailed(filePath, error, status, targetDir) {
|
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
180
|
* Main optimization function
|
|
181
|
-
* @param {string}
|
|
181
|
+
* @param {string} targetPath - Target directory or file to optimize
|
|
182
182
|
* @param {boolean} verbose - Show detailed processing information
|
|
183
183
|
*/
|
|
184
|
-
async function optimize(
|
|
185
|
-
// Validate
|
|
186
|
-
if (!fs.existsSync(
|
|
187
|
-
throw new Error(`
|
|
184
|
+
async function optimize(targetPath, verbose = false) {
|
|
185
|
+
// Validate target exists
|
|
186
|
+
if (!fs.existsSync(targetPath)) {
|
|
187
|
+
throw new Error(`Target does not exist: ${targetPath}`);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
const stats = fs.statSync(targetPath);
|
|
191
|
+
const isFile = stats.isFile();
|
|
192
|
+
const targetDir = isFile ? path.dirname(targetPath) : targetPath;
|
|
193
|
+
|
|
190
194
|
// Ensure config file exists
|
|
191
195
|
ensureConfigFile(targetDir);
|
|
192
196
|
|
|
@@ -208,9 +212,33 @@ async function optimize(targetDir, verbose = false) {
|
|
|
208
212
|
}
|
|
209
213
|
console.log('');
|
|
210
214
|
|
|
211
|
-
// Search for media files
|
|
215
|
+
// Search for media files or process single file
|
|
212
216
|
console.log('š Searching for media files...');
|
|
213
|
-
|
|
217
|
+
|
|
218
|
+
let images = [], videos = [], audio = [], documents = [];
|
|
219
|
+
|
|
220
|
+
if (isFile) {
|
|
221
|
+
// Handle single file
|
|
222
|
+
const ext = path.extname(targetPath).toLowerCase().slice(1);
|
|
223
|
+
if (fileSearcher.SUPPORTED_IMAGES.includes(ext)) {
|
|
224
|
+
images = [targetPath];
|
|
225
|
+
} else if (fileSearcher.SUPPORTED_VIDEOS.includes(ext)) {
|
|
226
|
+
videos = [targetPath];
|
|
227
|
+
} else if (fileSearcher.SUPPORTED_AUDIO.includes(ext)) {
|
|
228
|
+
audio = [targetPath];
|
|
229
|
+
} else if (fileSearcher.SUPPORTED_DOCUMENTS.includes(ext)) {
|
|
230
|
+
documents = [targetPath];
|
|
231
|
+
} else {
|
|
232
|
+
throw new Error(`Unsupported file type: ${ext}`);
|
|
233
|
+
}
|
|
234
|
+
} else {
|
|
235
|
+
// Handle directory
|
|
236
|
+
const result = await fileSearcher.searchMediaFiles(targetDir, { verbose });
|
|
237
|
+
images = result.images;
|
|
238
|
+
videos = result.videos;
|
|
239
|
+
audio = result.audio;
|
|
240
|
+
documents = result.documents;
|
|
241
|
+
}
|
|
214
242
|
|
|
215
243
|
// Filter out already processed files
|
|
216
244
|
const pendingImages = images.filter(img => !isProcessed(img, status));
|