Repository navigation
Fail a track download that ends before its Content-Length - #9
Merged
Merged
Conversation
A connection to the Deezer CDN that closed partway could end the response body like a normal finish. The track was saved short and reported as downloaded. A FLAC cut short still reports its full length in its STREAMINFO header, so later checks didn't notice either. DecodeTrackStreamAsync now returns the bytes it read, and GetRawTrackStream and WriteRawTrackToFile compare that with the response's Content-Length. A shortfall throws IncompleteTrackException. A response without Content-Length (chunked) skips the check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem
GetEncryptedTrackDatastreams the CDN response withResponseHeadersRead, andDecodeTrackStreamAsyncdecodes until the stream returns 0 bytes. If the connection closed partway, the body could end like a normal finish, and the track was saved short and reported as downloaded. A FLAC cut short still reports its full length in its STREAMINFO header, so the Lidarr plugin's audio check (duration from TagLib) doesn't catch it either.Change
Decryption.DecodeTrackStreamAsyncreturns the number of bytes read from the input (the encrypted body, which is what Content-Length counts). Callers that ignore the result are unaffected.Decryption.EnsureComplete(received, expected, trackId): throwsIncompleteTrackExceptionwhen fewer bytes arrived thanContent-Length. No Content-Length (chunked response), zero, or more than expected passes.GetEncryptedTrackDatareturns the response'sContent-Lengthwith the stream.GetRawTrackStream(and soGetRawTrackBytes) andWriteRawTrackToFilecallEnsureCompleteafter decoding.DeezNET.Exceptions.IncompleteTrackException.The client has no automatic decompression, so
Content-Lengthis the size of the bytes the stream yields.Testing
DecodeTrackStreamAsyncReturnsBytesReadTest: the returned count equals the encrypted input length, with short reads.DecodeTrackStreamAsyncTruncatedBodyIsCaughtTest: a body cut at 7144 of 18432 bytes decodes without error, andEnsureCompletethrows with both counts in the message.EnsureCompleteAllowsTest: matching length, no Content-Length, zero, and more than expected all pass.Category!=Live).The Lidarr plugin picks this up with a submodule bump; its download loop already counts any exception from
WriteRawTrackToFileas a failed track and deletes the partial file.🤖 Generated with Claude Code