fix(stremio): derive real release name from NZB contents#765
Merged
Conversation
AIOStreams pushes NZBs to /api/nzb/streams with a generic transport name
("download.nzb" as a multipart part name or a ".../download?..." URL). That
name propagated everywhere and caused two bugs:
- RenameToNzbName rewrote the imported media file to "download.mp4", losing
the real title.
- The per-filename dedup/cache collided across releases, so a request for one
movie was served another already-completed movie's stream within the TTL.
When the incoming transport name looks obfuscated/generic, derive a
meaningful, unique name from the NZB's own contents (the <head><meta
type="name"> value, else the largest media <file> subject stem) before the
naming, dedup, and queue logic. This makes each release name unique and
correct without touching the parser/processor selection logic.
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
When AIOStreams pushes an NZB to AltMount's Stremio endpoint (
POST /api/nzb/streams), the release always landed asdownload.nzb→ imported asdownload.mp4under/complete/stremio/download/, and playing a second, different movie served the first one back.Root cause (single, unified)
AltMount named each NZB from the transport only. AIOStreams always sends a generic name — either the multipart part name
download.nzb, or a download-endpoint URL like.../download?...whosefilepath.Baseisdownload. That genericdownloadcaused both symptoms:RenameToNzbName(defaulttrue) rewrote the real media file todownload.mp4, discarding the true subject name. The written content was the correct movie; only the name was wrong.handleNzbStreamsdeduplicates/caches per filename (stremioPlayGroup.Do(safeFilename)+ListQueueItems(&completed, safeFilename, …)). Since every Stremio NZB is nameddownload.nzb, a request for movie B was treated as a cache hit for the already-completed movie A within the TTL, returning A's stream. All releases also collided on the same virtual path.Fix
The real name already lives inside the NZB. When the incoming transport name looks obfuscated/generic (which
downloadis), derive a meaningful, unique name from the NZB contents before the naming/dedup/queue logic:deriveNzbNameFromContent(nzbData)parses the NZB locally (no NNTP) and prefers the<head><meta type="name">value, else the largest media<file>subject's release stem.nzbparser.Parse,fileinfo.IsProbablyObfuscated,isMediaExtension,sanitizeFilename,nzbtrim.Downstream —
safeFilename,nzbName,tempPath, the singleflight/dedup key, andAddToQueue— then use the unique real name, andRenameToNzbNameproduces the correct output (e.g.The.Sheep.Detectives.2026.2160p….mp4). Distinct movies no longer collide in cache or on disk.Deliberately out of scope
parser.determineNzbTypeorprocessor.processSingleFile— file/content selection works; only naming was broken.RenameToNzbNamestays on; feeding it a correct name is the fix.Testing
deriveNzbNameFromContent(meta preference, largest-media selection, obfuscation fallthrough, no-media/empty cases, invalid bytes) plus a guard that"download"is classified obfuscated.go build ./...✓,go test ./internal/api/... -race✓,go vet✓,gofmtclean./api/nzb/streamsrequests for different releases with genericdownload.nzbtransport names; confirm each imports under its real title and the second is not served the first's stream (distinct_queue_item_id/ storage paths).