Container image for organize-media.py, which sorts new downloads into a Jellyfin library
87
Container image for organize-media.py, which sorts new downloads into a Jellyfin library.
The script asks Claude (Haiku by default, through the Claude Code CLI) to identify each video
from its release-style path, then moves it into place:
/movies/Title (Year)/Title (Year).ext
/shows/Show (Year)/Season 01/Show - S01E01[ - Episode title].ext
Nothing is deleted or overwritten. Matching subtitles move with their video. Whatever is left
of a release folder (nfo, samples, ...) is parked in /source/_leftovers/, and every run that
moves files writes an undo log to /source/_leftovers/logs/.
Without --apply the script only does a dry run and prints the plan.
docker build -t organize-media docker/organize-media
The Claude Code CLI version is pinned with --build-arg CLAUDE_CODE_VERSION=<version>
(default latest).
| Variable | Default | Purpose |
|---|---|---|
ANTHROPIC_API_KEY | Claude auth with an API key | |
CLAUDE_CODE_OAUTH_TOKEN | Claude auth with a subscription token (claude setup-token) | |
PUID / PGID | 1000 | User and group the script runs as, and that moved files belong to |
INTERVAL | unset | Rerun forever with this pause (sleep syntax, e.g. 1h); unset runs once |
SOURCE_DIR | /source | Folder with the unsorted downloads |
MOVIES_DIR | /movies | Movie library |
SHOWS_DIR | /shows | Show library |
Set one of the two auth variables. Mount a volume at /home/app: it holds the Claude CLI
config and the cache of Claude's answers, so files seen before are not sent to Claude again.
Arguments after the image name go to the script: --apply, specific paths to sort,
--model, --batch, --no-cache and --undo LOGFILE.
The libraries can live inside the source folder. The script recognises /source/Movies and
/movies as the same folder and does not re-sort the library:
-v /mnt/nas/media:/source -v /mnt/nas/media/Movies:/movies -v /mnt/nas/media/Shows:/shows
Each bind mount counts as its own filesystem, even on the same disk, so a move from /source
to /movies is a full copy followed by a delete: slow, and it needs free space for one extra
copy of the file. To keep moves instant, mount only the parent and point the libraries into it:
-v /mnt/nas/media:/source -e MOVIES_DIR=/source/Movies -e SHOWS_DIR=/source/Shows
One dry run:
docker run --rm -e CLAUDE_CODE_OAUTH_TOKEN=... \
-v /mnt/nas/media:/source -v /mnt/nas/media/Movies:/movies -v /mnt/nas/media/Shows:/shows \
-v organize-media-home:/home/app organize-media
Every hour with Docker Compose. Scheduled runs need --apply, otherwise they only print plans:
services:
organize-media:
build: ./docker/organize-media
restart: unless-stopped
command: ["--apply"]
stop_grace_period: 5m
environment:
CLAUDE_CODE_OAUTH_TOKEN: ${CLAUDE_CODE_OAUTH_TOKEN}
INTERVAL: 1h
PUID: 1000
PGID: 1000
volumes:
- /mnt/nas/media:/source
- /mnt/nas/media/Movies:/movies
- /mnt/nas/media/Shows:/shows
- organize-media-home:/home/app
volumes:
organize-media-home:
A failed run is logged and retried after the next pause. A stop during the pause exits at once;
a stop during a run lets the run finish first, which is what stop_grace_period leaves time for.
The undo logs hold container paths, so run the undo in the container with the same mounts:
docker run --rm -v /mnt/nas/media:/source -v /mnt/nas/media/Movies:/movies \
-v /mnt/nas/media/Shows:/shows organize-media --undo /source/_leftovers/logs/organize-<timestamp>.tsv
Content type
Image
Digest
sha256:a5b5d5206…
Size
357.6 MB
Last updated
24 days ago
docker pull slinred/organize-media