-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfingerprint_examples.py
More file actions
57 lines (45 loc) · 1.66 KB
/
fingerprint_examples.py
File metadata and controls
57 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Example script to run ``fpcalc`` on a list of audio files.
Invoke as ``python fingerprint_examples.py <files>``. Glob patterns are
allowed. On Windows, paths with a ``\\?\\`` prefix are handled correctly.
"""
import argparse
import glob
import subprocess
from pathlib import Path
from typing import Iterable
from utils.path_helpers import strip_ext_prefix
def expand_files(inputs: Iterable[str]) -> list[str]:
"""Return file paths from ``inputs`` with basic glob expansion."""
paths: list[str] = []
for raw in inputs:
matches = glob.glob(raw)
if matches:
paths.extend(matches)
else:
paths.append(raw)
return paths
def main(argv: list[str] | None = None) -> None:
parser = argparse.ArgumentParser(description="Run fpcalc on files")
parser.add_argument("files", nargs="+", help="Audio files or glob patterns")
args = parser.parse_args(argv)
files = expand_files(args.files)
for path_str in files:
safe_path = strip_ext_prefix(path_str)
if not Path(safe_path).exists():
print(f"Missing: {safe_path}")
continue
cmd = ["fpcalc", "-json", safe_path]
try:
proc = subprocess.run(cmd, capture_output=True, text=True, check=True)
except FileNotFoundError:
print("❌ fpcalc not found on PATH.")
break
except subprocess.CalledProcessError as e:
print(f"❌ fpcalc failed for {safe_path!r}:")
print(e.stderr.strip())
continue
print(f"✅ {Path(safe_path).name}:")
print(proc.stdout.strip())
print("-" * 40)
if __name__ == "__main__":
main()