-
Notifications
You must be signed in to change notification settings - Fork 0
/
id3.py
executable file
·95 lines (78 loc) · 2.48 KB
/
id3.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python3
import eyed3
import eyed3.id3
import os
import re
import argparse
eyed3.log.setLevel("ERROR")
P1 = re.compile("^(.*) +- +(.*)$")
P2 = re.compile("^(.*): +[‘'\"”](.*)[’'\"”]$")
P3 = re.compile("^(.*): +[‘'\"”](.*)[’'\"”“] (.*)$")
P4 = re.compile("^\d*-(.*)_\s*[‘'\"”](.*)[’'\"”“].mp3$")
G_NONE = eyed3.id3.Genre()
def process_song(fname):
name = os.path.basename(fname)
a = eyed3.load(fname)
if(not a or not a.tag):
print("No ID3 info found", fname)
return
a.tag.header._version = eyed3.id3.ID3_V2_4
if(a.tag.artist == "KEXP" or a.tag.artist == "KCRW" or a.tag.artist == "MPR" or a.tag.artist == "Minnesota Public Radio"):
if(P1.match(a.tag.title)):
m = P1.match(a.tag.title)
a.tag.artist = m.group(1)
a.tag.title = m.group(2)
elif(P2.match(a.tag.title)):
m = P2.match(a.tag.title)
a.tag.artist = m.group(1)
a.tag.title = m.group(2)
elif(P3.match(a.tag.title)):
m = P3.match(a.tag.title)
a.tag.artist = m.group(1) + " " + m.group(3)
a.tag.title = m.group(2)
else:
print("No parsed", a.tag.title)
elif(a.tag.artist and a.tag.title and a.tag.title.startswith(a.tag.artist)):
a.tag.title = a.tag.title.replace(a.tag.artist + " - " , "")
elif(a.tag.title and P1.match(a.tag.title)):
m = P1.match(a.tag.title)
a.tag.artist = m.group(1)
a.tag.title = m.group(2)
elif(P3.match(name)):
m = P3.match(name)
a.tag.artist = m.group(1)
a.tag.title = m.group(2)
elif(P4.match(name)):
m = P4.match(name)
a.tag.artist = m.group(1)
a.tag.title = m.group(2)
elif(a.tag.genre == "KUTX Song of the Day" or (a.tag.artist and a.tag.title)):
pass
else:
print("NO PARSED", fname)
if a.tag.artist: a.tag.artist = a.tag.artist.replace("\\", "")
if a.tag.title: a.tag.title = a.tag.title.replace("\\", "")
a.tag.images.remove('')
a.tag.genre = G_NONE
try:
a.tag.save()
except:
print(":()")
print("dir2ogg --recursive --directory --delete-input --smart-mp3 /home/jose/Documents/Podcast/Song\ of\ the\ Day")
def dir_path(string):
if os.path.isdir(string):
return string
else:
raise NotADirectoryError(string)
def setup_args():
parser = argparse.ArgumentParser(description='Id3 tags seter')
parser.add_argument("directory", nargs=1, type=dir_path, help='Directory where files are')
args = parser.parse_args()
return args
def traverse(path):
for myfile in os.scandir(path):
if myfile.is_file():
process_song(myfile.path)
if __name__ == "__main__":
args = setup_args()
traverse(args.directory[0])