-
Notifications
You must be signed in to change notification settings - Fork 0
/
enc_rec.py
65 lines (55 loc) · 1.55 KB
/
enc_rec.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
import os
# import time
import subprocess as sp
import re
import multiprocessing
# import threading
def sun(s):
ret = ''
for c in s:
if c in ' \'\"()&!@?$':
ret += '\\'
ret += c
return ret
def conv(fpath):
print(fpath)
sp.getoutput('opusenc --quiet --bitrate 128 {} {}'.format(fpath, fpath.replace('.flac', '.opus')))
def metaconv(fpaths):
# ths = []
for fpath in fpaths:
conv(fpath)
# try:
# time.sleep(0)
# thread = threading.Thread(target=conv, args=(fpath,))
# ths.append(thread)
# thread.start()
# except BlockingIOError as e:
# time.sleep(5)
# [th.join() for th in ths]
def main():
targets = [[], [], []]
cnt = 0
for dn, ds, fs in os.walk(os.getcwd()):
for f in fs:
fpath = sun(dn + '/' + f)
# print(fpath)
if re.search('\.flac$', fpath):
if cnt % 3 == 1:
targets[1].append(fpath)
elif cnt % 3 == 2:
targets[2].append(fpath)
else:
targets[0].append(fpath)
cnt += 1
jobs = []
job0 = multiprocessing.Process(target=metaconv, args=(targets[0],))
jobs.append(job0)
job0.start()
job1 = multiprocessing.Process(target=metaconv, args=(targets[1],))
jobs.append(job1)
job1.start()
job2 = multiprocessing.Process(target=metaconv, args=(targets[2],))
jobs.append(job2)
job2.start()
[job.join() for job in jobs]
main()