| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- #!/usr/bin/env python3
- import re, sys, os, argparse, pathlib, logging
- import zz_remux as remux
- def main():
- # Static config
- debug = False
- log_level = logging.WARN
- prog_name = 'zz_remux'
- # ENV config
- if 'DEBUG' in os.environ:
- if os.environ['DEBUG'] == 'INFO':
- log_level = logging.INFO
- else:
- log_level = logging.DEBUG
- # CLI config
- parser = argparse.ArgumentParser(prog=prog_name,
- description='Calls mkvmerge, mkvpropedit and ffprobe in useful ways')
- parser.add_argument('root', metavar='base_directory', type=pathlib.Path,
- help='Recursively process all media files in this directory')
- parser.add_argument('--match', '-m',
- help='Only process files that match this (case-insensitive) regex')
- parser.add_argument('--no-recursion', '-n', action='store_true', help='Do not recurse')
- parser.add_argument('--verbose', '-v', action='store_true', help='Log more')
- parser.add_argument('--debug', '-d', action='store_true', help='Log lots more')
- args = None
- try:
- args = parser.parse_args()
- except:
- parser.print_help()
- sys.exit(-1)
- if args.debug:
- log_level = logging.DEBUG
- elif args.verbose:
- log_level = logging.INFO
- if not args.root.is_dir():
- print(f"Invalid base_directory: {args.root}", file=sys.stderr)
- parser.print_help()
- sys.exit(-1)
- root = args.root
- match = None
- if args.match:
- try:
- match = re.compile(args.match, re.IGNORECASE)
- args.match = True
- except:
- print(f"Unable to compile match regex: {args.match}", file=sys.stderr)
- parser.print_help()
- sys.exit(-1)
- recurse = True
- if args.no_recursion:
- recurse = False
- del args
- del parser
- # Logging
- logging.basicConfig(stream=sys.stderr)
- logger = logging.getLogger(prog_name)
- logger.setLevel(log_level)
- # Module init
- mux = remux.Mux(logLevel=log_level)
- scan = remux.Scan(logLevel=log_level)
- lang = remux.Lang(logLevel=log_level)
- # Walk
- logger.debug(f"Root: {root}")
- for (parent, dirs, files) in root.walk():
- logger.debug(f"Walking: {parent}")
- media = scan.scan(files, parent, match=match)
- mux.mux(media)
- lang.lang(media)
- # Non-recursion
- if not recurse:
- logger.info("Not recursing")
- return
- # Exec
- if __name__ == "__main__":
- main()
|