tools: Add a script for finding what files are missing a tag
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
0fc49912ed
commit
89b40ab905
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/python
|
||||
# Copyright 2020 (c) Anna Schumaker
|
||||
#
|
||||
# Use Mutagen to generate a list of tracks missing a specific tag for
|
||||
# all music files in the requested directory
|
||||
import mutagen
|
||||
import os
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 3 or not os.path.isdir(sys.argv[2]):
|
||||
print(f"Usage: {sys.argv[0]} TAG DIRECTORY")
|
||||
sys.exit(1)
|
||||
|
||||
print()
|
||||
print(f"Reading directory {sys.argv[2]}:")
|
||||
|
||||
files = [ ]
|
||||
for entry in pathlib.Path(sys.argv[2]).rglob("*"):
|
||||
if os.path.isfile(entry):
|
||||
files += [ entry ]
|
||||
|
||||
print(f" Found {len(files)} files")
|
||||
|
||||
missing = [ ]
|
||||
read = 0
|
||||
skip = 0
|
||||
for f in files:
|
||||
try:
|
||||
keys = set(mutagen.File(f).keys())
|
||||
if sys.argv[1] not in keys:
|
||||
missing += [ f ]
|
||||
read += 1
|
||||
except Exception as e:
|
||||
#print(e)
|
||||
skip += 1
|
||||
|
||||
print(f" Read {read} files, skipped {skip}")
|
||||
|
||||
print(f" There are {len(missing)} files missing the \"{sys.argv[1]}\" tag:")
|
||||
for f in missing:
|
||||
print(f" {f}")
|
||||
print()
|
Loading…
Reference in New Issue