Move a single season of a TV show (#4)
CI / test (push) Successful in 1m14s

Shows can be expanded to list their seasons, each with its size and its own Dry run / Move buttons. A season joins the same show on the other
server, so finished seasons can go to the big server while the current one stays on the fast one.

- Source exports a season from the show folder, with a manifest of just that season's folder plus the show's loose non-video files. Refuses
  seasons with no folder of their own, or whose folder holds otherseasons' episodes.
- Destination finds the show by provider ID, then name. If it already has the show, the show's own files are skipped (Job.skip_files) and
  never overwritten; otherwise they come with the season. Refuses if the season folder already exists.
- Only episode watch state is carried for a season.
- Source trashes just the season folder; after the last season, the leftover show folder joins it in the same trash entry if no videos
  remain. The chosen trash entry is saved so a re-run after a crash finishes in the same place.
- New GET /seasons (UI and peer). Fake Jellyfin gains season items.
- e2e tests: season into a new show, into an existing show, last season leaving, destination already has the season, misfiled episodes.
This commit is contained in:
IxianPixel committed 2026-11-06 17:02:40 +00:00
1 parent 25a743b350
commit 484ac50508
21 files changed
+959 -111

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ pub mod promote;
pub mod pull;
pub mod serve;
pub use manifest::{build_manifest, hash_file, list_relative};
pub use manifest::{build_manifest, build_manifest_filtered, hash_file, list_relative};
pub use promote::{part_path, partial_dir, prepare_partial, promote};
pub use pull::{Puller, PullerOptions};
pub use serve::range_response;
+31 -3
View File
@@ -20,10 +20,21 @@ pub async fn hash_file(path: &Path) -> Result<String, TransferError> {
/// them sorted by relative path. Symlinks and jellymove's own hidden folders
/// are skipped.
pub async fn build_manifest(root: &Path) -> Result<Manifest, TransferError> {
build_manifest_filtered(root, |_| true).await
}
/// Like [`build_manifest`], but only for files whose relative path passes
/// `keep`, e.g. one season's folder plus the show's loose files.
pub async fn build_manifest_filtered(
root: &Path,
keep: impl Fn(&str) -> bool + Send + 'static,
) -> Result<Manifest, TransferError> {
let root_owned = root.to_path_buf();
let listed = tokio::task::spawn_blocking(move || list_files(&root_owned))
.await
.expect("list task panicked")?;
let listed = tokio::task::spawn_blocking(move || {
list_files(&root_owned).map(|l| l.into_iter().filter(|(rel, _, _)| keep(rel)).collect::<Vec<_>>())
})
.await
.expect("list task panicked")?;
let mut files = Vec::with_capacity(listed.len());
for (rel, abs, size) in listed {
@@ -101,4 +112,21 @@ mod tests {
blake3::hash(b"video").to_hex().to_string()
);
}
#[tokio::test]
async fn filtered_manifest_keeps_only_matching_files() {
let dir = tempfile::tempdir().unwrap();
let root = dir.path();
for f in ["tvshow.nfo", "Season 01/a.mkv", "Season 02/b.mkv"] {
std::fs::create_dir_all(root.join(f).parent().unwrap()).unwrap();
std::fs::write(root.join(f), b"x").unwrap();
}
let m = build_manifest_filtered(root, |rel| {
!rel.contains('/') || rel.starts_with("Season 02/")
})
.await
.unwrap();
let names: Vec<_> = m.files.iter().map(|f| f.rel_path.as_str()).collect();
assert_eq!(names, ["Season 02/b.mkv", "tvshow.nfo"]);
}
}
+12 -3
View File
@@ -29,16 +29,25 @@ pub async fn prepare_partial(partial: &Path) -> Result<(), TransferError> {
Ok(())
}
/// Rename every verified `.part` into `target_folder`. Safe to run again after
/// Rename every verified `.part` into `target_folder`, except the manifest
/// entries listed in `skip` (which were never copied). Safe to run again after
/// a crash: files already in place (part gone, target present with the right
/// size) are skipped. Refuses to overwrite anything it didn't put there.
pub async fn promote(
partial: &Path,
target_folder: &Path,
manifest: &Manifest,
skip: &[usize],
) -> Result<(), TransferError> {
let wanted = || {
manifest
.files
.iter()
.enumerate()
.filter(|(idx, _)| !skip.contains(idx))
};
// Check every destination first so we never half-promote into a clash.
for (idx, entry) in manifest.files.iter().enumerate() {
for (idx, entry) in wanted() {
let dest = join_relative(target_folder, &entry.rel_path)
.ok_or_else(|| TransferError::UnsafePath(entry.rel_path.clone()))?;
let part_exists = tokio::fs::metadata(part_path(partial, idx)).await.is_ok();
@@ -47,7 +56,7 @@ pub async fn promote(
}
}
for (idx, entry) in manifest.files.iter().enumerate() {
for (idx, entry) in wanted() {
let part = part_path(partial, idx);
let dest = join_relative(target_folder, &entry.rel_path).expect("checked above");
match tokio::fs::metadata(&part).await {
+35 -3
View File
@@ -119,7 +119,7 @@ async fn pull_all(fx: &Fixture, p: &Puller) -> PathBuf {
.unwrap();
}
let target = lib_root.join("Alien (1979)");
promote(&partial, &target, &manifest).await.unwrap();
promote(&partial, &target, &manifest, &[]).await.unwrap();
target
}
@@ -200,7 +200,7 @@ async fn refuses_to_overwrite_existing_files() {
.await
.unwrap();
}
let err = promote(&partial, &target, &manifest).await.unwrap_err();
let err = promote(&partial, &target, &manifest, &[]).await.unwrap_err();
assert!(matches!(err, jm_transfer::TransferError::Exists(_)));
// Nothing was moved: the stranger's file is untouched and no video landed.
assert_eq!(
@@ -216,11 +216,43 @@ async fn promote_is_idempotent() {
let target = pull_all(&fx, &puller()).await;
let manifest = build_manifest(&fx.src.root).await.unwrap();
// A second promote after a "crash" finds everything already in place.
promote(&partial_dir(fx.dst_dir.path(), "job1"), &target, &manifest)
promote(&partial_dir(fx.dst_dir.path(), "job1"), &target, &manifest, &[])
.await
.unwrap();
}
#[tokio::test]
async fn promote_leaves_skipped_files_alone() {
let fx = fixture().await;
let manifest = build_manifest(&fx.src.root).await.unwrap();
let nfo = manifest
.files
.iter()
.position(|f| f.rel_path == "Alien (1979).nfo")
.unwrap();
// The target already has its own NFO; that entry is skipped and never copied.
let target = fx.dst_dir.path().join("Alien (1979)");
std::fs::create_dir_all(&target).unwrap();
std::fs::write(target.join("Alien (1979).nfo"), b"mine").unwrap();
let partial = partial_dir(fx.dst_dir.path(), "job1");
prepare_partial(&partial).await.unwrap();
let p = puller();
for (idx, entry) in manifest.files.iter().enumerate() {
if idx == nfo {
continue;
}
let url = format!("{}/files/{idx}", fx.base);
p.pull_verified(&url, entry, &part_path(&partial, idx), &mut |_| {})
.await
.unwrap();
}
promote(&partial, &target, &manifest, &[nfo]).await.unwrap();
assert_eq!(std::fs::read(target.join("Alien (1979).nfo")).unwrap(), b"mine");
assert!(target.join("Alien (1979).mkv").exists());
// And it's still idempotent.
promote(&partial, &target, &manifest, &[nfo]).await.unwrap();
}
#[tokio::test]
async fn bandwidth_limit_is_applied() {
let fx = fixture().await;