Tools: Add a script for finding common tags of music files

I want to know the bare minimum of what tags can be relied on in my
music, so this script can help me set default / fallback tags.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2020-10-03 09:33:44 -04:00
parent 3eb55713f2
commit f7318f0bc7
1 changed files with 47 additions and 0 deletions

47
tools/common_tags.py Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/python
# Copyright 2020 (c) Anna Schumaker
#
# Use Mutagen to generate a list of common tag names for
# all music files in the requested directory
import mutagen
import os
import pathlib
import sys
if len(sys.argv) != 2 or not os.path.isdir(sys.argv[1]):
print(f"Usage: {sys.argv[0]} DIRECTORY")
sys.exit(1)
print()
print(f"Reading directory {sys.argv[1]}:")
files = [ ]
for entry in pathlib.Path(sys.argv[1]).rglob("*"):
if os.path.isfile(entry):
files += [ entry ]
print(f" Found {len(files)} files")
read = 0
skip = 0
unique = None
for f in files:
try:
keys = set(mutagen.File(f).keys())
if unique == None:
unique = keys
else:
unique = unique.intersection(keys)
read += 1
except Exception as e:
#print(e)
skip += 1
print(f" Read {read} files, skipped {skip}")
tags = list(unique)
tags.sort()
print(f" There are {len(tags)} common tags:")
for t in tags:
print(f" {t}")
print()