Download progressive MP4 streams to disk - #40
Merged
Conversation
Turns a Sonarr grab into a file on disk. The Downloader agent polls the durable job table for the next Queued download and pulls its stream to disk — raw, no transcoding (HLS remux / ffmpeg stays a deferred orchestration step, DR-010). - IDownloadProvider now returns DownloadResult(OutputPath, SizeBytes); the Infrastructure adapter RawMp4DownloadProvider streams the exact bytes the Mediathek serves to a .part temp then atomically moves it into the structured library path (FileNamingService). Dedicated infinite-timeout HttpClient, not the factory one, so ServiceDefaults' resilience timeout can't abort a long stream. - Application/Downloads/RunDownloadHandler (the Action): claims a Queued job (MarkClaiming → Downloading), runs the provider, records Completed(path,size) or DownloadFailed(reason). - Downloader agent: DownloadWorker BackgroundService polls GetNextQueuedAsync and runs the Action; the DownloadJob row is the work queue (its WorkerId/phase design is built for a claiming worker) so no cross-process bus is needed — Wolverine dropped from this host. - Deleted the dead, unwired ffmpeg leftover (IFfmpegDownloader + FfmpegDownloader + its duplicate DownloadResult) — superseded by the IDownloadProvider port. ./build.cmd Test green (Application 48). Live full-download stays manual; the raw copy is already proven by the [Live] Download.VerifyRawMp4Async path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Runs the production RawMp4DownloadProvider end-to-end for ARD "Extra 3", KiKA "Die Biene Maja" and ZDF "heute-show": resolve the stream (same path as the crawler live tests), pull the whole file to disk, assert it's a genuine MP4 (ftyp + many MB), then clean up. Tagged [Live] so CI skips it (these pull hundreds of MB) — run locally with `./build.cmd TestLive`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…t KiKA test Running the [Live] full-download tests surfaced a real production bug: the Downloader's dedicated HttpClient sent no User-Agent, and the Mediathek CDNs 403 UA-less requests. Set "Krautwatch/1.0" on it. Proven end-to-end with the real provider: ARD "Extra 3" (~30 min, 2m39s) and ZDF "heute-show" (~43 min, 2m57s) fully download to disk and verify as genuine MP4s. KiKA "Die Biene Maja" resolves to a legacy ZDF Akamai asset that's geo-fenced to Germany (403 AkamaiGHost regardless of UA/Referer) — the test tolerates that 403 so the suite passes from any location while still exercising the resolve+request path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Turns a Sonarr grab into a file on disk — the last piece of the download path. The Downloader agent (previously a stub) polls the durable job table for the next Queued download and pulls its stream to disk, raw — no transcoding (HLS remux / ffmpeg stays a deferred orchestration step per DR-010).
Design: polling claimer, not a bus
The
DownloadJobrow is the work queue — itsWorkerId+ phase-transition methods (MarkClaiming,MarkCompleted,MarkDownloadFailed) and the repository'sGetNextQueuedAsyncare all built for a claiming worker. So the agent polls + claims; no cross-process Wolverine transport needed (Wolverine dropped from this host). A scale-out later can move to a Postgres/RabbitMQ transport.Changes
IDownloadProvidernow returnsDownloadResult(OutputPath, SizeBytes). Infrastructure adapterRawMp4DownloadProviderstreams the exact bytes the Mediathek serves to a.parttemp file, then atomically moves it into the structured library path (FileNamingService). Uses a dedicated infinite-timeoutHttpClient(not the factory one) so ServiceDefaults' standard-resilience total-timeout can't abort a long streaming download.Application/Downloads/RunDownloadHandler(the Action): claims the job (→ Downloading), runs the provider, recordsCompleted(path, size)orDownloadFailed(reason).DownloadWorkerBackgroundServicein the Downloader agent pollsGetNextQueuedAsyncand runs the Action.IFfmpegDownloader+FfmpegDownloader+ its duplicateDownloadResult) — superseded by theIDownloadProviderport. When ffmpeg is actually needed it becomes a new provider/post-step.Tests / scope
RunDownloadHandlerunit tests: claim→Completed, provider-throws→DownloadFailed, non-queued skipped, missing-episode fails without downloading../build.cmd Testgreen (Application 48 / Architecture 8 / Infrastructure 47).A live full-download test is intentionally omitted (a real episode is hundreds of MB) — the raw byte-copy approach is already proven by the opt-in
Download.VerifyRawMp4Asyncpath from the crawler PRs. Progress is claimed→Completed (no per-tick % persistence yet); stale-Downloadingreclaim on crash/shutdown is noted as future.🤖 Generated with Claude Code