Apply numbering only to non-normalized files by default
Also add `-f` to force numbering
This commit is contained in:
@@ -190,10 +190,13 @@ def build_plan(files, parse_mode):
|
|||||||
return plan
|
return plan
|
||||||
|
|
||||||
|
|
||||||
def build_number_plan(files, parse_mode):
|
def build_number_plan(files, parse_mode, force=False):
|
||||||
"""Build a rename plan using sequential numbering per day."""
|
"""Build a rename plan using sequential numbering per day."""
|
||||||
entries = []
|
entries = []
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
|
if not force and NORMALIZED.match(file_path.name):
|
||||||
|
entries.append((file_path, None, STATUS_ALREADY))
|
||||||
|
continue
|
||||||
date_str = get_date_for_file(file_path, parse_mode)
|
date_str = get_date_for_file(file_path, parse_mode)
|
||||||
entries.append((file_path, date_str))
|
entries.append((file_path, date_str))
|
||||||
|
|
||||||
@@ -201,7 +204,11 @@ def build_number_plan(files, parse_mode):
|
|||||||
plan = []
|
plan = []
|
||||||
seen_targets = {}
|
seen_targets = {}
|
||||||
|
|
||||||
for file_path, date_str in entries:
|
for entry in entries:
|
||||||
|
if len(entry) == 3:
|
||||||
|
plan.append((entry[0], None, entry[2]))
|
||||||
|
continue
|
||||||
|
file_path, date_str = entry
|
||||||
if date_str is None:
|
if date_str is None:
|
||||||
plan.append((file_path, None, STATUS_NO_MATCH))
|
plan.append((file_path, None, STATUS_NO_MATCH))
|
||||||
continue
|
continue
|
||||||
@@ -290,8 +297,15 @@ def main():
|
|||||||
help=(
|
help=(
|
||||||
'Discard original filename stems and number files sequentially '
|
'Discard original filename stems and number files sequentially '
|
||||||
'per day. Combines with --parse to select the date source. '
|
'per day. Combines with --parse to select the date source. '
|
||||||
|
'Skips already-normalized files unless --force is given.'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-f',
|
||||||
|
'--force',
|
||||||
|
action='store_true',
|
||||||
|
help='Force numbering even for already-normalized files (used with -n).',
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'files',
|
'files',
|
||||||
nargs='*',
|
nargs='*',
|
||||||
@@ -306,7 +320,7 @@ def main():
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if args.number:
|
if args.number:
|
||||||
plan = build_number_plan(files, args.parse)
|
plan = build_number_plan(files, args.parse, args.force)
|
||||||
else:
|
else:
|
||||||
plan = build_plan(files, args.parse)
|
plan = build_plan(files, args.parse)
|
||||||
print_preview(plan)
|
print_preview(plan)
|
||||||
|
|||||||
Reference in New Issue
Block a user