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/python
import os
import mimetypes
import string
import sys
import shutil
input = '/var/www/bayard_musique/'
output = '/var/www/bayard_musique_extraits/'
def grey(string):
return '\x1b\x5b1;30;40m%s\x1b\x5b0;37;40m'%(string)
def red(string):
return '\x1b\x5b1;31;40m%s\x1b\x5b0;37;40m'%(string)
def green(string):
return '\x1b\x5b1;32;40m%s\x1b\x5b0;37;40m'%(string)
def yellow(string):
return '\x1b\x5b1;33;40m%s\x1b\x5b0;37;40m'%(string)
def blue(string):
return '\x1b\x5b1;34;40m%s\x1b\x5b0;37;40m'%(string)
def orange(string):
return '\x1b\x5b1;40;40m%s\x1b\x5b0;37;40m'%(string)
if(os.path.exists(output) == 0):
print("mkdir %s"%(output))
os.mkdir(output)
#On preparre le repertoire de sortie en replicant l'arborescence du repertoire d'entre
for dirpath, dirnames, filenames in os.walk(input):
tmp = dirpath.replace(input, output)
if(os.path.exists(tmp) == 0):
print('mkdir %s'%(tmp))
os.mkdir(tmp)
mp3_count = 0
xml_count = 0
mp3_cut = 0
#On fait cqu'on a faire, forcement a un moment faut y aller et on va se prendre un cafe
for dirpath, dirnames, filenames in os.walk(input):
for filename in filenames:
f_mime = mimetypes.guess_type(filename)
if f_mime[0] == 'audio/mpeg':
mp3_count += 1
mp3_in = os.path.join(dirpath, filename)
mp3_out = os.path.join(dirpath.replace(input, output), filename)
cut_line = 'cutmp3 -i %s -a 0:30 -b 1:00 -O %s'%(mp3_in, mp3_out)
if(os.path.exists(mp3_out) == 0):
mp3_cut += 1
print('#%s %s (%s)\n cut to \n %s'%(grey(mp3_cut) ,yellow(mp3_in), blue(f_mime[0]) , green(mp3_out)))
a = os.popen('%s'%(cut_line)).readlines()
for p in a:
if p != '\n':
if 'ERROR' in p:
print(' %s'%(red(p.strip())))
elif 'WARNING' in p:
print(' %s'%(red(p.strip())))
else:
print(' %s'%(green(p.strip())))
elif f_mime[0] == 'application/xml':
xml_count += 1
xml_in = os.path.join(dirpath, filename)
xml_out = os.path.join(dirpath.replace(input, output), filename)
if(os.path.exists(xml_out) == 0):
print(' %s (%s) copy to %s'%(blue(xml_in), blue(f_mime[0]) , blue(xml_out)))
shutil.copyfile(xml_in, xml_out)
print
print(' mp3 count: %s, xml count: %s, mp3 cutted: %s'%(green(mp3_count), green(xml_count), green(mp3_cut)))
print |