Clean up leftover {tmdb-...} folders in a media library
Media managers (Radarr, Sonarr, Jellyfin) name folders like Movie (2020) {tmdb-12345}. When an item is removed or re-imported, a folder can be left behind with just artwork or an .nfo file. This how-to finds those folders and removes them, after showing you the list first.
Find candidates (dry run)
A candidate is a folder with { or } in its name, no subfolders, exactly two files, and no video file:
#!/bin/bash
root=${1:?usage: tmdb-clean <library> [--delete]}
find "$root" -mindepth 1 -type d \( -name '*{*' -o -name '*}*' \) -print0 |
while IFS= read -r -d '' d; do
subs=$(find "$d" -mindepth 1 -maxdepth 1 -type d | wc -l)
files=$(find "$d" -maxdepth 1 -type f | wc -l)
vids=$(find "$d" -maxdepth 1 -type f \( -iname '*.mkv' -o -iname '*.mp4' -o -iname '*.avi' -o -iname '*.m4v' \) | wc -l)
if (( subs == 0 && files == 2 && vids == 0 )); then
if [[ ${2:-} == --delete ]]; then rm -rf -- "$d"; echo "deleted: $d"
else echo "would delete: $d"; fi
fi
done
Use it
./tmdb-clean.sh /mnt/media/movies # review the list
./tmdb-clean.sh /mnt/media/movies --delete # then delete
- The video check is important. Without it, a folder with one movie and one subtitle file also matches "exactly two files".
-
-print0withread -d ''handles any file name safely. - Rescan the library in your media server afterwards.