fix(youtube): upload with the current channel description template (#1267)

## Why
On 2026-11-10 the daily description backfill sent "[YouTube
Descriptions] 1 updated, 0 remaining". The video was `0uM7NClsA_E`
(NOMAD-1779, job `58555663`). The NOMAD-1779 admin re-render on 11-09
uploaded it with the description template saved on the job at creation
(2026-10-16). The channel template changed on 10-22, so that copy was
out of date, and the backfill fixed the video the next morning.

## Change
- `get_effective_distribution_for_job` now gives non-private jobs, which
all upload to the shared Nomad channel, the **current**
`Settings.default_youtube_description`. The job's own
`youtube_description_template` is used only if no channel template is
configured. This covers first uploads, admin re-renders and
redistributes (the orchestrated path).
- The legacy `KaraokeFinalise` path in `video_worker.py` now resolves
the description through the same function instead of reading the job
field directly.
- `docs/API.md`: added a note that an admin-edited per-job template no
longer reaches YouTube while a channel template is set. The backfill was
already overwriting those edits.
- Version bumped to 0.297.1.

## Testing
- Added tests: the current template wins over an old copy on the job,
and the job's copy is used when there is no channel template. Updated
the existing non-private test.
- Backend suite (non-emulator): 7,255 passed. The only failures need the
Firestore emulator (`test_emulator_integration.py`), which wasn't
running locally; CI runs that suite.
- Local CodeRabbit review: no findings.

@coderabbitai ignore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_012RYLVSJbAsXHW4NxxzusWX

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Andrew Beveridge ☄️andClaude Opus 5.5 authored and GitHub committed 2026-11-11 22:24:47 -05:00
1 parent ad64286004
commit 5bf17d520f
5 files changed
+55 -8

No files matched your search

+13 -3
View File
@@ -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),
)
+34 -2
View File
@@ -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",
+5 -2
View File
@@ -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
+2
View File
@@ -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
+1 -1
View File
@@ -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 <andrew@beveridge.uk>"]
license = "MIT"