mediasnacks 0.29.0 → 0.30.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.
package/README.md CHANGED
@@ -22,6 +22,7 @@ mediasnacks <command> <args>
22
22
  - `avif` Converts images to AVIF
23
23
  - `png` Optimizes PNG images with oxipng
24
24
  - `sqcrop` Square crops images
25
+ - `base64` Encodes image to data URI
25
26
 
26
27
 
27
28
  - `resize` Resizes videos or images
package/index.js CHANGED
@@ -20,3 +20,4 @@ export { ssim } from './src/ssim.js'
20
20
  export { unemoji } from './src/unemoji.js'
21
21
  export { vsplit } from './src/vsplit.js'
22
22
  export { vtrim } from './src/vtrim.js'
23
+ export { base64 } from './src/base64.js'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediasnacks",
3
- "version": "0.29.0",
3
+ "version": "0.30.1",
4
4
  "description": "Utilities for optimizing and preparing videos and images",
5
5
  "license": "MIT",
6
6
  "author": "Eric Fortis",
package/src/base64.js ADDED
@@ -0,0 +1,53 @@
1
+ import { parse } from 'node:path'
2
+ import { readFileSync } from 'node:fs'
3
+ import { parseOptions } from './utils/parseOptions.js'
4
+
5
+
6
+ const HELP = `
7
+ SYNOPSIS
8
+ mediasnacks base64 [--css | --img] img
9
+
10
+ DESCRIPTION
11
+ Encodes image to data URI
12
+
13
+ EXAMPLES
14
+ mediasnacks base64 img
15
+ mediasnacks base64 --img img
16
+ mediasnacks base64 --css img
17
+ `
18
+
19
+ const MIMES = {
20
+ avif: 'image/avif',
21
+ gif: 'image/gif',
22
+ jpg: 'image/jpeg',
23
+ jpeg: 'image/jpeg',
24
+ png: 'image/png',
25
+ svg: 'image/svg+xml',
26
+ webp: 'image/webp',
27
+ }
28
+
29
+ export default async function main() {
30
+ const { values, files } = await parseOptions(HELP, {
31
+ css: { type: 'boolean' },
32
+ img: { type: 'boolean' },
33
+ })
34
+
35
+ if (files.length !== 1)
36
+ throw 'Only one file is accepted'
37
+
38
+ const { data, mime } = await base64(files[0])
39
+
40
+ if (values.css)
41
+ console.log(`background-image: url(data:${mime};base64,${data})`)
42
+ else if (values.img)
43
+ console.log(`<img src="data:${mime};base64,${data}" />`)
44
+ else
45
+ console.log(data)
46
+ }
47
+
48
+ export async function base64(file) {
49
+ return {
50
+ data: readFileSync(file).toString('base64'),
51
+ mime: MIMES[parse(file).ext.toLowerCase().replace('.', '')] || 'application/octect'
52
+ }
53
+ }
package/src/cli.js CHANGED
@@ -9,7 +9,8 @@ import pkgJSON from '../package.json' with { type: 'json' }
9
9
  const COMMANDS = {
10
10
  avif: ['./avif.js', 'Converts images to AVIF'],
11
11
  png: ['./png.js', 'Optimizes PNG images with oxipng'],
12
- sqcrop: ['./sqcrop.js', 'Square crops images\n'],
12
+ sqcrop: ['./sqcrop.js', 'Square crops images'],
13
+ base64: ['./base64.js', 'Encodes a file to data URI\n'],
13
14
 
14
15
  resize: ['./resize.js', 'Resizes videos or images'],
15
16
  edgespic: ['./edgespic.js', 'Extracts first and last frames'],
package/src/moov2front.js CHANGED
@@ -9,13 +9,11 @@ SYNOPSIS
9
9
 
10
10
  DESCRIPTION
11
11
  Rearranges .mov and .mp4 metadata to the start of the file for fast-start streaming.
12
-
13
- What is Fast Start?
14
- - https://wiki.avblocks.com/avblocks-for-cpp/muxer-parameters/mp4
15
- - https://trac.ffmpeg.org/wiki/HowToCheckIfFaststartIsEnabledForPlayback
16
-
17
- NOTES
18
12
  Files are overwritten.
13
+
14
+ SEE ALSO
15
+ - https://wiki.avblocks.com/avblocks-for-cpp/muxer-parameters/mp4
16
+ - https://trac.ffmpeg.org/wiki/HowToCheckIfFaststartIsEnabledForPlayback
19
17
  `
20
18
 
21
19
  export default async function main() {
package/src/play.sh ADDED
@@ -0,0 +1,10 @@
1
+ #!/bin/sh
2
+
3
+ # mpv with a filtered playlist with recursive search
4
+ # usage: cd Music && play artistA artistB
5
+
6
+ regex=$(IFS='|'; echo "$*")
7
+ /usr/bin/find -E . -type f -iregex ".*(${regex}).*" \
8
+ -not -path "*.fcpbundle/*" \
9
+ -not -name ".DS_Store" \
10
+ -print | mpv --playlist=-
package/src/qdir.js CHANGED
@@ -68,8 +68,8 @@ export async function qdir(dir, pollIntervalMs = 10_000) {
68
68
  async function getNextJob(dir) {
69
69
  const entries = await readdir(dir, { withFileTypes: true })
70
70
  const scripts = entries
71
- .filter(entry => entry.isFile() && filter(entry.name))
72
- .map(entry => entry.name)
71
+ .filter(dirent => dirent.isFile() && filter(dirent.name))
72
+ .map(dirent => dirent.name)
73
73
  .sort()
74
74
  return scripts.length
75
75
  ? join(dir, scripts[0])
@@ -81,7 +81,7 @@ async function runShell(scriptPath) {
81
81
  return new Promise((resolve, reject) => {
82
82
  const p = spawn('/bin/sh', [scriptPath], { stdio: 'inherit' })
83
83
  p.on('error', reject)
84
- p.on('exit', code => resolve(code))
84
+ p.on('exit', resolve)
85
85
  })
86
86
  }
87
87