diff --git a/backend/services/job_defaults_service.py b/backend/services/job_defaults_service.py index eb3ad694..1949c1d4 100644 --- a/backend/services/job_defaults_service.py +++ b/backend/services/job_defaults_service.py @@ -71,7 +71,9 @@ def get_effective_distribution_for_job(job) -> EffectiveDistributionSettings: - enable_youtube_upload → False (no YouTube for private) - gdrive_folder_id → None (no Google Drive for private) - For non-private jobs, returns the job's own distribution settings unchanged. + For non-private jobs, returns the job's own distribution settings, except + youtube_description, which is the CURRENT channel template + (settings.default_youtube_description), not the copy frozen on the job. Args: job: Job object (or any object with distribution fields) @@ -100,14 +102,22 @@ def get_effective_distribution_for_job(job) -> EffectiveDistributionSettings: discord_webhook_url=getattr(job, 'discord_webhook_url', None), youtube_description=None, ) - # Non-private: return job's own settings + # Non-private: return job's own settings, except the YouTube description. + # Every non-private upload lands on the shared Nomad channel, whose template + # is Settings.default_youtube_description (the description backfill worker + # rewrites every channel video to it). The job only holds a copy frozen at + # creation, so a job uploaded long after creation (admin re-render, + # redistribute) would publish a stale description that the backfill then + # has to fix the next day. Use the current template; fall back to the job's + # copy only if no channel template is configured. + current_template = get_settings().default_youtube_description return EffectiveDistributionSettings( dropbox_path=getattr(job, 'dropbox_path', None), brand_prefix=getattr(job, 'brand_prefix', None), enable_youtube_upload=getattr(job, 'enable_youtube_upload', False), gdrive_folder_id=getattr(job, 'gdrive_folder_id', None), discord_webhook_url=getattr(job, 'discord_webhook_url', None), - youtube_description=getattr(job, 'youtube_description_template', None), + youtube_description=current_template or getattr(job, 'youtube_description_template', None), ) diff --git a/backend/tests/test_private_tracks.py b/backend/tests/test_private_tracks.py index f50a4fdc..4687d5ca 100644 --- a/backend/tests/test_private_tracks.py +++ b/backend/tests/test_private_tracks.py @@ -206,8 +206,10 @@ class TestGetEffectiveDistributionForJob: assert dist.discord_webhook_url == "https://discord.com/webhook/123" - def test_non_private_job_uses_job_settings(self): + @patch('backend.services.job_defaults_service.get_settings') + def test_non_private_job_uses_job_settings(self, mock_settings): """Non-private job should use its own distribution settings.""" + mock_settings.return_value = SimpleNamespace(default_youtube_description="") job = SimpleNamespace( is_private=False, dropbox_path="/Tracks-Organized", @@ -227,8 +229,38 @@ class TestGetEffectiveDistributionForJob: assert dist.discord_webhook_url == "https://discord.com/hook" assert dist.youtube_description == "description" - def test_job_without_is_private_treated_as_non_private(self): + @patch('backend.services.job_defaults_service.get_settings') + def test_non_private_job_uses_current_channel_template_not_stale_copy(self, mock_settings): + """A job created before a template change (e.g. an admin re-render weeks + later) must upload with the CURRENT channel template, not its frozen copy.""" + mock_settings.return_value = SimpleNamespace(default_youtube_description="NEW {title}") + job = SimpleNamespace( + is_private=False, + dropbox_path="/Tracks-Organized", + brand_prefix="NOMAD", + enable_youtube_upload=True, + gdrive_folder_id=None, + discord_webhook_url=None, + youtube_description_template="OLD {title}", + ) + + dist = get_effective_distribution_for_job(job) + + assert dist.youtube_description == "NEW {title}" + + @patch('backend.services.job_defaults_service.get_settings') + def test_non_private_job_falls_back_to_job_template_without_channel_template(self, mock_settings): + mock_settings.return_value = SimpleNamespace(default_youtube_description=None) + job = SimpleNamespace(is_private=False, youtube_description_template="JOB {title}") + + dist = get_effective_distribution_for_job(job) + + assert dist.youtube_description == "JOB {title}" + + @patch('backend.services.job_defaults_service.get_settings') + def test_job_without_is_private_treated_as_non_private(self, mock_settings): """Job object without is_private attribute should be treated as non-private.""" + mock_settings.return_value = SimpleNamespace(default_youtube_description="") job = SimpleNamespace( dropbox_path="/Tracks-Organized", brand_prefix="NOMAD", diff --git a/backend/workers/video_worker.py b/backend/workers/video_worker.py index 5d845f16..1421aa9d 100644 --- a/backend/workers/video_worker.py +++ b/backend/workers/video_worker.py @@ -1099,11 +1099,14 @@ async def generate_video_legacy(job_id: str) -> bool: job_log.info(f" using user-provided instrumental (selection was: {instrumental_selection})") # Set up YouTube description file if template is provided + # Current channel template, not the copy frozen on the job at creation. + from backend.services.job_defaults_service import get_effective_distribution_for_job + youtube_desc_template = get_effective_distribution_for_job(job).youtube_description youtube_desc_path = None - if youtube_credentials and getattr(job, 'youtube_description_template', None): + if youtube_credentials and youtube_desc_template: youtube_desc_path = os.path.join(temp_dir, "youtube_description.txt") with open(youtube_desc_path, 'w') as f: - f.write(job.youtube_description_template) + f.write(youtube_desc_template) job_log.info("YouTube description template written to temp file") # Duet-aware CDG: download the corrections JSON locally if present diff --git a/docs/API.md b/docs/API.md index 308b1730..59dbda4d 100644 --- a/docs/API.md +++ b/docs/API.md @@ -2650,6 +2650,8 @@ Updates editable job fields. Allowed fields: `artist`, `title`, `user_email`, `t **Note:** Setting `is_private=true` on a completed job with existing outputs triggers automatic output deletion. +**Note:** YouTube uploads (first upload, admin re-render, redistribute) always use the current channel template `Settings.default_youtube_description`. A job's `youtube_description_template` is only a fallback for when no channel template is configured. The daily description backfill rewrites every channel video to the channel template anyway. + **Note:** `user_email` is trimmed and lowercased before saving. If no account exists for that email, one is auto-created (so the recipient can log in and see the job, and the admin can impersonate them immediately). The response message notes when diff --git a/pyproject.toml b/pyproject.toml index 27445789..b9364c1c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "karaoke-gen" -version = "0.297.0" +version = "0.297.1" description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens." authors = ["Andrew Beveridge "] license = "MIT"