Skip to content

fix(stremio): derive real release name from NZB contents#765

Merged
javi11 merged 1 commit into
mainfrom
session/sweet-jones-ac5b17
Jul 6, 2026
Merged

fix(stremio): derive real release name from NZB contents#765
javi11 merged 1 commit into
mainfrom
session/sweet-jones-ac5b17

Conversation

@javi11

@javi11 javi11 commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Problem

When AIOStreams pushes an NZB to AltMount's Stremio endpoint (POST /api/nzb/streams), the release always landed as download.nzb → imported as download.mp4 under /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?... whose filepath.Base is download. That generic download caused both symptoms:

  1. Wrong output name — the importer's RenameToNzbName (default true) rewrote the real media file to download.mp4, discarding the true subject name. The written content was the correct movie; only the name was wrong.
  2. "Plays another file"handleNzbStreams deduplicates/caches per filename (stremioPlayGroup.Do(safeFilename) + ListQueueItems(&completed, safeFilename, …)). Since every Stremio NZB is named download.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 download is), derive a meaningful, unique name from the NZB contents before the naming/dedup/queue logic:

  • New pure helper 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.
  • Reuses existing utilities: nzbparser.Parse, fileinfo.IsProbablyObfuscated, isMediaExtension, sanitizeFilename, nzbtrim.
  • A genuinely good incoming name is preserved (override only triggers on obfuscated/generic names).

Downstream — safeFilename, nzbName, tempPath, the singleflight/dedup key, and AddToQueue — then use the unique real name, and RenameToNzbName produces 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

  • No changes to parser.determineNzbType or processor.processSingleFile — file/content selection works; only naming was broken.
  • RenameToNzbName stays on; feeding it a correct name is the fix.

Testing

  • New table-driven unit tests for 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 ✓, gofmt clean.
  • Manual end-to-end (recommended before release): issue two /api/nzb/streams requests for different releases with generic download.nzb transport names; confirm each imports under its real title and the second is not served the first's stream (distinct _queue_item_id / storage paths).

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.
@javi11 javi11 merged commit 04c963a into main Jul 6, 2026
2 checks passed
@javi11 javi11 deleted the session/sweet-jones-ac5b17 branch July 6, 2026 06: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