From dfdbd92269721b4b951314f7500401916261d9b8 Mon Sep 17 00:00:00 2001 From: Andrew Beveridge Date: Fri, 17 Jan 2025 01:13:09 -0500 Subject: [PATCH] Added --keep-brand-code param --- .../karaoke_finalise/karaoke_finalise.py | 26 ++++++++++++++++--- karaoke_prep/utils/finalise_cli.py | 7 +++++ pyproject.toml | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/karaoke_prep/karaoke_finalise/karaoke_finalise.py b/karaoke_prep/karaoke_finalise/karaoke_finalise.py index 3c97219..2097cd8 100644 --- a/karaoke_prep/karaoke_finalise/karaoke_finalise.py +++ b/karaoke_prep/karaoke_finalise/karaoke_finalise.py @@ -43,6 +43,7 @@ def __init__( non_interactive=False, email_template_file=None, cdg_styles=None, + keep_brand_code=False, ): self.logger = logging.getLogger(__name__) self.logger.setLevel(log_level) @@ -132,6 +133,8 @@ def __init__( # Determine best available AAC codec self.aac_codec = self.detect_best_aac_codec() + self.keep_brand_code = keep_brand_code + def check_input_files_exist(self, base_name, with_vocals_file, instrumental_audio_file): self.logger.info(f"Checking required input files exist...") @@ -882,6 +885,19 @@ def generate_organised_folder_sharing_link(self): self.logger.error(f"Command output (stderr): {e.stderr}") self.logger.error(f"Full exception: {e}") + def get_existing_brand_code(self): + """Extract brand code from current directory name""" + current_dir = os.path.basename(os.getcwd()) + if " - " not in current_dir: + raise Exception(f"Current directory '{current_dir}' does not match expected format 'BRAND-XXXX - Artist - Title'") + + brand_code = current_dir.split(" - ")[0] + if not brand_code or "-" not in brand_code: + raise Exception(f"Could not extract valid brand code from directory name '{current_dir}'") + + self.logger.info(f"Using existing brand code: {brand_code}") + return brand_code + def execute_optional_features(self, artist, title, base_name, input_files, output_files): self.logger.info(f"Executing optional features...") @@ -900,7 +916,13 @@ def execute_optional_features(self, artist, title, base_name, input_files, outpu self.post_discord_notification() if self.folder_organisation_enabled: - self.brand_code = self.get_next_brand_code() + if self.keep_brand_code: + self.brand_code = self.get_existing_brand_code() + self.new_brand_code_dir = os.path.basename(os.getcwd()) + self.new_brand_code_dir_path = os.getcwd() + else: + self.brand_code = self.get_next_brand_code() + self.move_files_to_brand_code_folder(self.brand_code, artist, title, output_files) if self.public_share_copy_enabled: self.copy_final_files_to_public_share_dirs(self.brand_code, base_name, output_files) @@ -908,8 +930,6 @@ def execute_optional_features(self, artist, title, base_name, input_files, outpu if self.public_share_rclone_enabled: self.sync_public_share_dir_to_rclone_destination() - self.move_files_to_brand_code_folder(self.brand_code, artist, title, output_files) - self.generate_organised_folder_sharing_link() def authenticate_gmail(self): diff --git a/karaoke_prep/utils/finalise_cli.py b/karaoke_prep/utils/finalise_cli.py index 0a6fc02..7336ea5 100644 --- a/karaoke_prep/utils/finalise_cli.py +++ b/karaoke_prep/utils/finalise_cli.py @@ -128,6 +128,12 @@ def main(): help="Optional: Path to JSON file containing CDG style configuration. Required if --enable_cdg is used. Example: --style_params_json='/path/to/cdg_styles.json'", ) + parser.add_argument( + "--keep-brand-code", + action="store_true", + help="Optional: Use existing brand code from current directory instead of generating new one (default: disabled). Example: --keep-brand-code", + ) + args = parser.parse_args() log_level = getattr(logging, args.log_level.upper()) @@ -170,6 +176,7 @@ def main(): discord_webhook_url=args.discord_webhook_url, email_template_file=args.email_template_file, cdg_styles=cdg_styles, + keep_brand_code=args.keep_brand_code, ) if args.test_email_template: diff --git a/pyproject.toml b/pyproject.toml index 751218a..fc72a3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "karaoke-prep" -version = "0.35.5" +version = "0.36.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 "] license = "MIT"