FEATURE: single source of truth for default values added
This commit is contained in:
+50
-116
@@ -1,133 +1,67 @@
|
||||
"""Command‑line interface and entry point."""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
from .constants import DEFAULT_BAD_CHARS
|
||||
from .tracklist import read_tracklist, parse_format
|
||||
from .defaults import (
|
||||
DEFAULT_FORMAT,
|
||||
DEFAULT_OUTPUT_TEMPLATE,
|
||||
DEFAULT_REPLACEMENT_CHAR,
|
||||
DEFAULT_BAD_CHARS,
|
||||
DEFAULT_TRACKLIST_FORMAT,
|
||||
DEFAULT_ALBUM,
|
||||
DEFAULT_COMMENT,
|
||||
DEFAULT_COMMENT_STREAM,
|
||||
DEFAULT_COMMENT_SEPARATOR,
|
||||
DEFAULT_NO_COMMENT,
|
||||
DEFAULT_MERGE_COMMENTS,
|
||||
DEFAULT_DROP_VIDEO,
|
||||
DEFAULT_DROP_SUBS,
|
||||
DEFAULT_NUMBER_TRACKS,
|
||||
DEFAULT_REPLACE_BAD_CHARS,
|
||||
DEFAULT_SKIP_EXISTING,
|
||||
DEFAULT_DELETE_ORIGINAL,
|
||||
DEFAULT_TRANSCODE_TO,
|
||||
)
|
||||
from .core import split_audio
|
||||
|
||||
from .tracklist import read_tracklist, parse_format
|
||||
|
||||
def main():
|
||||
"""Parse arguments and start the splitting process."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Split an audio file into tracks using a tracklist.",
|
||||
epilog="Tracklist format: mm:ss track_name - author_name"
|
||||
)
|
||||
|
||||
# Positional arguments.
|
||||
parser.add_argument('input_file', help='Input audio/video file')
|
||||
parser = argparse.ArgumentParser(description="Split audio file using a tracklist.")
|
||||
parser.add_argument('input_file', help='Input audio file')
|
||||
parser.add_argument('tracklist_file', help='Tracklist file')
|
||||
|
||||
# Optional arguments.
|
||||
parser.add_argument(
|
||||
'--output-dir', '-o',
|
||||
help='Output directory for split tracks (default: <input_basename>_splits)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--format',
|
||||
help='Output container format (e.g., mp3, m4a, mkv, mp4, ogg, opus)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--transcode-to',
|
||||
help='Re-encode audio to this codec (e.g., libmp3lame, aac, libopus)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--drop-video',
|
||||
action='store_true',
|
||||
help='Remove video streams from output'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--drop-subs',
|
||||
action='store_true',
|
||||
help='Remove subtitle streams from output'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--number-tracks',
|
||||
action='store_true',
|
||||
help='Prepend track number to output filenames (convenience; use %%num in template for full control)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--replace-bad-chars',
|
||||
action='store_true',
|
||||
help='Replace problematic characters in filenames (default: off)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--replacement-char',
|
||||
default='_',
|
||||
help='Character used as replacement (default: "_")'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--bad-chars',
|
||||
default=DEFAULT_BAD_CHARS,
|
||||
help='String of characters to replace (default includes space and single quote)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--skip-existing',
|
||||
action='store_true',
|
||||
help='Skip extraction if output file already exists (default: overwrite)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--tracklist-format',
|
||||
default='%ts %tn - %an',
|
||||
help='Format of each line in the tracklist using placeholders: '
|
||||
'%%ts (timestamp), %%tn (track name), %%an (author), %%al (album), '
|
||||
'%%date (date/year), %%ext (file extension). '
|
||||
'Default: "%%ts %%tn - %%an"'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--output-template',
|
||||
default='%an-%tn.%ext',
|
||||
help='Template for output filenames using placeholders: '
|
||||
'%%tn (track name), %%an (author), %%al (album), '
|
||||
'%%date (date/year), %%ext (file extension), %%num (track number). '
|
||||
'Default: "%%an-%%tn.%%ext"'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--dry-run',
|
||||
action='store_true',
|
||||
help='Parse and display the tracklist without splitting any files'
|
||||
)
|
||||
# Output options
|
||||
parser.add_argument('--format', default=DEFAULT_FORMAT, help=f"Output container format (default: {DEFAULT_FORMAT})")
|
||||
parser.add_argument('--transcode-to', default=DEFAULT_TRANSCODE_TO, help="Audio codec to transcode to (default: copy)")
|
||||
parser.add_argument('--drop-video', action='store_true', default=DEFAULT_DROP_VIDEO, help="Drop video streams")
|
||||
parser.add_argument('--drop-subs', action='store_true', default=DEFAULT_DROP_SUBS, help="Drop subtitle streams")
|
||||
|
||||
# Metadata options.
|
||||
parser.add_argument(
|
||||
'--album',
|
||||
help='Set album name in output metadata (overrides parsed %%al and original album)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--comment',
|
||||
help='Explicit comment text (overrides all other comment settings)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--no-comment',
|
||||
action='store_true',
|
||||
help='Explicitly ignore any comment (no comment written)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--comment-stream',
|
||||
type=int,
|
||||
default=None,
|
||||
help='Select comment from a specific stream index (0‑based). Default: first stream with a comment.'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--merge-comments',
|
||||
action='store_true',
|
||||
help='Merge all comments from all streams into one (separated by --comment-separator)'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--comment-separator',
|
||||
default='; ',
|
||||
help='Separator used when merging comments (default: "; ")'
|
||||
)
|
||||
# Filename options
|
||||
parser.add_argument('--number-tracks', action='store_true', default=DEFAULT_NUMBER_TRACKS, help="Prepend track numbers")
|
||||
parser.add_argument('--output-template', default=DEFAULT_OUTPUT_TEMPLATE, help=f"Output filename template (default: {DEFAULT_OUTPUT_TEMPLATE})")
|
||||
parser.add_argument('--replace-bad-chars', action='store_true', default=DEFAULT_REPLACE_BAD_CHARS, help="Replace bad characters")
|
||||
parser.add_argument('--replacement-char', default=DEFAULT_REPLACEMENT_CHAR, help=f"Replacement character (default: {DEFAULT_REPLACEMENT_CHAR})")
|
||||
parser.add_argument('--bad-chars', default=DEFAULT_BAD_CHARS, help=f"Bad characters to replace (default: {DEFAULT_BAD_CHARS})")
|
||||
parser.add_argument('--skip-existing', action='store_true', default=DEFAULT_SKIP_EXISTING, help="Skip existing output files")
|
||||
|
||||
# NEW: Delete original after successful split.
|
||||
parser.add_argument(
|
||||
'--delete-original',
|
||||
action='store_true',
|
||||
help='Delete the original input file after successful splitting (default: keep)'
|
||||
)
|
||||
# Metadata options
|
||||
parser.add_argument('--album', default=DEFAULT_ALBUM, help="Album name")
|
||||
parser.add_argument('--comment', default=DEFAULT_COMMENT, help="Comment")
|
||||
parser.add_argument('--no-comment', action='store_true', default=DEFAULT_NO_COMMENT, help="Ignore comment")
|
||||
parser.add_argument('--comment-stream', type=int, default=DEFAULT_COMMENT_STREAM, help="Comment stream index")
|
||||
parser.add_argument('--merge-comments', action='store_true', default=DEFAULT_MERGE_COMMENTS, help="Merge all comments")
|
||||
parser.add_argument('--comment-separator', default=DEFAULT_COMMENT_SEPARATOR, help=f"Separator for merged comments (default: {DEFAULT_COMMENT_SEPARATOR})")
|
||||
|
||||
# Tracklist format
|
||||
parser.add_argument('--tracklist-format', default=DEFAULT_TRACKLIST_FORMAT, help=f"Tracklist format (default: {DEFAULT_TRACKLIST_FORMAT})")
|
||||
|
||||
# Other
|
||||
parser.add_argument('--delete-original', action='store_true', default=DEFAULT_DELETE_ORIGINAL, help="Delete original file after split")
|
||||
parser.add_argument('--dry-run', action='store_true', help="Parse and display tracklist without splitting")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user