Added new version of remote CLI with (in theory) more feature parity with karaoke-gen

This commit is contained in:
Andrew Beveridge committed 2025-12-08 04:39:50 -05:00
1 parent 729d3ec420
commit 9a6767aee8
9 files changed
+1662 -746

No files matched your search

+175 -45
View File
@@ -1,11 +1,13 @@
"""
File upload route for local file submission.
File upload route for local file submission with style configuration support.
"""
import json
import logging
from fastapi import APIRouter, UploadFile, File, Form, HTTPException, BackgroundTasks
from pathlib import Path
from typing import Optional, List
from backend.models.job import JobCreate
from backend.models.job import JobCreate, JobStatus
from backend.services.job_manager import JobManager
from backend.services.storage_service import StorageService
from backend.services.worker_service import get_worker_service
@@ -19,98 +21,226 @@ storage_service = StorageService()
worker_service = get_worker_service()
# File extension validation
ALLOWED_AUDIO_EXTENSIONS = {'.mp3', '.wav', '.flac', '.m4a', '.ogg', '.aac'}
ALLOWED_IMAGE_EXTENSIONS = {'.png', '.jpg', '.jpeg', '.gif', '.webp'}
ALLOWED_FONT_EXTENSIONS = {'.ttf', '.otf', '.woff', '.woff2'}
@router.post("/jobs/upload")
async def upload_and_create_job(
background_tasks: BackgroundTasks,
file: UploadFile = File(...),
artist: str = Form(...),
title: str = Form(...)
# Required fields
file: UploadFile = File(..., description="Audio file to process"),
artist: str = Form(..., description="Artist name"),
title: str = Form(..., description="Song title"),
# Style configuration files (optional)
style_params: Optional[UploadFile] = File(None, description="Style parameters JSON file"),
style_intro_background: Optional[UploadFile] = File(None, description="Intro/title screen background image"),
style_karaoke_background: Optional[UploadFile] = File(None, description="Karaoke video background image"),
style_end_background: Optional[UploadFile] = File(None, description="End screen background image"),
style_font: Optional[UploadFile] = File(None, description="Font file (TTF/OTF)"),
style_cdg_instrumental_background: Optional[UploadFile] = File(None, description="CDG instrumental background"),
style_cdg_title_background: Optional[UploadFile] = File(None, description="CDG title screen background"),
style_cdg_outro_background: Optional[UploadFile] = File(None, description="CDG outro screen background"),
# Processing options
enable_cdg: bool = Form(True, description="Generate CDG+MP3 package"),
enable_txt: bool = Form(True, description="Generate TXT+MP3 package"),
# Finalisation options
brand_prefix: Optional[str] = Form(None, description="Brand code prefix (e.g., NOMAD)"),
enable_youtube_upload: bool = Form(False, description="Upload to YouTube"),
youtube_description: Optional[str] = Form(None, description="YouTube video description text"),
discord_webhook_url: Optional[str] = Form(None, description="Discord webhook URL for notifications"),
webhook_url: Optional[str] = Form(None, description="Generic webhook URL"),
user_email: Optional[str] = Form(None, description="User email for notifications"),
):
"""
Upload an audio file and create a karaoke generation job.
Upload an audio file and create a karaoke generation job with full style configuration.
This endpoint:
1. Uploads the file to GCS
2. Creates a job in Firestore with the GCS path
3. Triggers the audio and lyrics workers
1. Validates all uploaded files
2. Creates a job in Firestore
3. Uploads all files to GCS (audio, style JSON, images, fonts)
4. Updates job with GCS paths
5. Triggers the audio and lyrics workers
The job will go through the full worker pipeline including human interaction points.
Style Configuration:
- style_params: JSON file with style configuration (fonts, colors, regions)
- style_*_background: Background images for various screens
- style_font: Custom font file
The style_params JSON can reference the uploaded images/fonts by their original
filenames, and the backend will update the paths to GCS locations.
"""
try:
# Validate file type
allowed_extensions = {'.mp3', '.wav', '.flac', '.m4a', '.ogg', '.aac'}
# Validate main audio file type
file_ext = Path(file.filename).suffix.lower()
if file_ext not in allowed_extensions:
if file_ext not in ALLOWED_AUDIO_EXTENSIONS:
raise HTTPException(
status_code=400,
detail=f"Invalid file type. Allowed: {', '.join(allowed_extensions)}"
detail=f"Invalid audio file type '{file_ext}'. Allowed: {', '.join(ALLOWED_AUDIO_EXTENSIONS)}"
)
# Validate style files if provided
if style_params and not style_params.filename.endswith('.json'):
raise HTTPException(status_code=400, detail="Style params must be a JSON file")
for img_file, name in [
(style_intro_background, "intro_background"),
(style_karaoke_background, "karaoke_background"),
(style_end_background, "end_background"),
(style_cdg_instrumental_background, "cdg_instrumental_background"),
(style_cdg_title_background, "cdg_title_background"),
(style_cdg_outro_background, "cdg_outro_background"),
]:
if img_file:
ext = Path(img_file.filename).suffix.lower()
if ext not in ALLOWED_IMAGE_EXTENSIONS:
raise HTTPException(
status_code=400,
detail=f"Invalid image file type '{ext}' for {name}. Allowed: {', '.join(ALLOWED_IMAGE_EXTENSIONS)}"
)
if style_font:
ext = Path(style_font.filename).suffix.lower()
if ext not in ALLOWED_FONT_EXTENSIONS:
raise HTTPException(
status_code=400,
detail=f"Invalid font file type '{ext}'. Allowed: {', '.join(ALLOWED_FONT_EXTENSIONS)}"
)
# Create job first to get job_id
job_create = JobCreate(
artist=artist,
title=title,
filename=file.filename
filename=file.filename,
enable_cdg=enable_cdg,
enable_txt=enable_txt,
brand_prefix=brand_prefix,
enable_youtube_upload=enable_youtube_upload,
youtube_description=youtube_description,
discord_webhook_url=discord_webhook_url,
webhook_url=webhook_url,
user_email=user_email,
)
job = job_manager.create_job(job_create)
job_id = job.job_id
# Upload file to GCS
gcs_path = f"uploads/{job.job_id}/{file.filename}"
logger.info(f"Uploading {file.filename} to GCS: {gcs_path}")
logger.info(f"Created job {job_id} for {artist} - {title}")
# Upload main audio file to GCS
audio_gcs_path = f"uploads/{job_id}/audio/{file.filename}"
logger.info(f"Uploading audio to GCS: {audio_gcs_path}")
storage_service.upload_fileobj(
file.file,
gcs_path,
audio_gcs_path,
content_type=file.content_type or 'audio/flac'
)
# Update job with GCS path BEFORE triggering workers
job_manager.update_job(job.job_id, {
'input_media_gcs_path': gcs_path,
'filename': file.filename
})
# Track style assets
style_assets = {}
# Verify the update by refetching the job
updated_job = job_manager.get_job(job.job_id)
# Upload style files if provided
if style_params:
style_gcs_path = f"uploads/{job_id}/style/style_params.json"
logger.info(f"Uploading style params to GCS: {style_gcs_path}")
storage_service.upload_fileobj(
style_params.file,
style_gcs_path,
content_type='application/json'
)
style_assets['style_params'] = style_gcs_path
# Upload background images
for img_file, asset_key in [
(style_intro_background, "intro_background"),
(style_karaoke_background, "karaoke_background"),
(style_end_background, "end_background"),
(style_cdg_instrumental_background, "cdg_instrumental_background"),
(style_cdg_title_background, "cdg_title_background"),
(style_cdg_outro_background, "cdg_outro_background"),
]:
if img_file:
gcs_path = f"uploads/{job_id}/style/{asset_key}{Path(img_file.filename).suffix.lower()}"
logger.info(f"Uploading {asset_key} to GCS: {gcs_path}")
storage_service.upload_fileobj(
img_file.file,
gcs_path,
content_type=img_file.content_type or 'image/png'
)
style_assets[asset_key] = gcs_path
# Upload font file
if style_font:
font_gcs_path = f"uploads/{job_id}/style/font{Path(style_font.filename).suffix.lower()}"
logger.info(f"Uploading font to GCS: {font_gcs_path}")
storage_service.upload_fileobj(
style_font.file,
font_gcs_path,
content_type='font/ttf'
)
style_assets['font'] = font_gcs_path
# Update job with all GCS paths
update_data = {
'input_media_gcs_path': audio_gcs_path,
'filename': file.filename,
'enable_cdg': enable_cdg,
'enable_txt': enable_txt,
}
if style_assets:
update_data['style_assets'] = style_assets
if 'style_params' in style_assets:
update_data['style_params_gcs_path'] = style_assets['style_params']
if brand_prefix:
update_data['brand_prefix'] = brand_prefix
if discord_webhook_url:
update_data['discord_webhook_url'] = discord_webhook_url
if youtube_description:
update_data['youtube_description_template'] = youtube_description
job_manager.update_job(job_id, update_data)
# Verify the update
updated_job = job_manager.get_job(job_id)
if not hasattr(updated_job, 'input_media_gcs_path') or not updated_job.input_media_gcs_path:
# Wait a moment for Firestore consistency
import asyncio
await asyncio.sleep(0.5)
updated_job = job_manager.get_job(job.job_id)
updated_job = job_manager.get_job(job_id)
if not hasattr(updated_job, 'input_media_gcs_path') or not updated_job.input_media_gcs_path:
raise HTTPException(
status_code=500,
detail="Failed to update job with GCS path"
detail="Failed to update job with GCS paths"
)
logger.info(f"File uploaded successfully for job {job.job_id}, GCS path: {gcs_path}")
logger.info(f"All files uploaded for job {job_id}")
if style_assets:
logger.info(f"Style assets: {list(style_assets.keys())}")
# Transition job to DOWNLOADING state before triggering workers
# This is required by the state machine: PENDING -> DOWNLOADING -> SEPARATING_STAGE1/TRANSCRIBING
from backend.models.job import JobStatus
# Transition job to DOWNLOADING state
job_manager.transition_to_state(
job_id=job.job_id,
job_id=job_id,
new_status=JobStatus.DOWNLOADING,
progress=5,
message="File uploaded, preparing to process"
message="Files uploaded, preparing to process"
)
# Trigger both workers in parallel using background tasks
# They run independently and coordinate via job state
background_tasks.add_task(worker_service.trigger_audio_worker, job.job_id)
background_tasks.add_task(worker_service.trigger_lyrics_worker, job.job_id)
# Trigger workers
background_tasks.add_task(worker_service.trigger_audio_worker, job_id)
background_tasks.add_task(worker_service.trigger_lyrics_worker, job_id)
return {
"status": "success",
"job_id": job.job_id,
"message": "File uploaded successfully. Processing started.",
"filename": file.filename
"job_id": job_id,
"message": "Files uploaded successfully. Processing started.",
"filename": file.filename,
"style_assets_uploaded": list(style_assets.keys()) if style_assets else []
}
except HTTPException:
raise
except Exception as e:
logger.error(f"Error uploading file: {e}", exc_info=True)
logger.error(f"Error uploading files: {e}", exc_info=True)
raise HTTPException(status_code=500, detail=str(e))
+31
View File
@@ -170,6 +170,27 @@ class Job(BaseModel):
webhook_url: Optional[str] = None # Webhook for notifications
user_email: Optional[str] = None # Email for notifications
# Style configuration (uploaded files)
style_params_gcs_path: Optional[str] = None # GCS path to style_params.json
style_assets: Dict[str, str] = Field(default_factory=dict)
"""
GCS paths to style asset files:
{
"intro_background": "gs://bucket/jobs/{job_id}/style/intro_bg.png",
"karaoke_background": "gs://bucket/jobs/{job_id}/style/karaoke_bg.png",
"end_background": "gs://bucket/jobs/{job_id}/style/end_bg.png",
"font": "gs://bucket/jobs/{job_id}/style/font.ttf",
"cdg_instrumental_background": "gs://bucket/jobs/{job_id}/style/cdg_instr.png",
"cdg_title_background": "gs://bucket/jobs/{job_id}/style/cdg_title.png",
"cdg_outro_background": "gs://bucket/jobs/{job_id}/style/cdg_outro.png"
}
"""
# Finalisation configuration
brand_prefix: Optional[str] = None # Brand code prefix (e.g., "NOMAD")
discord_webhook_url: Optional[str] = None # Discord notification webhook
youtube_description_template: Optional[str] = None # YouTube description template text
# Processing state
track_output_dir: Optional[str] = None # Local output directory (temp)
audio_hash: Optional[str] = None # Hash for deduplication
@@ -288,6 +309,7 @@ class JobCreate(BaseModel):
url: Optional[str] = None
artist: Optional[str] = None
title: Optional[str] = None
filename: Optional[str] = None # Original uploaded filename
# Optional preferences
enable_cdg: bool = True
@@ -297,6 +319,15 @@ class JobCreate(BaseModel):
webhook_url: Optional[str] = None
user_email: Optional[str] = None
# Style configuration (will be populated after file upload)
style_params_gcs_path: Optional[str] = None
style_assets: Dict[str, str] = Field(default_factory=dict)
# Finalisation configuration
brand_prefix: Optional[str] = None
discord_webhook_url: Optional[str] = None
youtube_description_template: Optional[str] = None
@validator('url', 'artist', 'title')
def validate_inputs(cls, v):
"""Validate string inputs are not empty."""
+32 -70
View File
@@ -34,6 +34,7 @@ from backend.models.job import JobStatus
from backend.services.job_manager import JobManager
from backend.services.storage_service import StorageService
from backend.config import get_settings
from backend.workers.style_helper import load_style_config, StyleConfig
# Import from karaoke_gen package
from karaoke_gen.video_generator import VideoGenerator
@@ -83,25 +84,34 @@ async def generate_screens(job_id: str) -> bool:
message="Generating title and end screens"
)
# Load style configuration (downloads assets from GCS if available)
style_config = await load_style_config(job, storage, temp_dir)
if style_config.has_custom_styles():
logger.info(f"Job {job_id}: Using custom style configuration")
else:
logger.info(f"Job {job_id}: Using default style configuration")
# Initialize video generator
video_generator = _create_video_generator(temp_dir)
# Generate title screen
# Generate title screen with style config
title_screen_path = await _generate_title_screen(
job_id=job_id,
job=job,
video_generator=video_generator,
style_config=style_config,
temp_dir=temp_dir
)
if not title_screen_path:
raise Exception("Title screen generation failed")
# Generate end screen
# Generate end screen with style config
end_screen_path = await _generate_end_screen(
job_id=job_id,
job=job,
video_generator=video_generator,
style_config=style_config,
temp_dir=temp_dir
)
@@ -206,72 +216,15 @@ def _create_video_generator(temp_dir: str) -> VideoGenerator:
)
def _get_title_format() -> Dict[str, Any]:
"""
Get title screen format parameters.
Single Responsibility: Style configuration separated.
Uses the same defaults as karaoke_gen.config.setup_title_format().
Returns:
Title format dict
"""
return {
"background_color": "#000000",
"background_image": None,
"font": None, # Will use default font
"title_region": "200,700,3440,400", # x,y,width,height
"title_color": "#FFFFFF",
"title_gradient": None,
"title_text_transform": "none",
"artist_region": "200,1100,3440,300",
"artist_color": "#CCCCCC",
"artist_gradient": None,
"artist_text_transform": "none",
"extra_text": None,
"extra_text_region": None,
"extra_text_color": "#FFFFFF",
"extra_text_gradient": None,
}
def _get_end_format() -> Dict[str, Any]:
"""
Get end screen format parameters.
Single Responsibility: Style configuration separated.
Uses the same defaults as karaoke_gen.config.setup_end_format().
Returns:
End format dict
"""
return {
"background_color": "#000000",
"background_image": None,
"font": None, # Will use default font
"title_region": "200,900,3440,400", # Centered on screen
"title_color": "#FFFFFF",
"title_gradient": None,
"title_text_transform": "none",
"artist_region": None, # No artist on end screen by default
"artist_color": "#CCCCCC",
"artist_gradient": None,
"artist_text_transform": "none",
"extra_text": "Thank you for singing!",
"extra_text_region": "200,1300,3440,200",
"extra_text_color": "#AAAAAA",
"extra_text_gradient": None,
}
async def _generate_title_screen(
job_id: str,
job,
video_generator: VideoGenerator,
style_config: StyleConfig,
temp_dir: str
) -> Optional[str]:
"""
Generate title screen video.
Generate title screen video with custom style configuration.
Single Responsibility: Only handles title screen generation.
@@ -279,6 +232,7 @@ async def _generate_title_screen(
job_id: Job ID
job: Job object with artist/title
video_generator: Video generator instance
style_config: Style configuration with formats and assets
temp_dir: Temporary directory
Returns:
@@ -292,8 +246,11 @@ async def _generate_title_screen(
output_image_filepath_noext = os.path.join(temp_dir, f"{artist_title} (Title)")
output_video_filepath = os.path.join(temp_dir, f"{artist_title} (Title).mov")
# Get title format settings
title_format = _get_title_format()
# Get title format settings from style config
title_format = style_config.get_intro_format()
intro_duration = style_config.intro_video_duration
logger.info(f"Job {job_id}: Title format - bg_image: {title_format.get('background_image')}, font: {title_format.get('font')}")
# Generate title screen (synchronous method)
video_generator.create_title_video(
@@ -302,8 +259,8 @@ async def _generate_title_screen(
format=title_format,
output_image_filepath_noext=output_image_filepath_noext,
output_video_filepath=output_video_filepath,
existing_title_image=None,
intro_video_duration=5 # 5 second intro
existing_title_image=title_format.get('existing_image'),
intro_video_duration=intro_duration
)
if os.path.exists(output_video_filepath):
@@ -322,10 +279,11 @@ async def _generate_end_screen(
job_id: str,
job,
video_generator: VideoGenerator,
style_config: StyleConfig,
temp_dir: str
) -> Optional[str]:
"""
Generate end screen video.
Generate end screen video with custom style configuration.
Single Responsibility: Only handles end screen generation.
@@ -333,6 +291,7 @@ async def _generate_end_screen(
job_id: Job ID
job: Job object with artist/title
video_generator: Video generator instance
style_config: Style configuration with formats and assets
temp_dir: Temporary directory
Returns:
@@ -346,8 +305,11 @@ async def _generate_end_screen(
output_image_filepath_noext = os.path.join(temp_dir, f"{artist_title} (End)")
output_video_filepath = os.path.join(temp_dir, f"{artist_title} (End).mov")
# Get end format settings
end_format = _get_end_format()
# Get end format settings from style config
end_format = style_config.get_end_format()
end_duration = style_config.end_video_duration
logger.info(f"Job {job_id}: End format - bg_image: {end_format.get('background_image')}, font: {end_format.get('font')}")
# Generate end screen (synchronous method)
video_generator.create_end_video(
@@ -356,8 +318,8 @@ async def _generate_end_screen(
format=end_format,
output_image_filepath_noext=output_image_filepath_noext,
output_video_filepath=output_video_filepath,
existing_end_image=None,
end_video_duration=5 # 5 second outro
existing_end_image=end_format.get('existing_image'),
end_video_duration=end_duration
)
if os.path.exists(output_video_filepath):
+282
View File
@@ -0,0 +1,282 @@
"""
Style configuration helper for workers.
Downloads and processes style assets from GCS, making them available
for screen generation, video rendering, and CDG generation.
"""
import json
import logging
import os
import tempfile
from pathlib import Path
from typing import Dict, Any, Optional, Tuple
from backend.services.storage_service import StorageService
logger = logging.getLogger(__name__)
# Default style configuration (used when no custom style is provided)
DEFAULT_INTRO_FORMAT = {
"video_duration": 5,
"existing_image": None,
"background_color": "#000000",
"background_image": None,
"font": None,
"artist_color": "#CCCCCC",
"artist_text_transform": "none",
"title_color": "#FFFFFF",
"title_gradient": None,
"title_text_transform": "none",
"title_region": "200,700,3440,400",
"artist_region": "200,1100,3440,300",
"artist_gradient": None,
"extra_text": None,
"extra_text_color": "#FFFFFF",
"extra_text_gradient": None,
"extra_text_region": None,
"extra_text_text_transform": "none",
}
DEFAULT_END_FORMAT = {
"video_duration": 5,
"existing_image": None,
"background_color": "#000000",
"background_image": None,
"font": None,
"artist_color": "#CCCCCC",
"artist_text_transform": "none",
"title_color": "#FFFFFF",
"title_gradient": None,
"title_text_transform": "none",
"title_region": "200,900,3440,400",
"artist_region": None,
"artist_gradient": None,
"extra_text": "Thank you for singing!",
"extra_text_color": "#AAAAAA",
"extra_text_region": "200,1300,3440,200",
"extra_text_text_transform": "none",
"extra_text_gradient": None,
}
DEFAULT_KARAOKE_FORMAT = {
"background_image": None,
"background_color": "#000000",
"font_path": None,
"font": None,
"ass_name": "Default",
"primary_color": "255, 255, 255, 255",
"secondary_color": "255, 255, 0, 255",
"outline_color": "0, 0, 0, 255",
"back_color": "0, 0, 0, 128",
"bold": False,
"italic": False,
"underline": False,
"strike_out": False,
"scale_x": 100,
"scale_y": 100,
"spacing": 0,
"angle": 0.0,
"border_style": 1,
"outline": 2,
"shadow": 1,
"margin_l": 0,
"margin_r": 0,
"margin_v": 50,
"encoding": 0,
}
class StyleConfig:
"""
Manages style configuration for a job.
Downloads style assets from GCS and provides processed style parameters
with local file paths for use by video generators.
"""
def __init__(self, job, storage: StorageService, temp_dir: str):
"""
Initialize style configuration.
Args:
job: Job object with style_assets and style_params_gcs_path
storage: Storage service for downloading files
temp_dir: Temporary directory for downloaded assets
"""
self.job = job
self.storage = storage
self.temp_dir = temp_dir
self.style_dir = os.path.join(temp_dir, "style")
os.makedirs(self.style_dir, exist_ok=True)
self._style_params: Optional[Dict[str, Any]] = None
self._local_assets: Dict[str, str] = {}
self._loaded = False
async def load(self) -> None:
"""
Download and parse style configuration from GCS.
Downloads:
- style_params.json (if exists)
- All style assets (backgrounds, fonts)
After loading, style params will have local file paths.
"""
if self._loaded:
return
logger.info(f"Loading style configuration for job {self.job.job_id}")
# Download style assets
style_assets = getattr(self.job, 'style_assets', {}) or {}
for asset_key, gcs_path in style_assets.items():
if gcs_path:
try:
local_path = await self._download_asset(asset_key, gcs_path)
if local_path:
self._local_assets[asset_key] = local_path
logger.info(f"Downloaded style asset '{asset_key}' to {local_path}")
except Exception as e:
logger.warning(f"Failed to download style asset '{asset_key}': {e}")
# Load and parse style_params.json
if 'style_params' in self._local_assets:
try:
with open(self._local_assets['style_params'], 'r') as f:
self._style_params = json.load(f)
logger.info(f"Loaded style params from {self._local_assets['style_params']}")
# Update file paths in style params to use local downloaded files
self._update_style_paths()
except Exception as e:
logger.warning(f"Failed to parse style_params.json: {e}")
self._style_params = None
self._loaded = True
async def _download_asset(self, asset_key: str, gcs_path: str) -> Optional[str]:
"""Download a single asset from GCS."""
try:
# Determine local filename
ext = Path(gcs_path).suffix
local_path = os.path.join(self.style_dir, f"{asset_key}{ext}")
# Download from GCS
self.storage.download_file(gcs_path, local_path)
if os.path.exists(local_path):
return local_path
return None
except Exception as e:
logger.error(f"Error downloading asset {asset_key}: {e}")
return None
def _update_style_paths(self) -> None:
"""
Update file paths in style params to use downloaded local files.
The uploaded style_params.json may have paths like "/tmp/font.ttf"
which don't exist on the Cloud Run instance. We need to replace
these with the actual downloaded file paths.
"""
if not self._style_params:
return
# Map of style param keys to asset keys
path_mappings = {
('intro', 'background_image'): 'intro_background',
('intro', 'font'): 'font',
('karaoke', 'background_image'): 'karaoke_background',
('karaoke', 'font_path'): 'font',
('end', 'background_image'): 'end_background',
('end', 'font'): 'font',
('cdg', 'font_path'): 'font',
('cdg', 'instrumental_background'): 'cdg_instrumental_background',
('cdg', 'title_screen_background'): 'cdg_title_background',
('cdg', 'outro_background'): 'cdg_outro_background',
}
for (section, key), asset_key in path_mappings.items():
if section in self._style_params and key in self._style_params[section]:
if asset_key in self._local_assets:
old_path = self._style_params[section][key]
self._style_params[section][key] = self._local_assets[asset_key]
logger.debug(f"Updated {section}.{key}: {old_path} -> {self._local_assets[asset_key]}")
def get_intro_format(self) -> Dict[str, Any]:
"""Get title/intro screen format, with custom styles if available."""
if self._style_params and 'intro' in self._style_params:
# Merge custom params with defaults
format_dict = DEFAULT_INTRO_FORMAT.copy()
format_dict.update(self._style_params['intro'])
return format_dict
return DEFAULT_INTRO_FORMAT.copy()
def get_end_format(self) -> Dict[str, Any]:
"""Get end screen format, with custom styles if available."""
if self._style_params and 'end' in self._style_params:
format_dict = DEFAULT_END_FORMAT.copy()
format_dict.update(self._style_params['end'])
return format_dict
return DEFAULT_END_FORMAT.copy()
def get_karaoke_format(self) -> Dict[str, Any]:
"""Get karaoke video format, with custom styles if available."""
if self._style_params and 'karaoke' in self._style_params:
format_dict = DEFAULT_KARAOKE_FORMAT.copy()
format_dict.update(self._style_params['karaoke'])
return format_dict
return DEFAULT_KARAOKE_FORMAT.copy()
def get_cdg_styles(self) -> Optional[Dict[str, Any]]:
"""Get CDG generation styles if available."""
if self._style_params and 'cdg' in self._style_params:
return self._style_params['cdg']
return None
def get_style_params_path(self) -> Optional[str]:
"""Get local path to style_params.json if available."""
return self._local_assets.get('style_params')
def get_local_asset_path(self, asset_key: str) -> Optional[str]:
"""Get local path for a specific asset."""
return self._local_assets.get(asset_key)
def has_custom_styles(self) -> bool:
"""Check if custom styles were provided."""
return self._style_params is not None
@property
def intro_video_duration(self) -> int:
"""Get intro video duration in seconds."""
if self._style_params and 'intro' in self._style_params:
return self._style_params['intro'].get('video_duration', 5)
return 5
@property
def end_video_duration(self) -> int:
"""Get end video duration in seconds."""
if self._style_params and 'end' in self._style_params:
return self._style_params['end'].get('video_duration', 5)
return 5
async def load_style_config(job, storage: StorageService, temp_dir: str) -> StyleConfig:
"""
Helper function to load style configuration for a job.
Args:
job: Job object
storage: Storage service
temp_dir: Temporary directory
Returns:
Loaded StyleConfig instance
"""
config = StyleConfig(job, storage, temp_dir)
await config.load()
return config
+355
View File
@@ -0,0 +1,355 @@
# CLI Feature Parity: karaoke-gen vs karaoke-gen-remote
This document tracks the feature parity between the local `karaoke-gen` CLI and the cloud-hosted `karaoke-gen-remote` CLI.
**Last Updated:** 2025-12-08
## Summary
| Category | karaoke-gen (Local) | karaoke-gen-remote (Cloud) | Status |
|----------|---------------------|---------------------------|--------|
| **Core Workflow** | ✅ Full | 🔄 Partial | In Progress |
| **Input Sources** | ✅ Files, URLs, YouTube | ⚠️ Files only | Limited |
| **Human Interactions** | ✅ Full | ✅ Full | Complete |
| **Style Configuration** | ✅ Full | ✅ Implemented | Complete |
| **Output Formats** | ✅ Full (6 formats) | 🔄 Partial | In Progress |
| **Finalisation Options** | ✅ Full | 🔄 Partial | In Progress |
| **Distribution** | ✅ Full | 🔄 Partial (Discord) | In Progress |
---
## Feature Comparison
### ✅ Working in Both CLIs
| Feature | Description | Notes |
|---------|-------------|-------|
| File upload | Submit local audio files | Remote supports: mp3, wav, flac, m4a, ogg, aac |
| Audio separation | Two-stage GPU separation via Modal | Same Modal API used by both |
| Lyrics transcription | AudioShake API transcription | Same AudioShake API |
| Auto-correction | Automatic lyrics correction | Uses LyricsTranscriber library |
| Human review | Browser-based lyrics review UI | Remote uses separate React UI |
| Instrumental selection | Choose clean vs with-backing-vocals | Interactive prompt in both |
| Job monitoring | Track progress to completion | Remote has colored CLI output |
| Resume jobs | Continue interrupted jobs | `--resume <job_id>` in remote |
### ⚠️ Partial/Limited in karaoke-gen-remote
| Feature | Local Behavior | Remote Behavior | TODO |
|---------|----------------|-----------------|------|
| **YouTube URL input** | Downloads and processes | ❌ Not supported | Backend needs URL download worker |
| **YouTube search** | Searches by artist+title | ❌ Not supported | Requires YouTube API integration |
| **Folder batch processing** | Process entire folder | ❌ Not supported | Backend needs batch job support |
| **Playlist processing** | Process YouTube playlists | ❌ Not supported | Backend needs playlist parsing |
| **Output formats** | 6 video formats generated | 🔄 Partial | Backend generates limited formats |
| **Title/End screens** | Custom styles from JSON | ⚠️ Default styles only | Backend needs style parameter support |
### ✅ Newly Implemented in karaoke-gen-remote
| Feature | Local CLI Flag | Description | Notes |
|---------|---------------|-------------|-------|
| **Style customization** | `--style_params_json` | Custom fonts, colors, backgrounds | Uploads JSON + all referenced files |
| **CDG generation** | `--enable_cdg` | Generate CDG+MP3 ZIP | Backend support added |
| **TXT generation** | `--enable_txt` | Generate TXT+MP3 ZIP | Backend support added |
| **Brand code** | `--brand_prefix` | Sequential brand numbering | Stored in job, backend TODO |
| **Discord notification** | `--discord_webhook_url` | Send Discord notification | Stored in job, backend TODO |
| **YouTube description** | `--youtube_description_file` | YouTube video description | Uploaded as text |
### ❌ Not Yet Implemented in karaoke-gen-remote
| Feature | Local CLI Flag | Description | Priority |
|---------|---------------|-------------|----------|
| **--prep-only** | `--prep-only` | Run only preparation phase | Medium |
| **--finalise-only** | `--finalise-only` | Run only finalisation phase | Low |
| **--edit-lyrics** | `--edit-lyrics` | Re-edit lyrics of existing track | Low |
| **--skip-transcription** | `--skip-transcription` | Skip lyrics (manual sync later) | Low |
| **--skip-separation** | `--skip-separation` | Skip audio separation | Low |
| **--skip-lyrics** | `--skip-lyrics` | Skip lyrics entirely | Low |
| **--lyrics-only** | `--lyrics-only` | Only process lyrics | Low |
| **--existing_instrumental** | `--existing_instrumental` | Use pre-separated instrumental | Medium |
| **--lyrics_file** | `--lyrics_file` | Use local lyrics file | Medium |
| **--background_video** | `--background_video` | Video background instead of image | Low |
| **Folder organization** | `--organised_dir` | Move to organized location (local-only) | N/A |
| **YouTube upload** | `--youtube_client_secrets_file` | Upload to YouTube | High |
| **Email draft** | `--email_template_file` | Create Gmail draft | Low |
| **rclone sync** | `--rclone_destination` | Sync to cloud storage (local-only) | N/A |
| **Style overrides** | `--style_override` | Override individual style params | Low |
---
## Detailed TODO List
### Phase 1: Core Feature Parity (High Priority)
These features are essential for basic usage parity.
#### 1.1 YouTube URL Support
**Status:** ❌ Not Started
**Effort:** Medium (2-3 days)
**Description:** Allow users to submit YouTube URLs instead of uploading files.
**Backend Changes:**
- [ ] Add URL input to job creation endpoint
- [ ] Create download worker that uses yt-dlp
- [ ] Handle rate limiting and geo-restrictions
- [ ] Store downloaded file in GCS
**CLI Changes:**
- [ ] Accept URL as first positional argument (already in parser)
- [ ] Submit URL to backend instead of uploading file
---
#### 1.2 Complete Output Formats
**Status:** 🔄 Partial
**Effort:** Medium (2-3 days)
**Description:** Generate all 6 output formats that local CLI produces.
**Required Formats:**
- [ ] Lossless 4K MP4 (PCM audio)
- [ ] Lossless 4K MKV (FLAC audio)
- [ ] Lossy 4K MP4 (AAC audio)
- [ ] Lossy 720p MP4 (AAC audio)
- [ ] CDG+MP3 ZIP
- [ ] TXT+MP3 ZIP
**Backend Changes:**
- [ ] Video worker to generate all 4 video formats
- [ ] Add CDG generation worker/step
- [ ] Add TXT generation worker/step
- [ ] Store all formats in GCS with proper naming
---
#### 1.3 YouTube Upload Integration
**Status:** ❌ Not Started
**Effort:** High (3-5 days)
**Description:** Automatically upload completed videos to YouTube.
**Backend Changes:**
- [ ] Secure credential storage in Secret Manager
- [ ] YouTube Data API v3 integration
- [ ] Upload worker with retry logic
- [ ] Thumbnail upload
- [ ] Store YouTube URL in job metadata
**CLI Changes:**
- [ ] Accept `--youtube_client_secrets_file` (already in parser)
- [ ] Display YouTube URL on completion
---
### Phase 2: Enhanced Features (Medium Priority)
#### 2.1 Custom Style Parameters
**Status:** ❌ Not Started
**Effort:** Medium (2-3 days)
**Description:** Support custom fonts, colors, and backgrounds.
**Backend Changes:**
- [ ] Accept style_params_json in job creation
- [ ] Upload style JSON to GCS
- [ ] Pass style params to title/end screen generator
- [ ] Pass style params to lyrics video generator
**CLI Changes:**
- [ ] Upload style JSON file with job submission
---
#### 2.2 Existing Instrumental Support
**Status:** ❌ Not Started
**Effort:** Low (1 day)
**Description:** Skip separation when user provides instrumental.
**Backend Changes:**
- [ ] Accept instrumental file upload
- [ ] Store instrumental in GCS
- [ ] Skip audio separation worker when instrumental provided
- [ ] Use provided instrumental in finalization
**CLI Changes:**
- [ ] Accept `--existing_instrumental` path
- [ ] Upload instrumental file alongside main audio
---
#### 2.3 Custom Lyrics File
**Status:** ❌ Not Started
**Effort:** Low (1 day)
**Description:** Use user-provided lyrics instead of fetching.
**Backend Changes:**
- [ ] Accept lyrics file upload
- [ ] Store lyrics in GCS
- [ ] Pass lyrics file to transcriber for alignment only
**CLI Changes:**
- [ ] Accept `--lyrics_file` path
- [ ] Upload lyrics file with job submission
---
#### 2.4 CDG/TXT Generation
**Status:** ❌ Not Started
**Effort:** Medium (2-3 days)
**Description:** Generate CDG and TXT karaoke formats.
**Backend Changes:**
- [ ] Integrate CDGGenerator from lyrics_transcriber
- [ ] Generate MP3 from instrumental FLAC
- [ ] Create ZIP packages
- [ ] Add job option flags: enable_cdg, enable_txt
**CLI Changes:**
- [ ] Accept `--enable_cdg` and `--enable_txt` flags
- [ ] Download CDG/TXT ZIPs on completion
---
### Phase 3: Distribution Features (Lower Priority)
#### 3.1 Discord Notification
**Status:** ❌ Not Started
**Effort:** Low (1 day)
**Backend Changes:**
- [ ] Accept webhook URL in job creation
- [ ] Send notification on completion
- [ ] Include job details and YouTube URL
---
#### 3.2 Email Draft Creation
**Status:** ❌ Not Started
**Effort:** Medium (2-3 days)
**Backend Changes:**
- [ ] Gmail API integration
- [ ] Template file handling
- [ ] Draft creation with placeholders
---
#### 3.3 Brand Code Organization
**Status:** ❌ Not Started
**Effort:** Low (1-2 days)
**Backend Changes:**
- [ ] Sequential brand code tracking in Firestore
- [ ] Rename output files with brand code
- [ ] Support `--brand_prefix` option
---
### Phase 4: Advanced Workflows (Low Priority)
#### 4.1 Prep-Only Mode
**Status:** ❌ Not Started
**Effort:** Low (1 day)
**Backend Changes:**
- [ ] Add job option to stop after screens generation
- [ ] Return job in "prep_complete" state
---
#### 4.2 Edit Lyrics Mode
**Status:** ❌ Not Started
**Effort:** Medium (2-3 days)
**Backend Changes:**
- [ ] API to re-open review for existing job
- [ ] Backup existing outputs
- [ ] Re-run lyrics processing only
- [ ] Re-generate affected outputs
---
#### 4.3 Batch Processing
**Status:** ❌ Not Started
**Effort:** High (3-5 days)
**Backend Changes:**
- [ ] Batch job creation endpoint
- [ ] Queue management for multiple jobs
- [ ] Aggregate progress reporting
- [ ] Batch completion notification
---
## Implementation Order Recommendation
Based on user value and effort, recommended implementation order:
### Sprint 1 (Week 1-2)
1. **Complete Output Formats** - Users need all video formats
2. **CDG/TXT Generation** - Core karaoke format support
### Sprint 2 (Week 2-3)
3. **YouTube URL Support** - Major convenience feature
4. **Custom Style Parameters** - Important for branding
### Sprint 3 (Week 3-4)
5. **YouTube Upload** - Automation for distribution
6. **Existing Instrumental** - Power user feature
### Sprint 4 (Week 4+)
7. **Custom Lyrics File** - Power user feature
8. **Discord/Email Notifications** - Nice to have
9. **Brand Code Organization** - Nice to have
10. **Advanced Workflows** - Edge cases
---
## Architecture Notes
### File Handling Differences
| Aspect | Local CLI | Remote CLI |
|--------|-----------|------------|
| Input location | Local filesystem | Uploaded to GCS |
| Working directory | Local temp dir | Cloud Run temp dir |
| Output storage | Local filesystem | GCS bucket |
| Output access | Direct file access | gsutil download / signed URLs |
| Cleanup | Manual | GCS lifecycle policies |
### Authentication Differences
| Aspect | Local CLI | Remote CLI |
|--------|-----------|------------|
| API auth | Environment variables | gcloud identity token |
| YouTube | Local OAuth flow | Server-side OAuth (TBD) |
| Gmail | Local OAuth flow | Server-side OAuth (TBD) |
| GCS | Not needed | Service account |
### Human Interaction Differences
| Interaction | Local CLI | Remote CLI |
|-------------|-----------|------------|
| Lyrics review | https://lyrics.nomadkaraoke.com (hosted UI, can override with `LYRICS_REVIEW_UI_URL=local`) | https://lyrics.nomadkaraoke.com (hosted UI) |
| Instrumental selection | CLI prompt | CLI prompt (same) |
| Approval prompts | CLI prompt | N/A (async) |
**Note:** Both CLIs now default to the hosted review UI at `https://lyrics.nomadkaraoke.com`. The local CLI starts a local API server on port 8000, and the hosted UI connects to it. Set `LYRICS_REVIEW_UI_URL=local` to use the bundled local frontend instead.
---
## Testing Checklist
When adding new features, ensure:
- [ ] Feature works with both small (<1 min) and large (>5 min) audio files
- [ ] Error handling for network failures
- [ ] Progress updates visible in CLI
- [ ] Output files downloadable via gsutil
- [ ] Job state persists across CLI interruptions
- [ ] Resume (`--resume`) works after feature is used
---
## Related Documentation
- [KARAOKE-GEN-CLI-WORKFLOW.md](../01-reference/KARAOKE-GEN-CLI-WORKFLOW.md) - Full local CLI workflow
- [CURRENT-STATUS.md](./CURRENT-STATUS.md) - Backend implementation status
- [WORKER-IMPLEMENTATION-PLAN.md](./WORKER-IMPLEMENTATION-PLAN.md) - Worker architecture
+353
View File
@@ -0,0 +1,353 @@
#!/usr/bin/env python
"""
Shared CLI argument parser for karaoke-gen and karaoke-gen-remote.
This module provides a common argument parser to ensure feature parity.
"""
import argparse
import logging
import os
import tempfile
from importlib import metadata
def get_version() -> str:
"""Get package version."""
try:
return metadata.version("karaoke-gen")
except metadata.PackageNotFoundError:
return "unknown"
def create_parser(prog: str = "karaoke-gen") -> argparse.ArgumentParser:
"""
Create the argument parser for karaoke-gen CLIs.
Args:
prog: Program name for the parser
Returns:
Configured ArgumentParser instance
"""
parser = argparse.ArgumentParser(
prog=prog,
description="Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video.",
formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, max_help_position=54),
)
# Basic information
parser.add_argument(
"args",
nargs="*",
help="[Media or playlist URL] [Artist] [Title] of song to process. If URL is provided, Artist and Title are optional but increase chance of fetching the correct lyrics. If Artist and Title are provided with no URL, the top YouTube search result will be fetched.",
)
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {get_version()}")
# Workflow control
workflow_group = parser.add_argument_group("Workflow Control")
workflow_group.add_argument(
"--prep-only",
action="store_true",
help="Only run the preparation phase (download audio, lyrics, separate stems, create title screens). Example: --prep-only",
)
workflow_group.add_argument(
"--finalise-only",
action="store_true",
help="Only run the finalisation phase (remux, encode, organize). Must be run in a directory prepared by the prep phase. Example: --finalise-only",
)
workflow_group.add_argument(
"--skip-transcription",
action="store_true",
help="Skip automatic lyrics transcription/synchronization. Use this to fall back to manual syncing. Example: --skip-transcription",
)
workflow_group.add_argument(
"--skip-separation",
action="store_true",
help="Skip audio separation process. Example: --skip-separation",
)
workflow_group.add_argument(
"--skip-lyrics",
action="store_true",
help="Skip fetching and processing lyrics. Example: --skip-lyrics",
)
workflow_group.add_argument(
"--lyrics-only",
action="store_true",
help="Only process lyrics, skipping audio separation and title/end screen generation. Example: --lyrics-only",
)
workflow_group.add_argument(
"--edit-lyrics",
action="store_true",
help="Edit lyrics of an existing track. This will backup existing outputs, re-run the lyrics transcription process, and update all outputs. Example: --edit-lyrics",
)
workflow_group.add_argument(
"--resume", "-r",
metavar="JOB_ID",
help="Resume monitoring an existing job (remote mode only). Example: --resume abc12345",
)
# Logging & Debugging
debug_group = parser.add_argument_group("Logging & Debugging")
debug_group.add_argument(
"--log_level",
default="info",
help="Optional: logging level, e.g. info, debug, warning (default: %(default)s). Example: --log_level=debug",
)
debug_group.add_argument(
"--dry_run",
action="store_true",
help="Optional: perform a dry run without making any changes. Example: --dry_run",
)
debug_group.add_argument(
"--render_bounding_boxes",
action="store_true",
help="Optional: render bounding boxes around text regions for debugging. Example: --render_bounding_boxes",
)
# Input/Output Configuration
io_group = parser.add_argument_group("Input/Output Configuration")
io_group.add_argument(
"--filename_pattern",
help="Required if processing a folder: Python regex pattern to extract track names from filenames. Must contain a named group 'title'. Example: --filename_pattern='(?P<index>\\d+) - (?P<title>.+).mp3'",
)
io_group.add_argument(
"--output_dir",
default=".",
help="Optional: directory to write output files (default: <current dir>). Example: --output_dir=/app/karaoke",
)
io_group.add_argument(
"--no_track_subfolders",
action="store_false",
dest="no_track_subfolders",
help="Optional: do NOT create a named subfolder for each track. Example: --no_track_subfolders",
)
io_group.add_argument(
"--lossless_output_format",
default="FLAC",
help="Optional: lossless output format for separated audio (default: FLAC). Example: --lossless_output_format=WAV",
)
io_group.add_argument(
"--output_png",
type=lambda x: (str(x).lower() == "true"),
default=True,
help="Optional: output PNG format for title and end images (default: %(default)s). Example: --output_png=False",
)
io_group.add_argument(
"--output_jpg",
type=lambda x: (str(x).lower() == "true"),
default=True,
help="Optional: output JPG format for title and end images (default: %(default)s). Example: --output_jpg=False",
)
# Audio Processing Configuration
audio_group = parser.add_argument_group("Audio Processing Configuration")
audio_group.add_argument(
"--clean_instrumental_model",
default="model_bs_roformer_ep_317_sdr_12.9755.ckpt",
help="Optional: Model for clean instrumental separation (default: %(default)s).",
)
audio_group.add_argument(
"--backing_vocals_models",
nargs="+",
default=["mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt"],
help="Optional: List of models for backing vocals separation (default: %(default)s).",
)
audio_group.add_argument(
"--other_stems_models",
nargs="+",
default=["htdemucs_6s.yaml"],
help="Optional: List of models for other stems separation (default: %(default)s).",
)
default_model_dir_unix = "/tmp/audio-separator-models/"
if os.name == "posix" and os.path.exists(default_model_dir_unix):
default_model_dir = default_model_dir_unix
else:
default_model_dir = os.path.join(tempfile.gettempdir(), "audio-separator-models")
audio_group.add_argument(
"--model_file_dir",
default=default_model_dir,
help="Optional: model files directory (default: %(default)s). Example: --model_file_dir=/app/models",
)
audio_group.add_argument(
"--existing_instrumental",
help="Optional: Path to an existing instrumental audio file. If provided, audio separation will be skipped.",
)
audio_group.add_argument(
"--instrumental_format",
default="flac",
help="Optional: format / file extension for instrumental track to use for remux (default: %(default)s). Example: --instrumental_format=mp3",
)
# Lyrics Configuration
lyrics_group = parser.add_argument_group("Lyrics Configuration")
lyrics_group.add_argument(
"--lyrics_artist",
help="Optional: Override the artist name used for lyrics search. Example: --lyrics_artist='The Beatles'",
)
lyrics_group.add_argument(
"--lyrics_title",
help="Optional: Override the song title used for lyrics search. Example: --lyrics_title='Hey Jude'",
)
lyrics_group.add_argument(
"--lyrics_file",
help="Optional: Path to a file containing lyrics to use instead of fetching from online. Example: --lyrics_file='/path/to/lyrics.txt'",
)
lyrics_group.add_argument(
"--subtitle_offset_ms",
type=int,
default=0,
help="Optional: Adjust subtitle timing by N milliseconds (+ve delays, -ve advances). Example: --subtitle_offset_ms=500",
)
lyrics_group.add_argument(
"--skip_transcription_review",
action="store_true",
help="Optional: Skip the review step after transcription. Example: --skip_transcription_review",
)
# Style Configuration
style_group = parser.add_argument_group("Style Configuration")
style_group.add_argument(
"--style_params_json",
help="Optional: Path to JSON file containing style configuration. Example: --style_params_json='/path/to/style_params.json'",
)
style_group.add_argument(
"--style_override",
action="append",
help="Optional: Override a style parameter. Can be used multiple times. Example: --style_override 'intro.background_image=/path/to/new_image.png'",
)
style_group.add_argument(
"--background_video",
help="Optional: Path to video file to use as background instead of static image. Example: --background_video='/path/to/video.mp4'",
)
style_group.add_argument(
"--background_video_darkness",
type=int,
default=0,
help="Optional: Darkness overlay percentage (0-100) for video background (default: %(default)s). Example: --background_video_darkness=50",
)
# Finalisation Configuration
finalise_group = parser.add_argument_group("Finalisation Configuration")
finalise_group.add_argument(
"--enable_cdg",
action="store_true",
help="Optional: Enable CDG ZIP generation during finalisation. Example: --enable_cdg",
)
finalise_group.add_argument(
"--enable_txt",
action="store_true",
help="Optional: Enable TXT ZIP generation during finalisation. Example: --enable_txt",
)
finalise_group.add_argument(
"--brand_prefix",
help="Optional: Your brand prefix to calculate the next sequential number. Example: --brand_prefix=BRAND",
)
finalise_group.add_argument(
"--organised_dir",
help="Optional: Target directory where the processed folder will be moved. Example: --organised_dir='/path/to/Tracks-Organized'",
)
finalise_group.add_argument(
"--organised_dir_rclone_root",
help="Optional: Rclone path which maps to your organised_dir. Example: --organised_dir_rclone_root='dropbox:Media/Karaoke/Tracks-Organized'",
)
finalise_group.add_argument(
"--public_share_dir",
help="Optional: Public share directory for final files. Example: --public_share_dir='/path/to/Tracks-PublicShare'",
)
finalise_group.add_argument(
"--youtube_client_secrets_file",
help="Optional: Path to youtube client secrets file. Example: --youtube_client_secrets_file='/path/to/client_secret.json'",
)
finalise_group.add_argument(
"--youtube_description_file",
help="Optional: Path to youtube description template. Example: --youtube_description_file='/path/to/description.txt'",
)
finalise_group.add_argument(
"--rclone_destination",
help="Optional: Rclone destination for public_share_dir sync. Example: --rclone_destination='googledrive:KaraokeFolder'",
)
finalise_group.add_argument(
"--discord_webhook_url",
help="Optional: Discord webhook URL for notifications. Example: --discord_webhook_url='https://discord.com/api/webhooks/...'",
)
finalise_group.add_argument(
"--email_template_file",
help="Optional: Path to email template file. Example: --email_template_file='/path/to/template.txt'",
)
finalise_group.add_argument(
"--keep-brand-code",
action="store_true",
help="Optional: Use existing brand code from current directory instead of generating new one. Example: --keep-brand-code",
)
finalise_group.add_argument(
"-y",
"--yes",
action="store_true",
help="Optional: Run in non-interactive mode, assuming yes to all prompts. Example: -y",
)
finalise_group.add_argument(
"--test_email_template",
action="store_true",
help="Optional: Test the email template functionality with fake data. Example: --test_email_template",
)
# Remote CLI specific options
remote_group = parser.add_argument_group("Remote Processing Options (karaoke-gen-remote only)")
remote_group.add_argument(
"--service-url",
default=os.environ.get('KARAOKE_GEN_URL', ''),
help="Backend service URL (or set KARAOKE_GEN_URL env var). Required for remote mode.",
)
remote_group.add_argument(
"--review-ui-url",
default=os.environ.get('REVIEW_UI_URL', 'https://lyrics.nomadkaraoke.com'),
help="Lyrics review UI URL (default: https://lyrics.nomadkaraoke.com)",
)
remote_group.add_argument(
"--poll-interval",
type=int,
default=int(os.environ.get('POLL_INTERVAL', '5')),
help="Seconds between status polls (default: 5)",
)
return parser
def process_style_overrides(style_override_list, logger=None):
"""
Process style override arguments into a dictionary.
Args:
style_override_list: List of override strings in 'key=value' format
logger: Optional logger instance
Returns:
Dictionary of style overrides
Raises:
ValueError: If override format is invalid
"""
style_overrides = {}
if style_override_list:
for override in style_override_list:
try:
key, value = override.split("=", 1)
style_overrides[key] = value
except ValueError:
error_msg = f"Invalid style override format: {override}. Must be in 'key=value' format."
if logger:
logger.error(error_msg)
raise ValueError(error_msg)
return style_overrides
def is_url(string: str) -> bool:
"""Simple check to determine if a string is a URL."""
return string.startswith("http://") or string.startswith("https://")
def is_file(string: str) -> bool:
"""Check if a string is a valid file."""
return os.path.isfile(string)
+7 -285
View File
@@ -11,16 +11,7 @@ import time
import pyperclip
from karaoke_gen import KaraokePrep
from karaoke_gen.karaoke_finalise import KaraokeFinalise
def is_url(string):
"""Simple check to determine if a string is a URL."""
return string.startswith("http://") or string.startswith("https://")
def is_file(string):
"""Check if a string is a valid file."""
return os.path.isfile(string)
from .cli_args import create_parser, process_style_overrides, is_url, is_file
async def async_main():
@@ -30,284 +21,15 @@ async def async_main():
log_handler.setFormatter(log_formatter)
logger.addHandler(log_handler)
parser = argparse.ArgumentParser(
description="Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video.",
formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, max_help_position=54),
)
# Basic information
parser.add_argument(
"args",
nargs="*",
help="[Media or playlist URL] [Artist] [Title] of song to process. If URL is provided, Artist and Title are optional but increase chance of fetching the correct lyrics. If Artist and Title are provided with no URL, the top YouTube search result will be fetched.",
)
# Get version using importlib.metadata
try:
package_version = metadata.version("karaoke-gen")
except metadata.PackageNotFoundError:
package_version = "unknown"
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {package_version}")
# Workflow control
workflow_group = parser.add_argument_group("Workflow Control")
workflow_group.add_argument(
"--prep-only",
action="store_true",
help="Only run the preparation phase (download audio, lyrics, separate stems, create title screens). Example: --prep-only",
)
workflow_group.add_argument(
"--finalise-only",
action="store_true",
help="Only run the finalisation phase (remux, encode, organize). Must be run in a directory prepared by the prep phase. Example: --finalise-only",
)
workflow_group.add_argument(
"--skip-transcription",
action="store_true",
help="Skip automatic lyrics transcription/synchronization. Use this to fall back to manual syncing. Example: --skip-transcription",
)
workflow_group.add_argument(
"--skip-separation",
action="store_true",
help="Skip audio separation process. Example: --skip-separation",
)
workflow_group.add_argument(
"--skip-lyrics",
action="store_true",
help="Skip fetching and processing lyrics. Example: --skip-lyrics",
)
workflow_group.add_argument(
"--lyrics-only",
action="store_true",
help="Only process lyrics, skipping audio separation and title/end screen generation. Example: --lyrics-only",
)
workflow_group.add_argument(
"--edit-lyrics",
action="store_true",
help="Edit lyrics of an existing track. This will backup existing outputs, re-run the lyrics transcription process, and update all outputs. Example: --edit-lyrics",
)
# Logging & Debugging
debug_group = parser.add_argument_group("Logging & Debugging")
debug_group.add_argument(
"--log_level",
default="info",
help="Optional: logging level, e.g. info, debug, warning (default: %(default)s). Example: --log_level=debug",
)
debug_group.add_argument(
"--dry_run",
action="store_true",
help="Optional: perform a dry run without making any changes. Example: --dry_run",
)
debug_group.add_argument(
"--render_bounding_boxes",
action="store_true",
help="Optional: render bounding boxes around text regions for debugging. Example: --render_bounding_boxes",
)
# Input/Output Configuration
io_group = parser.add_argument_group("Input/Output Configuration")
io_group.add_argument(
"--filename_pattern",
help="Required if processing a folder: Python regex pattern to extract track names from filenames. Must contain a named group 'title'. Example: --filename_pattern='(?P<index>\\d+) - (?P<title>.+).mp3'",
)
io_group.add_argument(
"--output_dir",
default=".",
help="Optional: directory to write output files (default: <current dir>). Example: --output_dir=/app/karaoke",
)
io_group.add_argument(
"--no_track_subfolders",
action="store_false",
dest="no_track_subfolders",
help="Optional: do NOT create a named subfolder for each track. Example: --no_track_subfolders",
)
io_group.add_argument(
"--lossless_output_format",
default="FLAC",
help="Optional: lossless output format for separated audio (default: FLAC). Example: --lossless_output_format=WAV",
)
io_group.add_argument(
"--output_png",
type=lambda x: (str(x).lower() == "true"),
default=True,
help="Optional: output PNG format for title and end images (default: %(default)s). Example: --output_png=False",
)
io_group.add_argument(
"--output_jpg",
type=lambda x: (str(x).lower() == "true"),
default=True,
help="Optional: output JPG format for title and end images (default: %(default)s). Example: --output_jpg=False",
)
# Audio Processing Configuration
audio_group = parser.add_argument_group("Audio Processing Configuration")
audio_group.add_argument(
"--clean_instrumental_model",
default="model_bs_roformer_ep_317_sdr_12.9755.ckpt",
help="Optional: Model for clean instrumental separation (default: %(default)s).",
)
audio_group.add_argument(
"--backing_vocals_models",
nargs="+",
default=["mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt"],
help="Optional: List of models for backing vocals separation (default: %(default)s).",
)
audio_group.add_argument(
"--other_stems_models",
nargs="+",
default=["htdemucs_6s.yaml"],
help="Optional: List of models for other stems separation (default: %(default)s).",
)
default_model_dir_unix = "/tmp/audio-separator-models/"
if os.name == "posix" and os.path.exists(default_model_dir_unix):
default_model_dir = default_model_dir_unix
else:
# Use tempfile to get the platform-independent temp directory
default_model_dir = os.path.join(tempfile.gettempdir(), "audio-separator-models")
audio_group.add_argument(
"--model_file_dir",
default=default_model_dir,
help="Optional: model files directory (default: %(default)s). Example: --model_file_dir=/app/models",
)
audio_group.add_argument(
"--existing_instrumental",
help="Optional: Path to an existing instrumental audio file. If provided, audio separation will be skipped.",
)
audio_group.add_argument(
"--instrumental_format",
default="flac",
help="Optional: format / file extension for instrumental track to use for remux (default: %(default)s). Example: --instrumental_format=mp3",
)
# Lyrics Configuration
lyrics_group = parser.add_argument_group("Lyrics Configuration")
lyrics_group.add_argument(
"--lyrics_artist",
help="Optional: Override the artist name used for lyrics search. Example: --lyrics_artist='The Beatles'",
)
lyrics_group.add_argument(
"--lyrics_title",
help="Optional: Override the song title used for lyrics search. Example: --lyrics_title='Hey Jude'",
)
lyrics_group.add_argument(
"--lyrics_file",
help="Optional: Path to a file containing lyrics to use instead of fetching from online. Example: --lyrics_file='/path/to/lyrics.txt'",
)
lyrics_group.add_argument(
"--subtitle_offset_ms",
type=int,
default=0,
help="Optional: Adjust subtitle timing by N milliseconds (+ve delays, -ve advances). Example: --subtitle_offset_ms=500",
)
lyrics_group.add_argument(
"--skip_transcription_review",
action="store_true",
help="Optional: Skip the review step after transcription. Example: --skip_transcription_review",
)
# Style Configuration
style_group = parser.add_argument_group("Style Configuration")
style_group.add_argument(
"--style_params_json",
help="Optional: Path to JSON file containing style configuration. Example: --style_params_json='/path/to/style_params.json'",
)
style_group.add_argument(
"--style_override",
action="append",
help="Optional: Override a style parameter. Can be used multiple times. Example: --style_override 'intro.background_image=/path/to/new_image.png'",
)
style_group.add_argument(
"--background_video",
help="Optional: Path to video file to use as background instead of static image. Example: --background_video='/path/to/video.mp4'",
)
style_group.add_argument(
"--background_video_darkness",
type=int,
default=0,
help="Optional: Darkness overlay percentage (0-100) for video background (default: %(default)s). Example: --background_video_darkness=50",
)
# Finalisation Configuration
finalise_group = parser.add_argument_group("Finalisation Configuration")
finalise_group.add_argument(
"--enable_cdg",
action="store_true",
help="Optional: Enable CDG ZIP generation during finalisation. Example: --enable_cdg",
)
finalise_group.add_argument(
"--enable_txt",
action="store_true",
help="Optional: Enable TXT ZIP generation during finalisation. Example: --enable_txt",
)
finalise_group.add_argument(
"--brand_prefix",
help="Optional: Your brand prefix to calculate the next sequential number. Example: --brand_prefix=BRAND",
)
finalise_group.add_argument(
"--organised_dir",
help="Optional: Target directory where the processed folder will be moved. Example: --organised_dir='/path/to/Tracks-Organized'",
)
finalise_group.add_argument(
"--organised_dir_rclone_root",
help="Optional: Rclone path which maps to your organised_dir. Example: --organised_dir_rclone_root='dropbox:Media/Karaoke/Tracks-Organized'",
)
finalise_group.add_argument(
"--public_share_dir",
help="Optional: Public share directory for final files. Example: --public_share_dir='/path/to/Tracks-PublicShare'",
)
finalise_group.add_argument(
"--youtube_client_secrets_file",
help="Optional: Path to youtube client secrets file. Example: --youtube_client_secrets_file='/path/to/client_secret.json'",
)
finalise_group.add_argument(
"--youtube_description_file",
help="Optional: Path to youtube description template. Example: --youtube_description_file='/path/to/description.txt'",
)
finalise_group.add_argument(
"--rclone_destination",
help="Optional: Rclone destination for public_share_dir sync. Example: --rclone_destination='googledrive:KaraokeFolder'",
)
finalise_group.add_argument(
"--discord_webhook_url",
help="Optional: Discord webhook URL for notifications. Example: --discord_webhook_url='https://discord.com/api/webhooks/...'",
)
finalise_group.add_argument(
"--email_template_file",
help="Optional: Path to email template file. Example: --email_template_file='/path/to/template.txt'",
)
finalise_group.add_argument(
"--keep-brand-code",
action="store_true",
help="Optional: Use existing brand code from current directory instead of generating new one. Example: --keep-brand-code",
)
finalise_group.add_argument(
"-y",
"--yes",
action="store_true",
help="Optional: Run in non-interactive mode, assuming yes to all prompts. Example: -y",
)
finalise_group.add_argument(
"--test_email_template",
action="store_true",
help="Optional: Test the email template functionality with fake data. Example: --test_email_template",
)
# Use shared CLI parser
parser = create_parser(prog="karaoke-gen")
args = parser.parse_args()
# Process style overrides
style_overrides = {}
if args.style_override:
for override in args.style_override:
try:
key, value = override.split("=", 1)
style_overrides[key] = value
except ValueError:
logger.error(f"Invalid style override format: {override}. Must be in 'key=value' format.")
sys.exit(1)
try:
style_overrides = process_style_overrides(args.style_override, logger)
except ValueError:
sys.exit(1)
# Handle test email template case first
if args.test_email_template:
File diff suppressed because it is too large. Load diff
Submodule lyrics_transcriber_local updated: 34defdf8ed...83715b70b7.