-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
32 lines (28 loc) · 871 Bytes
/
test.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
from mutagen.easyid3 import EasyID3
import re, os, sys
def cleanup(value):
if isinstance(value, list):
for key, _ in enumerate(value):
value[key] = cleanup(value[key])
return value
else:
# print "VALUE:", value
pattern = re.compile("(-\s)*www.songs.pk", re.IGNORECASE)
output = pattern.sub("", value)
return output.strip()
def cleanUpFile(filePath):
audio = EasyID3(filePath)
changed = 0
for fieldName in audio:
if audio[fieldName] == "":
continue
cleanValue = cleanup( audio[fieldName] )
if not cleanValue == audio[fieldName]:
changed = 1
audio[fieldName] = cleanValue
if changed == 1:
print audio["title"]
print audio.save()
if __name__ == "__main__":
filePath = sys.argv[1]
cleanUpFile(filePath)