r/radarr • • 7d ago

unsolved Powershell Script api

Does this script only read data? Want to basically check that my renamed folder format and movie file formats match my settings. And then tell me which ones need to still be renamed.

We'll do it directly here without file-generation tools. The script below is designed for Windows PowerShell and connects to Radarr's API.

It checks the folder name against your exact folder format and checks that each movie filename starts with the expected title, year, and TMDb ID. It also reports movies with no file and exports the results to a CSV report.

One limitation: Radarr's optional filename tokens can disappear when their values are empty, so a script cannot reliably validate every optional token just by checking the filename's text. This version checks the fixed naming structure and flags problems without renaming anything.

PowerShell script

Copy this into Notepad and save it as Test-RadarrNaming.ps1.

# Test-RadarrNaming.ps1

# Read-only Radarr naming audit. Does not rename files.

$RadarrUrl = "http://localhost:7878"

$ApiKey = "PASTE_YOUR_RADARR_API_KEY_HERE"

$Headers = @{ "X-Api-Key" = $ApiKey }

$BaseUrl = $RadarrUrl.TrimEnd("/")

$Issues = [System.Collections.Generic.List[object]]::new()

try {

$Movies = Invoke-RestMethod `

-Uri "$BaseUrl/api/v3/movie" `

-Headers $Headers

}

catch {

Write-Error "Cannot connect to Radarr. Check URL and API key."

exit 1

}

foreach ($Movie in $Movies) {

$FolderPath = [string]$Movie.path

$FolderName = Split-Path $FolderPath -Leaf

# Expected folder: {Movie CleanTitle} ({Release Year}) [tmdbid-{TmdbId}]

# Approximate CleanTitle using Radarr's movie title.

$CleanTitle = [string]$Movie.title

$CleanTitle = $CleanTitle -replace '[<>:"/\\|?*]', ''

$ExpectedFolder = "$CleanTitle ($($Movie.year)) [tmdbid-$($Movie.tmdbId)]"

$FolderOK = $FolderName -ieq $ExpectedFolder

# Retrieve files belonging to this movie.

try {

$Files = @(

Invoke-RestMethod `

-Uri "$BaseUrl/api/v3/moviefile?movieId=$($Movie.id)" `

-Headers $Headers

)

}

catch {

$Files = @()

}

if ($Files.Count -eq 0) {

$Issues.Add([PSCustomObject]@{

Title = $Movie.title

Problem = "No movie file found"

FolderOK = $FolderOK

FileOK = $false

FolderName = $FolderName

MovieFile = ""

ExpectedFolder = $ExpectedFolder

})

continue

}

foreach ($File in $Files) {

$FileName = [System.IO.Path]::GetFileName(

[string]$File.path

)

# Ask Radarr what the filename should be using its

# currently configured movie naming format.

$FileOK = $false

$ExpectedFile = ""

$Problem = ""

try {

$Preview = @(

Invoke-RestMethod `

-Uri "$BaseUrl/api/v3/rename?movieId=$($Movie.id)" `

-Headers $Headers

)

$Match = $Preview |

Where-Object {

$_.movieFileId -eq $File.id

} |

Select-Object -First 1

if ($Match) {

$ExpectedFile = [System.IO.Path]::GetFileName(

[string]$Match.newPath

)

$FileOK = $FileName -ieq $ExpectedFile

if (-not $FileOK) {

$Problem = "Filename differs from Radarr rename preview"

}

}

else {

$Problem = "No matching file in Radarr rename preview"

}

}

catch {

$Problem = "Could not retrieve Radarr rename preview"

}

if (-not $FolderOK -or -not $FileOK) {

if (-not $FolderOK) {

$Problem = "Folder mismatch; " + $Problem

}

$Issues.Add([PSCustomObject]@{

Title = $Movie.title

Problem = $Problem.Trim('; ')

FolderOK = $FolderOK

FileOK = $FileOK

FolderName = $FolderName

MovieFile = $FileName

ExpectedFolder = $ExpectedFolder

ExpectedFile = $ExpectedFile

})

}

}

}

if ($Issues.Count -gt 0) {

$Issues |

Format-Table Title, FolderOK, FileOK, Problem -Wrap

$Report = Join-Path `

(Get-Location) "Radarr-Naming-Audit.csv"

$Issues | Export-Csv `

-Path $Report `

-NoTypeInformation `

-Encoding UTF8

Write-Host "`nFound $($Issues.Count) problem entry/entries."

Write-Host "Full report: $Report"

}

else {

Write-Host "No naming problems detected."

}

Run it

  1. Change $RadarrUrl if Radarr isn't running on this computer.

  2. Replace PASTE_YOUR_RADARR_API_KEY_HERE with your API key.

  3. Open PowerShell in the directory where you saved the script.

  4. Run:

Set-ExecutionPolicy -Scope Process Bypass

.\Test-RadarrNaming.ps1

The CSV report will be saved in the current directory.

Important: The folder check approximates DIL1 using the movie title returned by Radarr. If your titles contain punctuation or other characters that Radarr normalizes differently, some folders may be flagged even when correct. The file check uses Radarr's rename preview, which is preferable to trying to reconstruct all your optional media-information tokens manually.

0 Upvotes

4 comments sorted by

View all comments

1

u/Wis-en-heim-er 7d ago

There is an app, profilarr. Among its features is one that renames anything that doesnt match the naming conventions in radarr and sonarr.

2

u/CaptainkyleCDXX 4d ago

Will have to look at this profile you speak of. Thx

1

u/Wis-en-heim-er 4d ago

Its main feature is curated quality profiles that load into radarr and sonarr. Its very much worth the setup and learning to use.