-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudiobook.py
74 lines (53 loc) · 2 KB
/
audiobook.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
import glob , os, subprocess ,sys
from metadata import *
import metadata
scriptDirectory = os.path.dirname(os.path.realpath(__file__))
indir = os.path.join("C:\\","book",title) #C:\\book\A Distant Mirror"
if not os.path.exists(indir):
os.makedirs(indir)
# print("Saving files to: ", indir )
os.chdir(indir)
# print("Local directory: ", os.getcwd() )
drive='E'
# print(dir(metadata))
def rip():
RIP_EXE = 'nlrip.exe'
ripper = None
for root, dirs, files in os.walk(scriptDirectory):
if RIP_EXE in files:
ripper = os.path.join(root, RIP_EXE)
print("Ripper:", ripper)
ripNum = 1
while True:
result = subprocess.run("{} {} {:0>2}.wav".format(ripper, drive, ripNum) , check=True)
ans = input("Saved disk {}. Rip another CD? [Y/n]".format(ripNum)) or 'Y'
if ans not in ['Y','y']:
break
ripNum += 1
def encode():
encoder = os.path.join(scriptDirectory, 'qaac', 'qaac64.exe')
AAC_CMD = encoder + ' -o "{outdir}\\{filename}.m4b" -v32 --title "{title}" --artist "{artist}" --artwork "{art}" --concat "{files}"'
infiles = sorted( glob.glob(os.path.join( indir, "*.wav")) )
artwork = glob.glob(os.path.join( indir, "*.jp*" ) )[0]
# Break up large audibooks for iPod compatibility (13 hour max)
n = 12
if len(infiles) > n:
part = 1
else:
part = 0
for i in range(0,len(infiles),n):
files = '" "'.join( infiles[i:i+n] )
if part:
filename = '{} Part {}'.format(title, part)
else:
filename = title
print('-----------------------------')
cmd = AAC_CMD.format(outdir = indir, filename = filename, artist = author, title = title, art = artwork, files = files)
print(cmd)
sts = subprocess.call(cmd, shell=True)
print('===============================')
part += 1
if __name__ == '__main__':
# rip()
encode()
ans = input("Encoding done. Press Enter to continue.")