Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Sonarr & Radarr Mirror Cleanup Scripts

Python

These scripts compare the target instance against the source and remove items from the target that:

  • Do not exist in the source, or
  • Exist in the source but are not in allowed quality profiles (optional)

Designed for mirrored libraries, read-only replicas, or downstream servers.


Features

  • Works for both Sonarr and Radarr.
  • Safe dry-run/debug mode to preview changes before applying.
  • Optional delete files mode to remove media from disk.
  • Uses TVDB IDs (Sonarr) and TMDB IDs (Radarr) for accurate matching.
  • Confirmation prompt before deleting (can be disabled).
  • Designed for consistency between Sonarr and Radarr scripts.

Requirements

  • Python 3.9+
  • requests library (pip install requests)
  • Sonarr v3 or Radarr v3 API access

Configuration

Both scripts have configuration flags at the top of the file for easy setup:

DEBUG_MODE = True            # True = show differences only, NO changes
DELETE_FILES = True          # True = delete media files on disk
REQUIRE_CONFIRMATION = True  # Ask before deleting (ignored in DEBUG_MODE)

# Example for Sonarr
SONARR_1_URL = "https://sonarr.source.url"
SONARR_1_API_KEY = "API_KEY_HERE"
SONARR_2_URL = "http://sonarr.target.url"
SONARR_2_API_KEY = "API_KEY_HERE"

# Example for Radarr
RADARR_1_URL = "https://radarr.source.url"
RADARR_1_API_KEY = "API_KEY_HERE"
RADARR_2_URL = "http://radarr.target.url"
RADARR_2_API_KEY = "API_KEY_HERE"

Profile Enforcement (Optional)

ENFORCE_SOURCE_PROFILES = True

ALLOWED_PROFILE_NAMES = [
    "HD - 720p/1080p + 4K"
]

If enabled:

  • Items not in the allowed profiles in the source will be removed from the target.

Flags

Flag Description
DEBUG_MODE True = Preview differences, do not delete anything
DELETE_FILES True = Remove media files from disk
REQUIRE_CONFIRMATION True = Prompt before deletion (ignored in DEBUG_MODE)

Safe Testing Workflow

  1. Dry-run only:
DEBUG_MODE = True
DELETE_FILES = False
  1. Remove from target only (no files deleted):
DEBUG_MODE = False
DELETE_FILES = False
  1. Full cleanup (delete from target + files):
DEBUG_MODE = False
DELETE_FILES = True

You can also disable the confirmation prompt by setting REQUIRE_CONFIRMATION = False.


Safety Notes

  • Scripts use TVDB ID (Sonarr) and TMDB ID (Radarr) to avoid accidental deletion based on title mismatches.
  • Always run in DEBUG_MODE first to verify the list of items that will be deleted.
  • Backup your Sonarr/Radarr database before performing destructive runs.
  • Works best with Sonarr/Radarr v3 APIs.

About

Cleanup scripts for Radarr and Sonarr Instances

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages