fix: provide-url YouTube downloads failing with 'No audio source selection found' (v0.285.1) (#1224)

Pasting a YouTube URL in the audio modal (job 258ba59b) failed:
provide-url set source_name/download_url but not source_id, and the
worker fallback required source_id. Now sets source_id and the worker
accepts download_url. The retry loop could never succeed before.

Tests: worker regression test for the provide-url job shape; provide-url
test asserts source_id. Emulator test_e2e_cli_backend needs Firestore
emulator, left to CI.

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

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* YouTube audio jobs submitted with a pasted URL can now proceed when no
video ID is available.
* YouTube video IDs are saved with provided-URL jobs when available, and
stale search selections no longer override the pasted URL.

* **Chores**
  * Updated the application version to 0.285.1.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Andrew Beveridge ☄️andClaude Sonnet 5.5 authored and GitHub committed 2026-10-26 20:07:38 -04:00
1 parent 3230bfbe0b
commit cd1fa3feaf
7 files changed
+53 -5

No files matched your search

+3
View File
@@ -1374,7 +1374,10 @@ async def provide_url_for_job(
'audio_source_type': 'url',
'url': url,
'source_name': 'YouTube' if is_youtube else 'url',
'source_id': youtube_service._extract_video_id(url) if is_youtube else None,
'download_url': url,
# a stale earlier selection would otherwise win over the pasted URL in the worker
'state_data.selected_audio_index': None,
})
job_manager.transition_to_state(
job_id=job_id,
+1 -1
View File
@@ -185,7 +185,7 @@ class YouTubeDownloadService:
# Shorts URL
r'youtube\.com/shorts/([a-zA-Z0-9_-]{11})',
# Embed URL
r'youtube\.com/embed/([a-zA-Z0-9_-]{11})',
r'youtube(?:-nocookie)?\.com/embed/([a-zA-Z0-9_-]{11})',
# Old-style URL
r'youtube\.com/v/([a-zA-Z0-9_-]{11})',
]
@@ -273,6 +273,7 @@ class TestProvideUrl:
yt = MagicMock()
yt.check_availability = AsyncMock(return_value={"available": True})
yt.download = AsyncMock()
yt._extract_video_id = MagicMock(return_value="abcdefghijk")
ws = MagicMock()
ws.trigger_audio_download_worker = AsyncMock(return_value=True)
@@ -292,6 +293,11 @@ class TestProvideUrl:
srcd = [c for c in mock_job_manager.update_job.call_args_list
if c.args[1].get("source_name") == "YouTube" and c.args[1].get("download_url")]
assert srcd
# the worker's job-level fallback needs source_id too
assert srcd[0].args[1].get("source_id") == "abcdefghijk"
# a stale earlier selection must not override the pasted URL
assert srcd[0].args[1].get("state_data.selected_audio_index") is None
assert "state_data.selected_audio_index" in srcd[0].args[1]
def test_youtube_worker_trigger_failure_requeues(self, mock_job_manager):
from fastapi.testclient import TestClient
@@ -227,6 +227,38 @@ class TestProcessAudioDownload:
mock_ws.trigger_audio_worker.assert_awaited_once_with("test-job-123")
mock_ws.trigger_lyrics_worker.assert_awaited_once_with("test-job-123")
@pytest.mark.asyncio
async def test_provide_url_job_without_source_id_downloads_from_url(self):
"""A job parked then given a pasted YouTube URL has download_url but no
source_id (provide-url shape); the worker must still download it."""
job = _make_job(
source_name="YouTube",
source_id=None,
download_url="https://www.youtube.com/watch?v=icW5d_fYJaI",
state_data={"audio_search_results": [{"provider": "Spotify"}]},
)
with patch("backend.workers.audio_download_worker.JobManager") as mock_jm_cls, \
patch("backend.workers.audio_download_worker.StorageService"), \
patch("backend.workers.audio_download_worker._download_audio", new_callable=AsyncMock) as mock_dl, \
patch("backend.workers.audio_download_worker.get_worker_service") as mock_ws_factory, \
patch("backend.workers.audio_download_worker.reconcile_and_maybe_pause",
new_callable=AsyncMock, return_value=False):
mock_jm = MagicMock()
mock_jm.get_job.return_value = job
mock_jm.transition_to_state.return_value = True
mock_jm_cls.return_value = mock_jm
mock_dl.return_value = ("uploads/test-job-123/audio/song.mp3", "song.mp3")
mock_ws_factory.return_value = AsyncMock()
result = await process_audio_download("test-job-123")
assert result is True
kwargs = mock_dl.call_args.kwargs
assert kwargs["source_name"] == "YouTube"
assert kwargs["download_url"] == "https://www.youtube.com/watch?v=icW5d_fYJaI"
@pytest.mark.asyncio
async def test_download_error_fails_job(self):
"""DownloadError should fail the job and return False."""
@@ -51,6 +51,12 @@ class TestYouTubeDownloadService:
url = "https://www.youtube.com/embed/dQw4w9WgXcQ"
assert service._extract_video_id(url) == "dQw4w9WgXcQ"
def test_extract_video_id_nocookie_embed_url(self):
"""Privacy-enhanced embed URLs pass _is_youtube_url, so they must yield an ID."""
service = YouTubeDownloadService()
url = "https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ"
assert service._extract_video_id(url) == "dQw4w9WgXcQ"
def test_extract_video_id_with_extra_params(self):
"""Should extract video ID when URL has extra parameters."""
service = YouTubeDownloadService()
+4 -3
View File
@@ -258,7 +258,7 @@ async def process_audio_download(job_id: str) -> bool:
f"[job:{job_id}] Unexpected status {job.status}, expected DOWNLOADING_AUDIO"
)
# Still proceed if there's download params - this handles retry cases
if not (job.source_name and job.source_id):
if not (job.source_name and (job.source_id or job.download_url)):
logger.error(f"[job:{job_id}] No download params available, aborting")
return False
@@ -275,8 +275,9 @@ async def process_audio_download(job_id: str) -> bool:
source_id = selected.get('source_id')
target_file = selected.get('target_file')
download_url = selected.get('url')
elif job.source_name and job.source_id:
# Fallback to job-level params (set by _validate_and_prepare_selection)
elif job.source_name and (job.source_id or job.download_url):
# Fallback to job-level params (set by _validate_and_prepare_selection,
# or by provide-url which only knows the pasted URL, not a source_id)
source_name = job.source_name
source_id = job.source_id
target_file = job.target_file
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "karaoke-gen"
version = "0.285.0"
version = "0.285.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"