Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pretty_duration_centis_limit():
mi = MediaInfoForTest(FFPROBE_EXAMPLE_JSON_PATH)
mi.duration_seconds = 1.9999
pretty_duration = MediaInfo.pretty_duration(mi.duration_seconds, show_centis=True)
assert_equals(pretty_duration, "00:01.99")
def test_pretty_duration_millis_limit():
mi = MediaInfoForTest(FFPROBE_EXAMPLE_JSON_PATH)
mi.duration_seconds = 1.9999
pretty_duration = MediaInfo.pretty_duration(mi.duration_seconds, show_millis=True)
assert_equals(pretty_duration, "00:01.999")
def test_grid_equality():
g1 = Grid(4, 4)
g2 = Grid(4, 4)
assert_equals(g1, g2)
def test_grid_equality():
g1 = Grid(4, 4)
g2 = Grid(4, 4)
assert_equals(g1, g2)
def test_grid_columns_integer():
assert_raises(ArgumentTypeError, mxn_type, 'ax4')
assert_raises(ArgumentTypeError, mxn_type, '4.1x4')
def test_grid_default():
test_grid = mxn_type('4x4')
assert_equals(test_grid.x, 4)
assert_equals(test_grid.y, 4)
# Argument parser before actual argument parser to let the user overwrite the config path
preargparser = argparse.ArgumentParser(add_help=False)
preargparser.add_argument("-c", "--config", dest="configfile", default=None)
preargs, _ = preargparser.parse_known_args()
try:
if preargs.configfile:
# check if the given config file exists
# abort if not, because the user wants to use a specific file and not the default config
if os.path.exists(preargs.configfile):
Config.load_configuration(preargs.configfile)
else:
error_exit("Could find config file")
else:
# check if the config file exists and load it
if os.path.exists(DEFAULT_CONFIG_FILE):
Config.load_configuration(DEFAULT_CONFIG_FILE)
except configparser.MissingSectionHeaderError as e:
error_exit(e.message)
parser = argparse.ArgumentParser(description="Create a video contact sheet",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("filenames", nargs="+")
parser.add_argument(
"-o", "--output",
help="save to output file",
dest="output_path")
# adding --config to the main parser to display it when the user asks for help
# the value is not important anymore
parser.add_argument(
"-c", "--config",
help="Config file to load defaults from",
default=DEFAULT_CONFIG_FILE
def mxn_type(string):
"""Type parser for argparse. Argument of type "mxn" will be converted to Grid(m, n).
An exception will be thrown if the argument is not of the required form
"""
try:
split = string.split("x")
assert (len(split) == 2)
m = int(split[0])
assert (m >= 0)
n = int(split[1])
assert (n >= 0)
return Grid(m, n)
except (IndexError, ValueError, AssertionError):
error = "Grid must be of the form mxn, where m is the number of columns and n is the number of rows."
raise argparse.ArgumentTypeError(error)
print("Processing {}...".format(path))
if args.interval is not None and args.manual_timestamps is not None:
error_exit("Cannot use --interval and --manual at the same time.")
if args.vcs_width != DEFAULT_CONTACT_SHEET_WIDTH and args.actual_size:
error_exit("Cannot use --width and --actual-size at the same time.")
if args.delay_percent is not None:
args.start_delay_percent = args.delay_percent
args.end_delay_percent = args.delay_percent
args.num_groups = 5
media_info = MediaInfo(
path,
verbose=args.is_verbose)
media_capture = MediaCapture(
path,
accurate=args.is_accurate,
skip_delay_seconds=args.accurate_delay_seconds,
frame_type=args.frame_type
)
# metadata margins
if not args.metadata_margin == DEFAULT_METADATA_MARGIN:
args.metadata_horizontal_margin = args.metadata_margin
args.metadata_vertical_margin = args.metadata_margin
if args.interval is None and args.manual_timestamps is None and (args.grid.x == 0 or args.grid.y == 0):
error = "Row or column of size zero is only supported with --interval or --manual."
if args.interval is not None and args.manual_timestamps is not None:
error_exit("Cannot use --interval and --manual at the same time.")
if args.vcs_width != DEFAULT_CONTACT_SHEET_WIDTH and args.actual_size:
error_exit("Cannot use --width and --actual-size at the same time.")
if args.delay_percent is not None:
args.start_delay_percent = args.delay_percent
args.end_delay_percent = args.delay_percent
args.num_groups = 5
media_info = MediaInfo(
path,
verbose=args.is_verbose)
media_capture = MediaCapture(
path,
accurate=args.is_accurate,
skip_delay_seconds=args.accurate_delay_seconds,
frame_type=args.frame_type
)
# metadata margins
if not args.metadata_margin == DEFAULT_METADATA_MARGIN:
args.metadata_horizontal_margin = args.metadata_margin
args.metadata_vertical_margin = args.metadata_margin
if args.interval is None and args.manual_timestamps is None and (args.grid.x == 0 or args.grid.y == 0):
error = "Row or column of size zero is only supported with --interval or --manual."
error_exit(error)
if args.interval is not None: