rip-py: Add a split-file command
This is a backup from 2020-11-29 which added a split-file command to the toolkit, which can be used to e.g. split DVDs of concerts into its songs.
This commit is contained in:
parent
32edd53cfb
commit
37f03fe6bd
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import itertools
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
@ -78,6 +79,7 @@ def _rip_title(title, output_dir, fifo_path, device=None, media_type=None,
|
||||||
'-analyzeduration', '150M',
|
'-analyzeduration', '150M',
|
||||||
'-i', fifo_path,
|
'-i', fifo_path,
|
||||||
'-map', '0:v:0',
|
'-map', '0:v:0',
|
||||||
|
#'-c:a', 'flac',
|
||||||
'-c:a', 'copy',
|
'-c:a', 'copy',
|
||||||
'-c:v', 'h264',
|
'-c:v', 'h264',
|
||||||
'-crf', '18',
|
'-crf', '18',
|
||||||
|
@ -281,5 +283,32 @@ def find_right_title(start_title, end_title, device):
|
||||||
print('No title without duplicates found.')
|
print('No title without duplicates found.')
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command('split-file')
|
||||||
|
@click.option('-c', '--chapters-file', type=FILE_TYPE, required=True,
|
||||||
|
help='File with timestamps separated by comma')
|
||||||
|
@click.option('-i', '--input-file', type=FILE_TYPE, required=True)
|
||||||
|
@click.option('-o', '--output-dir', type=DIRECTORY_TYPE, required=True)
|
||||||
|
def split_file(output_dir, input_file, chapters_file):
|
||||||
|
extension = input_file.split('.')[-1]
|
||||||
|
|
||||||
|
with open(chapters_file) as f:
|
||||||
|
chapters = f.read().strip().split(',')
|
||||||
|
|
||||||
|
for i, (start, end) in enumerate(itertools.zip_longest(chapters, chapters[1:])):
|
||||||
|
ffmpeg_cmd = ['ffmpeg',
|
||||||
|
'-ss', start]
|
||||||
|
if end is not None:
|
||||||
|
ffmpeg_cmd += ['-to', end]
|
||||||
|
|
||||||
|
ffmpeg_cmd += [
|
||||||
|
'-i', input_file,
|
||||||
|
'-c:a', 'flac',
|
||||||
|
#'-c:v', 'copy',
|
||||||
|
os.path.join(output_dir, '{}.{}'.format(i + 1, extension))
|
||||||
|
]
|
||||||
|
#print(ffmpeg_cmd)
|
||||||
|
subprocess.check_call(ffmpeg_cmd)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
cli()
|
cli()
|
||||||
|
|
Loading…
Reference in New Issue