86 lines
1.9 KiB
Python
86 lines
1.9 KiB
Python
|
#!/usr/bin/env python3
|
||
|
# -*- coding: UTF-8 -*-
|
||
|
#
|
||
|
# split.py
|
||
|
#
|
||
|
# Copyright 2023 Beat Jäckle <beat@git.jdmweb2.ch>
|
||
|
from ffmpeg import FFmpeg
|
||
|
from splitSrc.ChapterTitle import ChapterTitle
|
||
|
from splitSrc.ChapterTimes import ChapterTimes
|
||
|
|
||
|
FILENAMEMUSTER = ['../HPMoR_Part_', '.mp3']
|
||
|
TITLES = 'chaptertitle.ods'
|
||
|
TIMES = 'chapter.csv'
|
||
|
|
||
|
|
||
|
def ffmpeg(part, cid, time: dict, end, title) -> None:
|
||
|
# utitle = title.replace(" ", "_")
|
||
|
# utitle = utitle.replace("'", "_")
|
||
|
# utitle = utitle.replace("__", "_")
|
||
|
utitle = title['t_']
|
||
|
title = title['t']
|
||
|
filename = f'{cid}_{utitle}'
|
||
|
f = FFmpeg()
|
||
|
f.option('y')
|
||
|
if end is not None:
|
||
|
f.input(
|
||
|
FILENAMEMUSTER[0] +
|
||
|
str(part) +
|
||
|
FILENAMEMUSTER[1],
|
||
|
ss=time,
|
||
|
to=end,
|
||
|
|
||
|
)
|
||
|
else:
|
||
|
f.input(
|
||
|
FILENAMEMUSTER[0] +
|
||
|
str(part) +
|
||
|
FILENAMEMUSTER[1],
|
||
|
ss=time,
|
||
|
to=end,
|
||
|
|
||
|
)
|
||
|
f.output(
|
||
|
filename,
|
||
|
metadata=f'title={title}'
|
||
|
)
|
||
|
f.execute()
|
||
|
|
||
|
|
||
|
def main(args):
|
||
|
chapterTitle = ChapterTitle(TITLES)
|
||
|
chapterTimes = ChapterTimes()
|
||
|
current = next(chapterTimes)
|
||
|
for pochain in chapterTimes:
|
||
|
[i, p, t] = current
|
||
|
|
||
|
try:
|
||
|
i = int(i)
|
||
|
except ValueError:
|
||
|
print(i, t, 'Keine Kapitelnummer')
|
||
|
else:
|
||
|
# Test if it has a processor)
|
||
|
if p == pochain[1]:
|
||
|
end = pochain[2]
|
||
|
else:
|
||
|
end = None
|
||
|
try:
|
||
|
title = chapterTitle[i]
|
||
|
except KeyError:
|
||
|
print('No Chapter',i)
|
||
|
title = dict(t='__No Name__', t_='UNKNOWN')
|
||
|
ffmpeg(
|
||
|
part=p,
|
||
|
cid=i,
|
||
|
time=t,
|
||
|
end=end,
|
||
|
title=title)
|
||
|
finally:
|
||
|
current = pochain
|
||
|
return 0
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
import sys
|
||
|
sys.exit(main(sys.argv))
|