Created
January 3, 2021 02:33
-
-
Save willsthompson/e6121b9309aaf0b0985e74dedda39fb7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import listdir | |
from os.path import join, isfile | |
from shlex import quote | |
import argparse | |
import subprocess | |
SH_BREAK = ' \\\n\t' | |
parser = argparse.ArgumentParser(description='Merge/chapterize discrete MKV files') | |
parser.add_argument('source_path') | |
parser.add_argument('output_filename') | |
parser.add_argument('--title', nargs=1) | |
args = parser.parse_args() | |
source_files = sorted([ | |
f for f in listdir(args.source_path) | |
if isfile(join(args.source_path, f)) | |
and f.endswith('.mkv') | |
]) | |
mm_args_pre = [ | |
"--ui-language en_US", | |
f"--output '{args.output_filename}'", | |
"--default-track 0:yes " | |
] | |
if args.title: mm_args_pre.append( f"--title {args.title}" ) | |
mm_args = [ | |
f"'(' {quote(join(args.source_path, f))} ')'" for f in source_files | |
] | |
mm_args_post = [ | |
"--generate-chapters-name-template '<FILE_NAME>'", | |
"--generate-chapters when-appending" | |
] | |
cmd = SH_BREAK.join([ | |
'mkvmerge', | |
*mm_args_pre, | |
f' {SH_BREAK}+ '.join(mm_args), | |
*mm_args_post | |
]) | |
print('Chapterize command:') | |
print(cmd) | |
print('Executing...') | |
subprocess.run(cmd, shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment