-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-music-extensions
executable file
·60 lines (47 loc) · 1.57 KB
/
check-music-extensions
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
58
59
60
#!/usr/bin/env python3
"""
Check if all my music files are mp3's. If they're not, warn me
This is mostly so that I can sweep across my music directory, looking for
items without album art so my music players which hopefully use APIC frames can
pull the album art
This uses my list-music script:
https://purarue.xyz/d/list-music?dark
"""
import os
import sys
import subprocess
from pathlib import Path
from typing import Iterator
import click
def list_music() -> Iterator[Path]:
"""
Lists files in the system music directory
Excludes common files that are found in ablums, but
are *not* audio files from the 'fd' result,
so that any new/unexpected music types are shown
https://purarue.xyz/d/list-music?dark
"""
os.chdir(os.environ["XDG_MUSIC_DIR"])
proc = subprocess.run(
"list-music",
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
proc.check_returncode()
assert proc.stderr.strip() == "", proc.stderr
yield from map(Path, proc.stdout.strip().splitlines())
def filter_extension(src: Iterator[Path], ext: str = ".mp3") -> list[Path]:
"""
Remove any Path from src where 'ext' doesn't match
"""
return list(filter(lambda p: p.suffix != ext, src))
@click.command(help=__doc__)
def main() -> None:
if non_mp3 := filter_extension(list_music()):
click.secho("Found some non-mp3 files:", fg="red", err=True)
click.echo("\n".join(list(map(str, non_mp3))))
sys.exit(2)
sys.exit(0)
if __name__ == "__main__":
main(prog_name="check-music-extensions")