Files
2026-11-06 17:34:22 +00:00

225 lines
9.9 KiB
Markdown

# jellymove
Move movies and TV series between two Jellyfin servers, with their subtitles,
artwork, NFOs, extras and everyone's watch history.
Built for a two-tier setup: a cloud server with fast but limited storage and
a home server with slow but large storage, presented as one library by
[Jellyswarrm](https://github.com/LLukas22/Jellyswarrm). Pick a film or series
in the web UI and send it to the other side. jellymove copies it, checks it,
gets the other Jellyfin to index it, carries the watch state across, and only
then removes it from the source.
> **Status: early (v0.1).** The whole move flow works end to end against a
> test double of Jellyfin. It has **not yet been run against a real Jellyfin
> server**. Try a dry run first, keep backups, and read "Not yet verified" below.
## How a move works
One agent runs next to each Jellyfin and sees the same media folders. The
**destination pulls**:
1. **Plan.** The source checks that the item has its own folder, hashes every
file (BLAKE3) and records each user's played state, resume points and
favourites. The destination picks a library and refuses if the folder
already exists. *Dry runs stop here.*
2. **Copy.** Files stream into a hidden `.jellymove-partial/` folder inside the
destination library. Dropped connections resume from where they stopped,
and each file is hash-checked.
3. **Promote.** Verified files are renamed into place, an atomic operation on
the same filesystem.
4. **Index.** The destination asks Jellyfin to scan that folder, then waits
until the item and every episode appear.
5. **Restore watch history.** Jellyfin gives moved files new item IDs, so
jellymove re-applies each user's data to the new items, matching users by
name. Before a move starts, jellymove warns if someone with watch history
has no account on the other server. If you move anyway, their history is
kept with the move: create the user there, then use **Re-apply watch
history** on the move in Moves. Only their history is applied, so anything
others have watched since is left alone.
6. **Clean up.** The source moves its folder to `.jellymove-trash/` in the same
library and rescans. It is not deleted: the **Trash** tab shows what's
waiting on each server, how much space it uses, and empties it when you're
ready.
A crash or restart at any point resumes from the last completed step.
### Moving a single season
In TV Shows, **Show seasons** lists a show's seasons with their sizes, each
with its own move button. A season moves into the same show on the other
server, found by its TVDB/TMDB/IMDb ID or its name, and its episodes keep
their watch history. If the other server doesn't have the show yet, the show's
own files (`tvshow.nfo`, posters) are copied with the season; if it does, they
are left alone. When the last season leaves a server, what's left of the show
folder goes to the trash with it.
A season can only move on its own if it has its own folder (`Show/Season 02/`)
holding just that season's episodes. Specials (`Season 00` or `Specials`) work
the same way.
## Quick look (no Jellyfin needed)
```sh
npm --prefix ui ci && npm --prefix ui run build
cargo run -p jm-server --example demo
# open http://127.0.0.1:8097 (cloud) and http://127.0.0.1:8098 (home)
```
## Running it for real
Install one agent per server. **Mount media at the same paths as the Jellyfin
container**, so the paths Jellyfin reports are the paths jellymove sees.
With Docker, copy [deploy/docker-compose.yml](deploy/docker-compose.yml),
fill in the `environment:` section, fix the volumes and `user:`, then:
```sh
mkdir jellymove-data && sudo chown 1000:1000 jellymove-data # same IDs as user:
docker compose run --rm jellymove check-config # prints the settings, secrets hidden
docker compose up -d
```
Every setting in [config.example.toml](config.example.toml) can be set as
`JELLYMOVE_<KEY>`, with `__` between a section and its key
(`[peer] token` → `JELLYMOVE_PEER__TOKEN`). There's no config file in this
setup, so the "config file not found; using environment only" warning at
start-up is expected. If you'd rather use a file, mount it at
`/config/jellymove.toml`. Environment variables still override it.
Each release publishes an image (x86_64) to the Gitea container registry:
`git.malgra.com/ixianpixel/jellymove:<version>`, and `:latest` for anything
that isn't a pre-release. It's the same static binary as the systemd tarball,
on Alpine. If the package isn't public, log in once with a Gitea token that
only has `read:package`:
```sh
docker login git.malgra.com
```
To upgrade, run `docker compose pull && docker compose up -d`.
- Create an admin API key in Jellyfin (Dashboard → API Keys). jellymove reads
every user's watch state.
- Use the same `peer.token` on both agents (`openssl rand -hex 32`).
- The agents talk over HTTP, and **each must be able to reach the other**: the
destination pulls, so a move *to* the cloud needs the cloud agent to reach
home. Put them on Tailscale/WireGuard (simplest), or behind your reverse
proxy with TLS. An outbound-only mode for a home server behind NAT is on
the roadmap.
- Run the container as the same user as Jellyfin (`user: "1000:1000"`) so
moved files keep the right ownership.
- Set a UI password (`[ui]`, or `JELLYMOVE_UI__USERNAME`/`__PASSWORD`)
unless the port is only reachable privately.
- The **Status** tab checks that every library folder is visible and writable.
### Without Docker (systemd)
Each release has a static Linux binary (x86_64, musl, web UI built in), so it
runs on any distro with no other dependencies:
```sh
tar -xzf jellymove-v0.1.0-x86_64-unknown-linux-musl.tar.gz
cd jellymove-v0.1.0-x86_64-unknown-linux-musl
sudo install -m 755 jellymove /usr/local/bin/jellymove
sudo install -D -m 640 -g jellyfin config.example.toml /etc/jellymove/jellymove.toml
sudo cp jellymove.service /etc/systemd/system/
sudo systemctl daemon-reload && sudo systemctl enable --now jellymove
```
Before starting it, edit `/etc/jellymove/jellymove.toml` and set
`data_dir = "/var/lib/jellymove"` (the unit's `StateDirectory`). If Jellyfin
runs as a different user, change `User=`/`Group=` in the unit and `-g` above.
To upgrade, replace `/usr/local/bin/jellymove` and run `sudo systemctl restart jellymove`.
Interrupted transfers resume after a restart.
### Making a release
`.github/workflows/release.yml` runs on Gitea Actions. To cut a release:
1. Bump `version` in the root `Cargo.toml`.
2. Add a `## v0.1.1` section to the top of `CHANGELOG.md`, using whichever of
`### Added`, `### Updated`, `### Fixed` and `### Removed` apply.
3. Commit, then push a matching tag:
```sh
git tag v0.1.1 && git push origin v0.1.1
```
The workflow runs the tests, builds the UI and binary, attaches the tarball
and its `.sha256` to a Gitea release for that tag, then pushes the Docker
image. It builds the image with `crane`, so the runner needs no Docker
socket. Gitea won't let the workflow's own token push packages, so the repo
needs two Actions secrets: `REGISTRY_USER` (your Gitea username) and
`REGISTRY_TOKEN` (a personal access token with only package read and write).
The workflow stops straight away if either is missing. The release notes
are that version's section of `CHANGELOG.md`; the workflow stops straight
away if there isn't one. Re-running it replaces the files and refreshes the
notes. Tags with a `-` (`v0.2.0-rc1`) are marked pre-release.
### Library mapping
By default an item goes into the library with the same name on the other
server. To file things elsewhere, configure this on the **receiving** agent:
```toml
[incoming_libraries]
"Movies" = "Movies (archive)"
```
### Jellyswarrm
While a move is running the item exists on both servers, and Jellyswarrm
v0.3.1+ shows it once with two versions. Jellyswarrm's merge cache can go stale
when files move ([#216](https://github.com/LLukas22/Jellyswarrm/issues/216)).
Until that is fixed upstream, restart Jellyswarrm after a move if the merged
view looks wrong. A post-move hook can do it for you:
```toml
[hooks]
post_move = "docker restart jellyswarrm"
```
The hook runs with `sh -c` on the **receiving** agent, so it only helps if
Jellyswarrm runs on that machine. The Docker image has a shell but no Docker
CLI, and mounting `/var/run/docker.sock` gives the container root on the
host. Prefer a socket proxy that only allows restarts, or restart by hand.
## Safety rules
- Nothing leaves the source until the destination has indexed every file.
- The source copy goes to `.jellymove-trash/`. Empty it from the **Trash** tab once you're
happy (automatic retention is on the roadmap).
- Nothing at the destination is ever overwritten. A season move refuses if
that season's folder already exists there.
- A movie must be in **its own folder**. jellymove refuses flat folders like
`Movies/Heat.mkv` + `Movies/Ronin.mkv`, because moving "the folder" would take both.
- Peers can only fetch files the source has explicitly exported, by index.
## Not yet verified
- Against real Jellyfin, in particular user-data writes
(`POST /UserItems/{id}/UserData`), `/Library/Media/Updated` timing on large
libraries, and multi-version movies.
- Against real Jellyswarrm.
- Running the published Docker image, and building from the `Dockerfile`.
The image's contents and config are checked, but it hasn't been started yet.
- Windows and macOS. The code is cross-platform, but only Linux has been run.
## Roadmap
- "Promote" (pre-warm) shortcuts
- Automatic trash retention (e.g. empty after N days)
- Pairing codes and pinned TLS instead of a shared token
- Outbound-only control channel so a NATed home agent needs no inbound port
- Automatic tiering rules ("demote anything unwatched for 90 days when the cloud disk is over 80%")
- Sonarr/Radarr root-folder updates so the *arrs follow the move
- iroh transport (built-in NAT traversal); scheduled bandwidth windows
- `jellymove service install` (systemd/launchd/Windows service)
## Development
See [CLAUDE.md](CLAUDE.md) for layout, commands and invariants, and
[docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the design.