Skip to content

Commit

Permalink
Added non-interactive mode to finalise
Browse files Browse the repository at this point in the history
  • Loading branch information
beveradb committed Jan 22, 2025
1 parent 07ee85b commit a7a96f2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
17 changes: 15 additions & 2 deletions karaoke_prep/karaoke_finalise/karaoke_finalise.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def __init__(
youtube_description_file=None,
rclone_destination=None,
discord_webhook_url=None,
non_interactive=False,
email_template_file=None,
cdg_styles=None,
keep_brand_code=False,
non_interactive=False,
):
self.logger = logging.getLogger(__name__)
self.logger.setLevel(log_level)
Expand Down Expand Up @@ -136,6 +136,10 @@ def __init__(

self.keep_brand_code = keep_brand_code

# Update ffmpeg base command to include -y if non-interactive
if self.non_interactive:
self.ffmpeg_base_command += " -y"

def check_input_files_exist(self, base_name, with_vocals_file, instrumental_audio_file):
self.logger.info(f"Checking required input files exist...")

Expand Down Expand Up @@ -190,13 +194,17 @@ def prepare_output_filenames(self, base_name):
return output_files

def prompt_user_confirmation_or_raise_exception(self, prompt_message, exit_message, allow_empty=False):
if self.non_interactive:
self.logger.info(f"Non-interactive mode, automatically confirming: {prompt_message}")
return True

if not self.prompt_user_bool(prompt_message, allow_empty=allow_empty):
self.logger.error(exit_message)
raise Exception(exit_message)

def prompt_user_bool(self, prompt_message, allow_empty=False):
if self.non_interactive:
self.logger.warning(f"Non-interactive mode, responding True for prompt: {prompt_message}")
self.logger.info(f"Non-interactive mode, automatically answering yes to: {prompt_message}")
return True

options_string = "[y]/n" if allow_empty else "y/[n]"
Expand Down Expand Up @@ -518,6 +526,11 @@ def choose_instrumental_audio_file(self, base_name):
if len(filtered_files) == 1:
return filtered_files[0]

# In non-interactive mode, always choose the first option
if self.non_interactive:
self.logger.info(f"Non-interactive mode, automatically choosing first instrumental file: {filtered_files[0]}")
return filtered_files[0]

# Sort the remaining instrumental options alphabetically
filtered_files.sort(reverse=True)

Expand Down
8 changes: 8 additions & 0 deletions karaoke_prep/utils/finalise_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def main():
help="Optional: Use existing brand code from current directory instead of generating new one (default: disabled). Example: --keep-brand-code",
)

parser.add_argument(
"-y",
"--yes",
action="store_true",
help="Optional: Run in non-interactive mode, assuming yes to all prompts (default: disabled). Example: -y",
)

args = parser.parse_args()

log_level = getattr(logging, args.log_level.upper())
Expand Down Expand Up @@ -177,6 +184,7 @@ def main():
email_template_file=args.email_template_file,
cdg_styles=cdg_styles,
keep_brand_code=args.keep_brand_code,
non_interactive=args.yes,
)

if args.test_email_template:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-prep"
version = "0.36.1"
version = "0.37.0"
description = "Prepare for karaoke video creation, by downloading audio and lyrics for a specified song or playlist from youtube and separating audio stems. After syncing, finalise the video with a title screen!"
authors = ["Andrew Beveridge <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit a7a96f2

Please sign in to comment.