-
Notifications
You must be signed in to change notification settings - Fork 0
/
removemetadata.py
executable file
·75 lines (63 loc) · 2.37 KB
/
removemetadata.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python3
import os
from sys import stderr
import argparse
from mutagen.mp3 import MP3
from mutagen.id3 import ID3
from mutagen.id3._util import error as ID3Error
from mutagen.flac import FLAC
from mutagen.wave import WAVE
from mutagen.aiff import AIFF
def remove_metadata(filepath):
file_ext = os.path.splitext(filepath)[1].lower()
try:
if file_ext == ".mp3":
audio = MP3(filepath, ID3=ID3)
if audio.tags is not None:
audio.delete()
audio.save()
print(f"Metadata removed from: {filepath}")
else:
print(f"No metadata found in: {filepath}")
elif file_ext == ".flac":
audio = FLAC(filepath)
if audio.tags is not None:
audio.clear()
audio.save()
print(f"Metadata removed from: {filepath}")
else:
print(f"No metadata found in: {filepath}")
elif file_ext == ".wav":
audio = WAVE(filepath)
if audio.tags is not None:
audio.delete()
audio.save()
print(f"Metadata removed from: {filepath}")
else:
print(f"No metadata found in: {filepath}")
elif file_ext == ".aiff":
audio = AIFF(filepath)
if audio.tags is not None:
audio.delete()
audio.save()
print(f"Metadata removed from: {filepath}")
else:
print(f"No metadata found in: {filepath}")
else:
print(f"Unsupported file format: {filepath}")
except ID3Error as e:
print(f"Error removing metadata from {filepath}: {e}")
def process_directory(directory):
for root, _, files in os.walk(directory):
for file in files:
filepath = os.path.join(root, file)
remove_metadata(filepath)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Remove metadata from all music files in a directory (.MP3, .FLAC, .WAV and .AIFF are supported)")
parser.add_argument("input_dir", help="The directory containing music files to process")
parser.print_help()
args = parser.parse_args()
if os.path.isdir(args.input_dir):
process_directory(args.input_dir)
else:
stderr.write(f"Directory not found: {args.input_dir}")