This repository was archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagger.py
More file actions
68 lines (66 loc) · 2.21 KB
/
tagger.py
File metadata and controls
68 lines (66 loc) · 2.21 KB
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
from mutagen.mp3 import MP3
from mutagen.id3 import error
from mutagen.id3 import ID3, TIT2, TALB, TPE1, TPE2, COMM, USLT, TCOM, TCON, TDRC, APIC,TRCK
import os
import re
def makeClean(path):
return re.sub(r"[\W ]", '', path)
def dir(folder):
if not os.path.exists(folder):
os.makedirs(folder)
def tagGPM(track,albumArt,song):
tags = MP3(song)
try:
tags.add_tags()
except error:
print("has tags")
try:
tags["TRCK"] = TRCK(encoding=3, text=str(track["trackNumber"]))
except:
print(" !!! Failed to add track no")
try:
tags["TIT2"] = TIT2(encoding=3, text=track["title"])
except:
print(" !!! Failed to add title")
try:
tags["TALB"] = TALB(encoding=3, text=track["album"])
except:
print(" !!! Failed to add album")
try:
tags["COMM"] = COMM(encoding=3, lang=u'eng', desc='desc', text=u'Downloaded from GPM')
except:
print(" !!! Failed to add comment")
try:
tags["TPE1"] = TPE1(encoding=3, text=track["artist"])
except:
print(" !!! Failed to add artist")
try:
tags["TPE2"] = TPE2(encoding=3, text=track["albumArtist"])
except:
print(" !!! Failed to add album artist")
try:
tags["TCOM"] = TCOM(encoding=3, text=track["composer"])
except:
print(" !!! Failed to add composer")
try:
tags["TCON"] = TCON(encoding=3, text=track["genre"])
except:
print(" !!! Failed to add genre")
try:
tags["TDRC"] = TDRC(encoding=3, text=str(track["year"]))
except:
print(" !!! Failed to add year")
tags["APIC"] = APIC(
encoding=3, # 3 is for utf-8
mime='image/png', # image/jpeg or image/png
type=3, # 3 is for the cover image
desc=u'Cover',
data=open(albumArt,"rb").read()
)
output = "output/" + makeClean(track["albumArtist"]) + "/" + makeClean(track["album"]) + "/" + makeClean(track["title"]) + ".mp3"
dir("output")
dir("output/" + makeClean(track["albumArtist"]))
dir("output/" + makeClean(track["albumArtist"]) + "/" + makeClean(track["album"]) )
tags.save(song)
os.rename(song, output)
os.remove(albumArt)