Briefing for coding agents and new maintainers working on this repo. Keep changes safe, small, and well tested.
RemoveSamples-NZBGet is a Post-Processing extension for NZBGet v23+. It finds and removes “sample” clips and junk assets from completed downloads using name patterns and size thresholds. It only performs destructive actions when the overall download status indicates success.
Goals:
- Idempotent and predictable runs
- Contract correctness
- Clear, minimal logs with a one-line summary
- Cross-platform behavior on Windows and Linux
Execution order: after ExtendedUnpacker, before Clean and before media managers scan the payload.
Exit codes:
POSTPROCESS_SUCCESS = 93POSTPROCESS_ERROR = 94POSTPROCESS_NONE = 95
Env vars read at runtime:
Required
NZBPP_DIRECTORYNZBPP_STATUSwith fallbackNZBPP_TOTALSTATUS
Optional
NZBPP_NZBNAMENZBPP_CATEGORY
Required options provided as env vars:
NZBPO_REMOVEDIRECTORIESNZBPO_REMOVEFILESNZBPO_DEBUGNZBPO_VIDEOSIZETHRESHOLDMBNZBPO_VIDEOEXTSNZBPO_AUDIOSIZETHRESHOLDMBNZBPO_AUDIOEXTS
Optional toggles (read only if present, some land in v1.1.0):
NZBPO_TESTMODENZBPO_BLOCKIMPORTDURINGTESTNZBPO_RELATIVEPERCENTNZBPO_PROTECTEDPATHSNZBPO_DENYPATTERNSNZBPO_IMAGESAMPLESNZBPO_JUNKEXTRASNZBPO_CATEGORYTHRESHOLDSNZBPO_QUARANTINEMODENZBPO_QUARANTINEMAXAGEDAYS
If you need a new NZBPO_* key, open an issue first.
- Name patterns: case-insensitive matches for words like
sample, common dot variants, and typical scene junk. Never hard-code titles. Prefer pattern lists that are user configurable. - Size thresholds: treat very small video or audio as samples. Defaults come from the options above. Relative-percent can be used when enabled.
- Category overrides: when enabled, thresholds may vary by
NZBPP_CATEGORY.
- If
NZBPP_STATUSorNZBPP_TOTALSTATUSis not success, exit 95 without changing files. - Perform deletions or moves only when
NZBPO_REMOVEFILES=yesorNZBPO_REMOVEDIRECTORIES=yes. WhenNZBPO_TESTMODE=yes, never modify files (simulate only). - Never traverse above
NZBPP_DIRECTORY. Reject symlinks. - Respect
PROTECTEDPATHSand deny lists. When quarantine is enabled, move to_samples_quarantineand optionally purge by age. - Keep the Windows UTF-8 console safeguard near the top of
main.pyso debug logs do not throwUnicodeEncodeError. - Never traverse above
NZBPP_DIRECTORY. Reject symlinks and Windows junctions.
[INFO]actions,[ERROR]failures,[DEBUG]only whenNZBPO_DEBUGis true.- Always print one final summary line, for example:
Summary: removed 2 files, 1 dir; quarantined 0; errors 0; exit=93 - Return the correct exit code.
Linux or macOS (bash):
export NZBPP_DIRECTORY="/abs/path/to/testdir"
export NZBPP_STATUS=SUCCESS
export NZBPO_REMOVEDIRECTORIES=yes
export NZBPO_REMOVEFILES=yes
export NZBPO_DEBUG=no
export NZBPO_VIDEOSIZETHRESHOLDMB=150
export NZBPO_VIDEOEXTS=".mkv,.mp4,.avi,.mov,.ts,.m4v"
export NZBPO_AUDIOSIZETHRESHOLDMB=2
export NZBPO_AUDIOEXTS=".mp3,.flac,.m4a,.ogg,.wav"
export NZBPO_TESTMODE=yes
# Optional toggles:
# export NZBPO_BLOCKIMPORTDURINGTEST=yes
# export NZBPO_QUARANTINEMODE=yes
# export NZBPO_QUARANTINEMAXAGEDAYS=30
python3 main.py; echo "exit=$?"Windows PowerShell:
$env:NZBPP_DIRECTORY = "C:\Path\To\testdir"
$env:NZBPP_STATUS = "SUCCESS"
$env:NZBPO_REMOVEDIRECTORIES = "yes"
$env:NZBPO_REMOVEFILES = "yes"
$env:NZBPO_DEBUG = "no"
$env:NZBPO_VIDEOSIZETHRESHOLDMB = "150"
$env:NZBPO_VIDEOEXTS = ".mkv,.mp4,.avi,.mov,.ts,.m4v"
$env:NZBPO_AUDIOSIZETHRESHOLDMB = "2"
$env:NZBPO_AUDIOEXTS = ".mp3,.flac,.m4a,.ogg,.wav"
$env:NZBPO_TESTMODE = "yes"
# Optional toggles (uncomment as needed)
# $env:NZBPO_BLOCKIMPORTDURINGTEST = "yes"
# $env:NZBPO_QUARANTINEMODE = "yes"
# $env:NZBPO_QUARANTINEMAXAGEDAYS = "30"
python .\main.py; echo "exit=$LASTEXITCODE"Test corpus guidelines:
- Include nested
samplefolders, tiny audio, a few image assets, long and Unicode paths. Verify summary text and exit code.
- Keep env parsing helpers tight and explicit. Do not assume casing or presence.
- Avoid OS-specific path assumptions. Use
pathlibwhere possible. - Do not hard-code user policy. Use options and flags.
- Increment version when behavior changes and update the changelog.
- PR title in imperative mood and scoped, for example:
fix: honor ProtectedPaths under dry run. - Include what you tested, on which OS, and the observed exit code.
- Acceptance criteria:
- Contract header values unchanged
- Required env keys and option names intact
- One summary line in logs
- Windows UTF-8 safeguard present
- Local smoke test completed
- Adjust thresholds: change option defaults and descriptions, not the detection core.
- Add deny pattern: extend
NZBPO_DENYPATTERNSlist, not hard-coded checks. - Protect a file or dir: add to
NZBPO_PROTECTEDPATHS. - Enable quarantine: set
QuarantineMode=Yes, optionallyQuarantineMaxAgeDays>0.
If uncertain, run a one-minute local simulation and include 2–3 bullets of findings in the PR.
Maintainer: Anunnaki-Astronaut
URL: https://github.com/Anunnaki-Astronaut/RemoveSamples-NZBGet