Exemplo n.º 1
0
def split_album_art_paths(value):
	paths = value
	if value:
		paths = []

		if not isinstance(value, list):
			value = value.split(',')

		for val in value:
			paths.append(custom_path(val.strip()))

	return paths
Exemplo n.º 2
0
def test_cli_custom_path_non_windows():
	assert custom_path('/d/Music/test.mp3') == Path('/d/Music/test.mp3')
Exemplo n.º 3
0
def test_cli_custom_path_windows(value):
	assert custom_path(value) == Path('D:/Music/test.mp3')
Exemplo n.º 4
0
def default_args(args):
	defaults = Namespace()

	# Set defaults.
	defaults.verbose = 0
	defaults.quiet = 0
	defaults.debug = False
	defaults.dry_run = False
	defaults.username = ''
	defaults.filters = []

	if 'no_log_to_stdout' in args:
		defaults.log_to_stdout = False
		defaults.no_log_to_stdout = True
	else:
		defaults.log_to_stdout = True
		defaults.no_log_to_stdout = False

	if 'log_to_file' in args:
		defaults.log_to_file = True
		defaults.no_log_to_file = False
	else:
		defaults.log_to_file = False
		defaults.no_log_to_file = True

	if args._command in ['down', 'download', 'up', 'upload']:
		defaults.uploader_id = None
		defaults.device_id = None
	elif args._command in ['quota']:
		defaults.uploader_id = None
	else:
		defaults.device_id = None

	if args._command in ['down', 'download', 'up', 'upload']:
		defaults.no_recursion = False
		defaults.max_depth = math.inf
		defaults.exclude_paths = []
		defaults.exclude_regexes = []
		defaults.exclude_globs = []

		if 'no_use_hash' in args:
			defaults.use_hash = False
			defaults.no_use_hash = True
		else:
			defaults.use_hash = True
			defaults.no_use_hash = False

		if 'no_use_metadata' in args:
			defaults.use_metadata = False
			defaults.no_use_metadata = True
		else:
			defaults.use_metadata = True
			defaults.no_use_metadata = False

	if args._command in ['down', 'download']:
		defaults.output = str(Path('.').resolve())
		defaults.include = []
	elif args._command in ['up', 'upload']:
		defaults.include = [custom_path('.').resolve()]
		defaults.delete_on_success = False
		defaults.no_sample = False
		defaults.album_art = None

	if args._command in ['del', 'delete', 'search']:
		defaults.yes = False

	config_defaults = get_defaults(
		args._command,
		read_config_file(
			username=args.get('username')
		),
		command_keys=COMMAND_KEYS,
		command_aliases=COMMAND_ALIASES
	)

	for k, v in config_defaults.items():
		if k == 'album_art':
			defaults.album_art = split_album_art_paths(v)
		elif k == 'filters':
			defaults.filters = [
				parse_filter(filter_)
				for filter_ in v
			]
		elif k == 'max_depth':
			defaults.max_depth = int(v)
		elif k == 'output':
			defaults.output = str(custom_path(v))
		elif k == 'include':
			defaults.include = [
				custom_path(val)
				for val in v
			]
		elif k in [
			'log_to_stdout',
			'log_to_file',
			'use_hash',
			'use_metadata',
		]:
			defaults[k] = v
			defaults[f"no_{k}"] = not v
		elif k in [
			'no_log_to_stdout',
			'no_log_to_file',
			'no_use_hash',
			'no_use_metadata',
		]:
			defaults[k] = v
			defaults[k.replace('no_', '')] = not v
		elif k.startswith(('created', 'modified')):
			if k.endswith('in'):
				defaults[k] = datetime_string_to_time_period(v, in_=True)
			elif k.endswith('on'):
				defaults[k] = datetime_string_to_time_period(v, on=True)
			elif k.endswith('before'):
				defaults[k] = datetime_string_to_time_period(v, before=True)
			elif k.endswith('after'):
				defaults[k] = datetime_string_to_time_period(v, after=True)
		else:
			defaults[k] = v

	return defaults
Exemplo n.º 5
0

##########
# Output #
##########

output = argparse.ArgumentParser(
	argument_default=argparse.SUPPRESS,
	add_help=False
)

output_options = output.add_argument_group("Output")
output_options.add_argument(
	'-o', '--output',
	metavar='TEMPLATE_PATH',
	type=lambda t: str(custom_path(t)),
	help="Output file or directory name which can include template patterns."
)


###########
# Include #
###########

include = argparse.ArgumentParser(
	argument_default=argparse.SUPPRESS,
	add_help=False
)

include_options = include.add_argument_group("Include")
include_options.add_argument(
Exemplo n.º 6
0
torrent_options.add_argument('--md5',
                             action='store_true',
                             help="Add md5 hash to info dict.")

##########
# Output #
##########

output = argparse.ArgumentParser(argument_default=argparse.SUPPRESS,
                                 add_help=False)

output_options = output.add_argument_group("Output")
output_options.add_argument('-o',
                            '--output',
                            metavar='NAME',
                            type=lambda p: custom_path(p),
                            help=("Set name of torrent file.\n"
                                  "Defaults to input file or directory name."))

#########
# Input #
#########

input_ = argparse.ArgumentParser(argument_default=argparse.SUPPRESS,
                                 add_help=False)

input_options = input_.add_argument_group("Input")
input_options.add_argument('input',
                           metavar='PATH',
                           type=lambda p: custom_path(p).resolve(),
                           help="File or directory.")