mediasnacks 0.32.4 → 0.33.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
@@ -32,6 +32,7 @@ mediasnacks <command> <args>
32
32
  - `ssim` Computes similarity of two images
33
33
  - `gif`: Video to GIF
34
34
  - `info`: Prints video attributes
35
+ - `tag`: Sets color tag for Finder
35
36
 
36
37
 
37
38
  - `detectdups` Detects sequentially duplicate frames in a video
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediasnacks",
3
- "version": "0.32.4",
3
+ "version": "0.33.1",
4
4
  "description": "Utilities for optimizing and preparing videos and images",
5
5
  "license": "MIT",
6
6
  "author": "Eric Fortis",
package/src/cli.js CHANGED
@@ -18,7 +18,8 @@ const COMMANDS = {
18
18
  countframes: ['./countframes.js', 'Counts frames in a video'],
19
19
  ssim: ['./ssim.js', 'Computes SSIM between two images'],
20
20
  gif: ['./gif.js', 'Video to GIF'],
21
- info: ['./info.js', 'Prints video stream attributes\n'],
21
+ info: ['./info.js', 'Prints video stream attributes'],
22
+ tag: ['./tag.osascript', 'Sets color tag for Finder\n'],
22
23
 
23
24
  detectdups: ['./detectdups.js', 'Detects duplicate frames in a video'],
24
25
  dropdups: ['./dropdups.js', 'Removes duplicate frames in a video'],
package/src/dlaudio.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { parseOptions } from './utils/parseOptions.js'
2
- import { runSilently } from './utils/subprocess.js'
3
- import { unemoji } from './unemoji.js'
2
+ import { run } from './utils/subprocess.js'
4
3
 
5
4
 
6
5
  const HELP = `
@@ -17,18 +16,14 @@ export default async function main() {
17
16
  if (!positionals[0])
18
17
  throw usage('Missing URL')
19
18
 
20
- const f = await dlaudio(positionals[0])
21
- console.log(f)
19
+ await dlaudio(positionals[0])
22
20
  }
23
21
 
24
22
  export async function dlaudio(url) {
25
- const f = (await runSilently('yt-dlp', [
26
- '--print', 'filename',
23
+ await run('yt-dlp', [
27
24
  '--no-simulate',
28
25
  '-o', '%(title)s.%(ext)s',
29
26
  '-f', 'bestaudio[ext=m4a]/bestaudio',
30
27
  url
31
- ])).stdout.trim()
32
-
33
- return await unemoji(f) || f
28
+ ])
34
29
  }
package/src/info.js CHANGED
@@ -26,11 +26,17 @@ EXAMPLES
26
26
  DIR=\${FPS}fps
27
27
  mkdir -p \$DIR
28
28
  mediasnacks info *.* |
29
- grep \${FPS}fps |
30
- awk -F\\t '{print $NF}' |
29
+ awk "\\$3==\\"\${FPS}fps\\" { print \\$NF }" |
31
30
  while read -r f; do
32
31
  mv -- "$f" \$DIR/
33
32
  done
33
+
34
+ Tag with "red" (in macOS Finder) 1080 videos:
35
+ COLOR=red
36
+ HEIGHT=1080
37
+ mediasnacks info *.mov |
38
+ awk "\\$2==\$HEIGHT { print \\$NF }" |
39
+ xargs -I{} mediasnacks tag $COLOR "{}"
34
40
  `
35
41
 
36
42
  export default async function main() {
package/src/play.js CHANGED
@@ -15,7 +15,6 @@ EXAMPLE
15
15
  mediasnacks play artistX artistY
16
16
  `
17
17
 
18
-
19
18
  export default async function main() {
20
19
  const { values, positionals, usage } = await parseOptions(HELP, {
21
20
  recursive: { short: 'r', type: 'boolean', default: true },
package/src/seqcheck.js CHANGED
@@ -13,8 +13,8 @@ DESCRIPTION
13
13
  Find missing numbered files in a sequence.
14
14
 
15
15
  OPTIONS
16
- -ld, --left-delimiter <str> Delimiter before the number (default: "${LEFT_DELIM}")
17
- -rd, --right-delimiter <str> Delimiter after the number (default: "${RIGHT_DELIM}")
16
+ --left-delimiter <str> Char before the number (default: "${LEFT_DELIM}")
17
+ --right-delimiter <str> Char after the number (default: "${RIGHT_DELIM}")
18
18
  `
19
19
 
20
20
  export default async function main() {
@@ -35,7 +35,7 @@ export function seqcheck(dir, leftDelim = LEFT_DELIM, rightDelim = RIGHT_DELIM)
35
35
  }
36
36
 
37
37
  export function extractSeqNums(names, leftDelim, rightDelim) {
38
- const pattern = new RegExp(escapeRegex(leftDelim) + '(\\d+)' + escapeRegex(rightDelim))
38
+ const pattern = new RegExp(RegExp.escape(leftDelim) + '(\\d+)' + RegExp.escape(rightDelim))
39
39
  const seq = []
40
40
  for (const name of names) {
41
41
  const match = name.match(pattern)
@@ -54,7 +54,3 @@ export function findMissingNumbers(seq) {
54
54
  missing.push(i)
55
55
  return missing
56
56
  }
57
-
58
- function escapeRegex(str) {
59
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
60
- }
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/osascript
2
+
3
+ property colorNames : {"none", "orange", "red", "yellow", "blue", "purple", "green", "gray"}
4
+
5
+ on usage()
6
+ log "USAGE: mediasnacks tag <color> <file>"
7
+ set AppleScript's text item delimiters to " "
8
+ set colorList to colorNames as text
9
+ set AppleScript's text item delimiters to ""
10
+ log "COLORS: " & colorList
11
+ end usage
12
+
13
+ on labelNumForColor(theItem)
14
+ repeat with i from 1 to count of colorNames
15
+ if item i of colorNames as text is theItem as text then
16
+ return i - 1
17
+ end if
18
+ end repeat
19
+ return -1
20
+ end labelNumForColor
21
+
22
+ on run argv
23
+ if (count of argv) < 2 then
24
+ usage()
25
+ return
26
+ end if
27
+ set tagColor to item 1 of argv
28
+ set filePath to item 2 of argv
29
+
30
+ set labelNum to labelNumForColor(tagColor)
31
+ if labelNum is -1 then
32
+ log "invalid color: " & tagColor
33
+ usage()
34
+ return
35
+ end if
36
+
37
+ set theFile to POSIX file filePath as alias
38
+ tell application "Finder"
39
+ set label index of theFile to labelNum
40
+ end tell
41
+ return
42
+ end run
package/src/unemoji.js CHANGED
@@ -44,7 +44,7 @@ export default async function main() {
44
44
 
45
45
  for (const file of files) {
46
46
  const newpath = await unemoji(file)
47
- if (newpath)
47
+ if (newpath !== file)
48
48
  console.log(`Renaming: ${file} -> ${newpath}`)
49
49
  }
50
50
  }
@@ -57,10 +57,11 @@ export async function unemoji(file) {
57
57
  .replace(/\s+/g, ' ')
58
58
  .replace(/\s+\./g, '.')
59
59
  .trim()
60
+ const newpath = join(dir, newbase)
61
+
60
62
  if (base === newbase)
61
- return null
63
+ return newpath
62
64
 
63
- const newpath = join(dir, newbase)
64
65
  if (existsSync(newpath))
65
66
  throw `Skipping (exists): ${file} -> ${newpath}`
66
67
 
@@ -1,8 +1,8 @@
1
1
  import { formatSeconds } from './formatSeconds.js'
2
2
 
3
- const HIDE_CURSOR = '\x1b[?25l'
4
- const SHOW_CURSOR = '\x1b[?25h'
5
- const ERASE_TO_END = '\x1b[K'
3
+ export const HIDE_CURSOR = '\x1b[?25l'
4
+ export const SHOW_CURSOR = '\x1b[?25h'
5
+ export const ERASE_TO_END = '\x1b[K'
6
6
 
7
7
  export const showCursor = () => process.stdout.write(SHOW_CURSOR)
8
8
 
@@ -30,5 +30,5 @@ function progressBar(progress, width = 44) {
30
30
 
31
31
  const partials = ' ▏▎▍▌▋▊▉'
32
32
  const partial = partials.at(partials.length * fPartial)
33
- return '█'.repeat(nFull) + partial + ''.repeat(nRemaining)
33
+ return '█'.repeat(nFull) + partial + ''.repeat(nRemaining)
34
34
  }