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/
|
||||
|
||||
*local
|
||||
out/*
|
||||
|
|
0
out/.gitkeep
Normal file
0
out/.gitkeep
Normal file
81
split.py
81
split.py
|
@ -4,77 +4,54 @@
|
|||
# split.py
|
||||
#
|
||||
# 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.ChapterTimes import ChapterTimes
|
||||
from splitSrc.ffmpeg import ffmpeg
|
||||
|
||||
|
||||
FILENAMEMUSTER = ['../HPMoR_Part_', '.mp3']
|
||||
TITLES = 'chaptertitle.ods'
|
||||
TIMES = 'chapter.csv'
|
||||
FILEFORMAT = 'mp3'
|
||||
|
||||
|
||||
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
|
||||
def main():
|
||||
"""Splitting HPmod Files into their chapter"""
|
||||
chapter_title = ChapterTitle(TITLES)
|
||||
chapter_times = ChapterTimes()
|
||||
current = next(chapter_times)
|
||||
for pochain in chapter_times:
|
||||
[cid, part, time] = current
|
||||
|
||||
try:
|
||||
i = int(i)
|
||||
cid = int(cid)
|
||||
except ValueError:
|
||||
print(i, t, 'Keine Kapitelnummer')
|
||||
print(cid, time, 'Keine Kapitelnummer')
|
||||
else:
|
||||
# Test if it has a processor)
|
||||
if p == pochain[1]:
|
||||
if part == pochain[1]:
|
||||
end = pochain[2]
|
||||
else:
|
||||
end = None
|
||||
try:
|
||||
title = chapterTitle[i]
|
||||
title = chapter_title[cid]
|
||||
except KeyError:
|
||||
print('No Chapter',i)
|
||||
title = dict(t='__No Name__', t_='UNKNOWN')
|
||||
print('No Chapter', cid)
|
||||
title = dict(time='__No Name__', time_='UNKNOWN')
|
||||
else:
|
||||
ffmpeg(
|
||||
part=p,
|
||||
cid=i,
|
||||
time=t,
|
||||
part=part,
|
||||
cid=cid,
|
||||
time=time,
|
||||
end=end,
|
||||
title=title)
|
||||
title=title,
|
||||
filenamemuster=FILENAMEMUSTER,
|
||||
fileformat=FILEFORMAT,
|
||||
)
|
||||
finally:
|
||||
current = pochain
|
||||
return 0
|
||||
|
@ -82,4 +59,4 @@ def main(args):
|
|||
|
||||
if __name__ == '__main__':
|
||||
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