48 lines
1008 B
Python
48 lines
1008 B
Python
#!/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()
|