We can split now
This commit is contained in:
parent
2cf67e09e8
commit
d0a351e6a4
4 changed files with 114 additions and 54 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -161,3 +161,4 @@ cython_debug/
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
*local
|
*local
|
||||||
|
out/*
|
||||||
|
|
0
out/.gitkeep
Normal file
0
out/.gitkeep
Normal file
85
split.py
85
split.py
|
@ -4,77 +4,54 @@
|
||||||
# split.py
|
# split.py
|
||||||
#
|
#
|
||||||
# Copyright 2023 Beat Jäckle <beat@git.jdmweb2.ch>
|
# Copyright 2023 Beat Jäckle <beat@git.jdmweb2.ch>
|
||||||
from ffmpeg import FFmpeg
|
"""
|
||||||
|
Module providingClasses reading Files
|
||||||
|
Module providingFunction writing mediafiles for us
|
||||||
|
"""
|
||||||
from splitSrc.ChapterTitle import ChapterTitle
|
from splitSrc.ChapterTitle import ChapterTitle
|
||||||
from splitSrc.ChapterTimes import ChapterTimes
|
from splitSrc.ChapterTimes import ChapterTimes
|
||||||
|
from splitSrc.ffmpeg import ffmpeg
|
||||||
|
|
||||||
|
|
||||||
FILENAMEMUSTER = ['../HPMoR_Part_', '.mp3']
|
FILENAMEMUSTER = ['../HPMoR_Part_', '.mp3']
|
||||||
TITLES = 'chaptertitle.ods'
|
TITLES = 'chaptertitle.ods'
|
||||||
TIMES = 'chapter.csv'
|
TIMES = 'chapter.csv'
|
||||||
|
FILEFORMAT = 'mp3'
|
||||||
|
|
||||||
|
|
||||||
def ffmpeg(part, cid, time: dict, end, title) -> None:
|
def main():
|
||||||
# utitle = title.replace(" ", "_")
|
"""Splitting HPmod Files into their chapter"""
|
||||||
# utitle = utitle.replace("'", "_")
|
chapter_title = ChapterTitle(TITLES)
|
||||||
# utitle = utitle.replace("__", "_")
|
chapter_times = ChapterTimes()
|
||||||
utitle = title['t_']
|
current = next(chapter_times)
|
||||||
title = title['t']
|
for pochain in chapter_times:
|
||||||
filename = f'{cid}_{utitle}'
|
[cid, part, time] = current
|
||||||
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:
|
try:
|
||||||
i = int(i)
|
cid = int(cid)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print(i, t, 'Keine Kapitelnummer')
|
print(cid, time, 'Keine Kapitelnummer')
|
||||||
else:
|
else:
|
||||||
# Test if it has a processor)
|
# Test if it has a processor)
|
||||||
if p == pochain[1]:
|
if part == pochain[1]:
|
||||||
end = pochain[2]
|
end = pochain[2]
|
||||||
else:
|
else:
|
||||||
end = None
|
end = None
|
||||||
try:
|
try:
|
||||||
title = chapterTitle[i]
|
title = chapter_title[cid]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print('No Chapter',i)
|
print('No Chapter', cid)
|
||||||
title = dict(t='__No Name__', t_='UNKNOWN')
|
title = dict(time='__No Name__', time_='UNKNOWN')
|
||||||
ffmpeg(
|
else:
|
||||||
part=p,
|
ffmpeg(
|
||||||
cid=i,
|
part=part,
|
||||||
time=t,
|
cid=cid,
|
||||||
end=end,
|
time=time,
|
||||||
title=title)
|
end=end,
|
||||||
|
title=title,
|
||||||
|
filenamemuster=FILENAMEMUSTER,
|
||||||
|
fileformat=FILEFORMAT,
|
||||||
|
)
|
||||||
finally:
|
finally:
|
||||||
current = pochain
|
current = pochain
|
||||||
return 0
|
return 0
|
||||||
|
@ -82,4 +59,4 @@ def main(args):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
sys.exit(main(sys.argv))
|
sys.exit(main())
|
||||||
|
|
82
splitSrc/ffmpeg.py
Normal file
82
splitSrc/ffmpeg.py
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
#
|
||||||
|
# ffmpeg.py
|
||||||
|
#
|
||||||
|
# Copyright 2023 Beat Jäckle <beat@git.jdmweb2.ch>
|
||||||
|
from ffmpeg import FFmpeg
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
|
||||||
|
async def main(part, cid, time: dict, end, title, filenamemuster, fileformat):
|
||||||
|
utitle = title['t_']
|
||||||
|
title = title['t']
|
||||||
|
filename = f'out/{cid}_{utitle}.{fileformat}'
|
||||||
|
|
||||||
|
ffmpeg = (
|
||||||
|
FFmpeg()
|
||||||
|
.option("y")
|
||||||
|
)
|
||||||
|
if end is not None:
|
||||||
|
ffmpeg.input(
|
||||||
|
filenamemuster[0] +
|
||||||
|
str(part) +
|
||||||
|
filenamemuster[1],
|
||||||
|
ss=time,
|
||||||
|
to=end,
|
||||||
|
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
ffmpeg.input(
|
||||||
|
filenamemuster[0] +
|
||||||
|
str(part) +
|
||||||
|
filenamemuster[1],
|
||||||
|
ss=time,
|
||||||
|
to=end,
|
||||||
|
)
|
||||||
|
ffmpeg.output(
|
||||||
|
filename,
|
||||||
|
# metadata=[f'title={title}', f'track={cid}'],
|
||||||
|
options={
|
||||||
|
'metadata': [f'title={title}', f'track={cid}'],
|
||||||
|
"codec:a": "copy"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@ffmpeg.on("start")
|
||||||
|
def on_start(arguments):
|
||||||
|
print("Arguments:", arguments)
|
||||||
|
|
||||||
|
@ffmpeg.on("stderr")
|
||||||
|
def on_stderr(line):
|
||||||
|
print("stderr:", line)
|
||||||
|
|
||||||
|
@ffmpeg.on("progress")
|
||||||
|
def on_progress(progress):
|
||||||
|
print(progress)
|
||||||
|
|
||||||
|
@ffmpeg.on("progress")
|
||||||
|
def time_to_terminate(progress):
|
||||||
|
# Gracefully terminate when more than 200 frames are processed
|
||||||
|
if progress.frame > 200:
|
||||||
|
ffmpeg.terminate()
|
||||||
|
|
||||||
|
@ffmpeg.on("completed")
|
||||||
|
def on_completed():
|
||||||
|
print("Completed")
|
||||||
|
|
||||||
|
@ffmpeg.on("terminated")
|
||||||
|
def on_terminated():
|
||||||
|
print("Terminated")
|
||||||
|
|
||||||
|
@ffmpeg.on("error")
|
||||||
|
def on_error(code):
|
||||||
|
print("Error:", code)
|
||||||
|
|
||||||
|
await ffmpeg.execute()
|
||||||
|
|
||||||
|
|
||||||
|
def ffmpeg(part, cid, time: dict, end, title, filenamemuster, fileformat):
|
||||||
|
asyncio.run(main(
|
||||||
|
part, cid, time, end, title, filenamemuster, fileformat
|
||||||
|
))
|
Loading…
Reference in a new issue