Skip to content

Fail a track download that ends before its Content-Length - #9

Merged
jasonpatrickellykrause merged 1 commit into
mainfrom
feat/check-track-length
Nov 23, 2026
Merged

jasonpatrickellykrause merged 1 commit into
mainfrom
feat/check-track-length

Conversation

@jasonpatrickellykrause

Copy link
Copy Markdown
Collaborator

Problem

GetEncryptedTrackData streams the CDN response with ResponseHeadersRead, and DecodeTrackStreamAsync decodes 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.DecodeTrackStreamAsync returns the number of bytes read from the input (the encrypted body, which is what Content-Length counts). Callers that ignore the result are unaffected.
  • New Decryption.EnsureComplete(received, expected, trackId): throws IncompleteTrackException when fewer bytes arrived than Content-Length. No Content-Length (chunked response), zero, or more than expected passes.
  • GetEncryptedTrackData returns the response's Content-Length with the stream. GetRawTrackStream (and so GetRawTrackBytes) and WriteRawTrackToFile call EnsureComplete after decoding.
  • New public DeezNET.Exceptions.IncompleteTrackException.

The client has no automatic decompression, so Content-Length is 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, and EnsureComplete throws with both counts in the message.
  • EnsureCompleteAllowsTest: matching length, no Content-Length, zero, and more than expected all pass.
  • Local run: 64 passed, 0 failed (Category!=Live).

The Lidarr plugin picks this up with a submodule bump; its download loop already counts any exception from WriteRawTrackToFile as a failed track and deletes the partial file.

🤖 Generated with Claude Code

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]>
@jasonpatrickellykrause
jasonpatrickellykrause merged commit 4fe8e05 into main Nov 23, 2026
5 checks passed
@jasonpatrickellykrause
jasonpatrickellykrause deleted the feat/check-track-length branch November 23, 2026 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant