mediac 1.6.8 → 1.7.5
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/cmd/cmd_compress.js +23 -11
- package/cmd/cmd_ffmpeg.js +1109 -0
- package/cmd/cmd_prefix.js +2 -2
- package/cmd/cmd_remove.js +120 -70
- package/cmd/cmd_rename.js +57 -42
- package/cmd/cmd_shared.js +46 -2
- package/cmd/cmd_zipu.js +1 -1
- package/lib/core.js +171 -2
- package/lib/ffprobe.js +168 -0
- package/lib/file.js +33 -3
- package/lib/helper.js +125 -34
- package/package.json +15 -5
- package/scripts/media_cli.js +12 -8
- package/.vscode/settings.json +0 -3
- package/cmd/cmd_audiotag.js +0 -3
- package/labs/cjk_demo.js +0 -54
- package/labs/download_urls.js +0 -82
- package/labs/file_cli.js +0 -153
- package/labs/file_organize.js +0 -99
- package/labs/fs_demo.js +0 -17
- package/labs/gdh_gpt35.js +0 -95
- package/labs/gdh_gpt4.js +0 -94
- package/labs/git_date_header_001.js +0 -127
- package/labs/git_date_header_002.js +0 -88
- package/labs/make_thumbs.js +0 -157
- package/labs/merge_dir.js +0 -106
- package/labs/merge_dir_cli.js +0 -107
- package/labs/path_test.js +0 -14
- package/labs/pic_exif_rename.js +0 -131
- package/labs/print_unicode.js +0 -79
- package/labs/strftime.js +0 -84
- package/labs/string_format.js +0 -76
- package/labs/test.js +0 -55
- package/labs/unicode_test.js +0 -101
- package/labs/yargs_demo.js +0 -34
- package/labs/zip_test.js +0 -82
package/cmd/cmd_compress.js
CHANGED
|
@@ -18,6 +18,7 @@ import { cpus } from "os"
|
|
|
18
18
|
import pMap from 'p-map'
|
|
19
19
|
import path from "path"
|
|
20
20
|
import sharp from "sharp"
|
|
21
|
+
import * as core from '../lib/core.js'
|
|
21
22
|
import * as log from '../lib/debug.js'
|
|
22
23
|
import * as mf from '../lib/file.js'
|
|
23
24
|
import * as helper from '../lib/helper.js'
|
|
@@ -106,9 +107,9 @@ const handler = async function cmdCompress(argv) {
|
|
|
106
107
|
const walkOpts = {
|
|
107
108
|
needStats: true,
|
|
108
109
|
entryFilter: (f) =>
|
|
109
|
-
f.
|
|
110
|
+
f.isFile
|
|
110
111
|
&& !RE_THUMB.test(f.path)
|
|
111
|
-
&& f.
|
|
112
|
+
&& f.size > minFileSize
|
|
112
113
|
&& helper.isImageFile(f.path)
|
|
113
114
|
}
|
|
114
115
|
log.showGreen(logTag, `Walking files ...`)
|
|
@@ -176,7 +177,7 @@ const handler = async function cmdCompress(argv) {
|
|
|
176
177
|
})
|
|
177
178
|
log.show(logTag, `in ${helper.humanTime(startMs)} tasks:`)
|
|
178
179
|
tasks.slice(-1).forEach(t => {
|
|
179
|
-
log.show(
|
|
180
|
+
log.show(core.omit(t, "stats", "bar1"))
|
|
180
181
|
})
|
|
181
182
|
log.info(logTag, argv)
|
|
182
183
|
testMode && log.showYellow("++++++++++ TEST MODE (DRY RUN) ++++++++++")
|
|
@@ -267,11 +268,13 @@ async function preCompress(f, options = {}) {
|
|
|
267
268
|
const st = await fs.stat(fileSrc)
|
|
268
269
|
const m = await sharp(fileSrc).metadata()
|
|
269
270
|
try {
|
|
271
|
+
// 跳过以前由mediac压缩过的图片,避免重复压缩
|
|
272
|
+
// 可能需要添加一个命令行参数控制
|
|
270
273
|
if (m?.exif) {
|
|
271
274
|
const md = exif(m.exif)?.Image
|
|
272
|
-
if (md
|
|
275
|
+
if (md.Copyright?.includes("mediac")
|
|
273
276
|
|| md.Software?.includes("mediac")
|
|
274
|
-
|| md.Artist?.includes("mediac"))
|
|
277
|
+
|| md.Artist?.includes("mediac")) {
|
|
275
278
|
log.info(logTag, "skip:", fileDst)
|
|
276
279
|
return {
|
|
277
280
|
...f,
|
|
@@ -289,12 +292,7 @@ async function preCompress(f, options = {}) {
|
|
|
289
292
|
log.fileLog(`ExifErr: <${fileSrc}> ${error.message}`, logTag)
|
|
290
293
|
}
|
|
291
294
|
|
|
292
|
-
const
|
|
293
|
-
m.width > m.height ? maxWidth : Math.round((maxWidth * m.width) / m.height)
|
|
294
|
-
const newHeight = Math.round((newWidth * m.height) / m.width)
|
|
295
|
-
|
|
296
|
-
const dstWidth = newWidth > m.width ? m.width : newWidth
|
|
297
|
-
const dstHeight = newHeight > m.height ? m.height : newHeight
|
|
295
|
+
const { dstWidth, dstHeight } = calculateImageScale(m.width, m.height, maxWidth)
|
|
298
296
|
if (f.total < 1000 || f.index > f.total - 1000) {
|
|
299
297
|
log.show(logTag, `${f.index}/${f.total}`,
|
|
300
298
|
helper.pathShort(fileSrc),
|
|
@@ -358,4 +356,18 @@ async function purgeSrcFiles(results) {
|
|
|
358
356
|
const deleted = await pMap(toDelete, deletecFunc, { concurrency: cpus().length * 8 })
|
|
359
357
|
log.showCyan(logTag, `${deleted.filter(Boolean).length} files are safely removed`)
|
|
360
358
|
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// 给定图片长宽,给定长边数值,计算缩放后的长宽,只缩小不放大
|
|
362
|
+
function calculateImageScale(imgWidth, imgHeight, maxSide) {
|
|
363
|
+
// 不需要缩放的情况
|
|
364
|
+
if (imgWidth <= maxSide && imgHeight <= maxSide) {
|
|
365
|
+
return { dstWidth: imgWidth, dstHeight: imgHeight }
|
|
366
|
+
}
|
|
367
|
+
// 计算缩放比例
|
|
368
|
+
let scaleFactor = maxSide / Math.max(imgWidth, imgHeight)
|
|
369
|
+
// 计算新的长宽
|
|
370
|
+
let dstWidth = Math.round(imgWidth * scaleFactor)
|
|
371
|
+
let dstHeight = Math.round(imgHeight * scaleFactor)
|
|
372
|
+
return { dstWidth, dstHeight }
|
|
361
373
|
}
|