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
|
#!/usr/bin/python
#-*-coding:utf-8 -*
import re, os, time, sys
motif = sys.argv[1]
fileName = sys.argv[2]
titre = fileName[0:fileName.rindex('.')]
l = [""]
i = 0
while i < len(motif) :
if motif[i] == '%' :
l.append(motif[i:i+2])
l.append("")
i+=2
else:
l[-1] += motif[i]
i+=1
if l[-1] == "" :
l = l[0:len(l)-1]
if l[0] == "" :
l = l[1:]
regexString = "^"
for t in l :
if t[0] == '%':
regexString += "(.*?)"
else:
regexString += t
regexString += "$"
reg = re.search(regexString, titre)
if reg :
print(reg.group(0))
print(reg.group(1))
print(reg.group(2))
k = 1
option = { "%t":"title", "%a":"artist", "%A":"album", "%y":"year", "%n":"track", "%c":"comment"}
tag = { "title":"", "artist":"", "album":"", "year":"", "track":"", "comment":""}
optionEyeD3 = {"title":"-t", "artist":"-a", "album":"-A", "year":"-Y", "track":"-n", "comment":"-c"}
for i in range(len(l)):
if l[i] in option :
tag[option[l[i]]] = reg.group(k);
k+=1
cmdLine = "eyeD3 \"" + fileName + "\" "
for key, value in [ (x,y) for x,y in tag.items() if y != ""]:
cmdLine += optionEyeD3[key] + " \"" + value + "\" "
print(cmdLine)
os.system(cmdLine)
else:
print("Didn't match");
|