feat(import): import a whole folder as one sequence per format
Owner review 2, R9: Import › Folder… gains a "Group" choice for picked folders: Sessions (as before) or Whole folder. A whole folder, with its subfolders when Subfolders is on, becomes one sequence per file format; camera bodies and pauses are ignored, while RAW+JPEG of the same shots stays two sequences so no frame is ever doubled. Only the user's splits break it, and Merge joins a split part back. The planner implements it (ImportOptions.Grouping, Core, Linux-tested): the session key is "folder-" plus a hash of this PC's name, the full path and the format, so an interrupted or repeated import continues the same sequence; the default title is the folder's name. The plan shows one row per format with the format and the number of cameras. Cards and drives always import by sessions; the choice is not part of a card profile and a folder starts on Sessions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5209579631
commit
445dfd41a3
14 files changed
+419
-26
No files matched your search
@@ -94,6 +94,16 @@ public sealed class ImportChoicesTests
|
||||
Assert.SequenceEqual([fresh.Id], joined.Without(own.Id).Cards);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheGroupingTravelsToThePlannerButNeverIntoACardProfile()
|
||||
{
|
||||
var whole = new ImportChoices { Grouping = ImportGrouping.WholeFolder };
|
||||
Assert.Equal(ImportGrouping.WholeFolder, whole.ToOptions().Grouping);
|
||||
Assert.Equal(ImportGrouping.Sessions, new ImportChoices().ToOptions().Grouping, "a source starts with its sessions");
|
||||
Assert.True(whole.NeedsNewPlan(new ImportChoices()), "the grouping changes which photos form which sequence");
|
||||
Assert.Equal(ImportGrouping.Sessions, ImportChoices.FromProfile(whole.ToProfile()).Grouping, "a card always imports by sessions");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SplitsAndMergesTravelToThePlanner()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Globalization;
|
||||
using Chronos.App.Import;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Testing;
|
||||
@@ -175,6 +176,51 @@ public sealed class ImportPlansTests
|
||||
Assert.Equal(1, split[2].MergesInto, "the earlier session of the same body, skipping the other camera");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AWholeFolderRowShowsItsFormatAndCamerasWithTheFolderNameAsDefaultTitle()
|
||||
{
|
||||
var jpeg = Session(1, "2026/2026-09-28 Canon EOS R5", Item(1, Start), Item(2, Start.AddHours(5))) with
|
||||
{
|
||||
SessionKey = "folder-jpeg",
|
||||
Format = ImageFileFormat.Jpeg,
|
||||
Cameras = 2,
|
||||
Title = "Etna",
|
||||
DefaultTitle = "Etna",
|
||||
};
|
||||
var raw = Session(2, "2026/2026-09-28 Canon EOS R5 (2)", Item(3, Start), Item(4, Start.AddHours(5))) with
|
||||
{
|
||||
SessionKey = "folder-raw",
|
||||
Title = "Etna",
|
||||
DefaultTitle = "Etna",
|
||||
};
|
||||
var plan = Plan(null, null, jpeg, raw) with { Grouping = ImportGrouping.WholeFolder };
|
||||
|
||||
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>());
|
||||
Assert.Equal("2 cameras · JPEG", rows[0].CameraText);
|
||||
Assert.Equal("Canon EOS R5 · CR2", rows[1].CameraText);
|
||||
Assert.Null(rows[0].Title, "the folder's name is the placeholder, not typed text");
|
||||
Assert.Equal("Etna", rows[0].DefaultTitle);
|
||||
Assert.Null(rows[1].MergesInto, "another format never merges");
|
||||
var bySessions = ImportPlans.Sessions(plan with { Grouping = ImportGrouping.Sessions }, ImportDestinationKind.Archive, new HashSet<string>());
|
||||
Assert.Equal("Canon EOS R5", bySessions[1].CameraText);
|
||||
|
||||
var titled = ImportPlans.WithTitles(plan, new Dictionary<string, string> { ["folder-jpeg"] = "Etna at night" });
|
||||
Assert.Equal("Etna at night", titled.Sessions[0].Title);
|
||||
Assert.Equal("Etna", titled.Sessions[1].Title, "a sequence without a typed title keeps the folder's name");
|
||||
Assert.Equal("Etna at night", ImportPlans.Sessions(titled, ImportDestinationKind.Archive, new HashSet<string>())[0].Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AWholeFolderPartMergesBackIntoThePartBeforeItOfTheSameFormatWhateverItsCamera()
|
||||
{
|
||||
var first = Session(1, "2026/Etna", Item(1, Start));
|
||||
var second = Session(2, "2026/Etna (2)", Item(2, Start.AddHours(1))) with { CameraMake = "Nikon", CameraModel = "NIKON Z 8" };
|
||||
var plan = Plan(null, null, first, second) with { Grouping = ImportGrouping.WholeFolder };
|
||||
Assert.Equal(1, ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>())[1].MergesInto);
|
||||
Assert.Null(ImportPlans.Sessions(plan with { Grouping = ImportGrouping.Sessions }, ImportDestinationKind.Archive, new HashSet<string>())[1].MergesInto,
|
||||
"sessions of another camera never merge");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ShowPlanOffersASplitOnEveryPhotoButTheFirstOfItsSession()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Imaging;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Metadata;
|
||||
using Chronos.Core.Tests.Archiving;
|
||||
using Chronos.Testing;
|
||||
using static Chronos.Core.Tests.Import.ImportTestKit;
|
||||
@@ -163,6 +165,118 @@ public sealed class ImportPlannerTests(TestContext context)
|
||||
Assert.SequenceEqual([5, 5, 10], split.Sessions.Select(s => s.Items.Count));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderIsOneSequenceWhateverTheCameraBodiesAndPauses()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Etna eruption");
|
||||
TestPhotos.WriteSeries(folder, Start, 10, Interval, prefix: "CAN_");
|
||||
TestPhotos.WriteSeries(folder, Start.AddHours(3), 10, Interval, firstSeed: 20, prefix: "CAN_", firstNumber: 11);
|
||||
TestPhotos.WriteSeries(folder, Start.AddSeconds(5), 3, Interval, firstSeed: 40, prefix: "NIK_", make: "NIKON CORPORATION", model: "NIKON Z 8");
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
Assert.Equal(3, (await PlanAsync(folder, destination)).Sessions.Count, "by sessions: two Canon sessions and the Nikon");
|
||||
|
||||
var plan = await PlanAsync(folder, destination, new ImportOptions { Grouping = ImportGrouping.WholeFolder, FolderTemplate = "{year}/{title}" });
|
||||
Assert.Equal(ImportGrouping.WholeFolder, plan.Grouping);
|
||||
var session = plan.Sessions.Single();
|
||||
Assert.Equal(23, session.Items.Count);
|
||||
Assert.Equal(2, session.Cameras);
|
||||
Assert.Equal("Etna eruption", session.Title, "the folder's name is the default title");
|
||||
Assert.Equal("Etna eruption", session.DefaultTitle);
|
||||
Assert.Equal("2026/Etna eruption", session.Folder);
|
||||
Assert.SequenceEqual(session.Items.OrderBy(i => i.CapturedAt).Select(i => i.SourcePath), session.Items.Select(i => i.SourcePath),
|
||||
"both bodies in capture order");
|
||||
Assert.Equal("2026-09-28_21-01-30_0023.JPG", session.Items[^1].FileName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderOfRawAndJpegIsTwoSequencesSoNoFrameIsDoubled()
|
||||
{
|
||||
var photos = new List<CardPhoto>();
|
||||
for (var i = 0; i < 6; i++)
|
||||
{
|
||||
// An hour between shots: far beyond the session gap, ignored for a whole folder.
|
||||
var at = Start.AddHours(i);
|
||||
photos.Add(Photo($"IMG_{i:0000}.JPG", at, ImageFileFormat.Jpeg));
|
||||
photos.Add(Photo($"IMG_{i:0000}.CR3", at, ImageFileFormat.Cr3));
|
||||
}
|
||||
var plan = await ImportPlanner.PlanAsync(context.CreateTempDirectory("raw+jpeg"), context.CreateTempDirectory("archive"), photos, [],
|
||||
new ImportOptions { Grouping = ImportGrouping.WholeFolder }, new FakeLookup());
|
||||
|
||||
Assert.Equal(2, plan.Sessions.Count, "one sequence per format");
|
||||
Assert.SequenceEqual([ImageFileFormat.Jpeg, ImageFileFormat.Cr3], plan.Sessions.Select(s => s.Format).OrderBy(f => f));
|
||||
foreach (var session in plan.Sessions)
|
||||
{
|
||||
Assert.Equal(6, session.Items.Count);
|
||||
Assert.Equal(1, session.Items.Select(i => Path.GetExtension(i.SourcePath)).Distinct().Count(), "one format per sequence");
|
||||
}
|
||||
Assert.Equal(12, plan.Items.Select(i => i.SourcePath).Distinct().Count(), "every photo is planned once");
|
||||
Assert.NotEqual(plan.Sessions[0].SessionKey, plan.Sessions[1].SessionKey);
|
||||
Assert.NotEqual(plan.Sessions[0].Folder, plan.Sessions[1].Folder);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderTakesItsSubfoldersOnlyWhenAsked()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Construction");
|
||||
TestPhotos.WriteSeries(folder, Start, 4, Interval);
|
||||
TestPhotos.WriteSeries(Path.Combine(folder, "week 2"), Start.AddDays(7), 4, Interval, firstSeed: 50, firstNumber: 5);
|
||||
TestPhotos.WriteSeries(Path.Combine(folder, "week 2", "monday"), Start.AddDays(8), 4, Interval, firstSeed: 70, firstNumber: 9);
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
var whole = new ImportOptions { Grouping = ImportGrouping.WholeFolder };
|
||||
|
||||
var all = (await PlanAsync(folder, destination, whole)).Sessions.Single();
|
||||
Assert.Equal(12, all.Items.Count);
|
||||
Assert.Equal("week 2/monday/IMG_0012.JPG", all.Items[^1].SourcePath);
|
||||
var top = (await PlanAsync(folder, destination, whole with { IncludeSubfolders = false })).Sessions.Single();
|
||||
Assert.Equal(4, top.Items.Count);
|
||||
Assert.Equal(all.SessionKey, top.SessionKey, "the same folder's sequence, whatever is scanned in it");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderKeepsItsKeySoAnInterruptedImportResumesIntoItsSequence()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Etna");
|
||||
TestPhotos.WriteSeries(folder, Start, 10, Interval);
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
var whole = new ImportOptions { Grouping = ImportGrouping.WholeFolder };
|
||||
var first = (await PlanAsync(folder, destination, whole)).Sessions.Single();
|
||||
Assert.True(first.SessionKey.StartsWith("folder-", StringComparison.Ordinal), first.SessionKey);
|
||||
Assert.Equal(first.SessionKey, ImportPlanner.FolderKey(folder + Path.DirectorySeparatorChar, ImageFileFormat.Jpeg),
|
||||
"a trailing separator names the same folder");
|
||||
Assert.NotEqual(first.SessionKey, ImportPlanner.FolderKey(folder, ImageFileFormat.Cr3));
|
||||
Assert.NotEqual(first.SessionKey, ImportPlanner.FolderKey(Path.Combine(folder, "other"), ImageFileFormat.Jpeg));
|
||||
|
||||
// Photos added later, earlier ones too, keep the folder's key.
|
||||
TestPhotos.WriteSeries(folder, Start.AddDays(-1), 2, Interval, firstSeed: 90, prefix: "OLD_");
|
||||
Assert.Equal(first.SessionKey, (await PlanAsync(folder, destination, whole)).Sessions.Single().SessionKey);
|
||||
|
||||
var lookup = new FakeLookup();
|
||||
lookup.SessionFolders[first.SessionKey] = "2026/Etna";
|
||||
Assert.Equal("2026/Etna", (await PlanAsync(folder, destination, whole, lookup)).Sessions.Single().Folder, "the sequence of the interrupted import");
|
||||
|
||||
var typed = whole with { Titles = new Dictionary<string, string> { [first.SessionKey] = "Etna at night" } };
|
||||
var titled = (await PlanAsync(folder, destination, typed)).Sessions.Single();
|
||||
Assert.Equal("Etna at night", titled.Title);
|
||||
Assert.Equal("Etna", titled.DefaultTitle);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderSplitsOnlyWhereTheUserSplitsIt()
|
||||
{
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Harbour");
|
||||
TestPhotos.WriteSeries(folder, Start, 10, Interval);
|
||||
var destination = context.CreateTempDirectory("archive");
|
||||
var split = new ImportOptions { Grouping = ImportGrouping.WholeFolder, SplitBefore = new HashSet<string> { "IMG_0009.JPG" } };
|
||||
|
||||
var plan = await PlanAsync(folder, destination, split);
|
||||
Assert.SequenceEqual([8, 2], plan.Sessions.Select(s => s.Items.Count), "a part the user split off stays, however short");
|
||||
Assert.Equal(ImportPlanner.FolderKey(folder, ImageFileFormat.Jpeg), plan.Sessions[0].SessionKey);
|
||||
Assert.NotEqual(plan.Sessions[0].SessionKey, plan.Sessions[1].SessionKey);
|
||||
Assert.Equal(plan.Sessions[1].SessionKey, (await PlanAsync(folder, destination, split)).Sessions[1].SessionKey);
|
||||
var merged = split with { SplitBefore = new HashSet<string>(), MergeAt = new HashSet<string> { "IMG_0009.JPG" } };
|
||||
Assert.Equal(10, (await PlanAsync(folder, destination, merged)).Sessions.Single().Items.Count, "merging the part back undoes the split");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APhotoWithoutExifIsPlannedAtItsFileTime()
|
||||
{
|
||||
@@ -177,4 +291,8 @@ public sealed class ImportPlannerTests(TestContext context)
|
||||
// No camera identity: it forms its own body group rather than joining the Canon session.
|
||||
Assert.SequenceEqual([8, 1], plan.Sessions.Select(s => s.Items.Count));
|
||||
}
|
||||
|
||||
/// <summary>A photo as the scanner reads it, without a file behind it (the planner hashes only duplicate candidates).</summary>
|
||||
private static CardPhoto Photo(string path, DateTime captured, ImageFileFormat format) => new(new CardFile(path, 1_000, captured),
|
||||
new FrameMetadata { Format = format, Make = "Canon", Model = "Canon EOS R5", BodySerial = "0431", CapturedAt = captured });
|
||||
}
|
||||
@@ -105,6 +105,35 @@ public sealed class ImportServiceTests(TestContext context)
|
||||
Assert.Equal(20, (await FramesAsync(fx, plan.Sessions.Single())).Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AWholeFolderBecomesOneSequenceNamedAfterItThatALaterImportAddsTo()
|
||||
{
|
||||
await using var fx = await CreateAsync(context);
|
||||
var folder = Path.Combine(context.CreateTempDirectory("source"), "Etna eruption");
|
||||
Photos.WriteSeries(folder, Start, 5);
|
||||
Photos.WriteSeries(folder, Start.AddHours(4), 5, firstSeed: 20, prefix: "NIK_", make: "NIKON CORPORATION", model: "NIKON Z 8");
|
||||
var whole = new ImportOptions { Grouping = ImportGrouping.WholeFolder };
|
||||
|
||||
var plan = await fx.Service.PlanImportAsync(fx.Archive.Id, folder, whole, null, null, fx.Ct);
|
||||
var session = plan.Sessions.Single();
|
||||
await RunAsync(fx, plan);
|
||||
var id = await fx.Db.Sequences.FindBySessionKeyAsync(fx.Archive.Id, session.SessionKey);
|
||||
Assert.Equal("Etna eruption", (await fx.Db.Sequences.GetAsync(id!.Value))!.Title);
|
||||
Assert.Equal(10, (await FramesAsync(fx, session)).Count);
|
||||
|
||||
// Photos added to the folder later join the same sequence; those imported before are found in the archive.
|
||||
Photos.WriteSeries(folder, Start.AddDays(1), 3, firstSeed: 40, prefix: "LATE_");
|
||||
var later = await fx.Service.PlanImportAsync(fx.Archive.Id, folder, whole, null, null, fx.Ct);
|
||||
Assert.Equal(session.SessionKey, later.Sessions.Single().SessionKey);
|
||||
Assert.Equal(session.Folder, later.Sessions.Single().Folder);
|
||||
Assert.Equal(3, later.CopyCount);
|
||||
await RunAsync(fx, later);
|
||||
Assert.Equal(13, (await FramesAsync(fx, session)).Count);
|
||||
|
||||
static Task<ImportProgress> RunAsync(ArchiveFixture fx, ImportPlan plan) => fx.Service.Imports.ExecuteAsync(
|
||||
new ImportJobParameters(fx.Archive.Id, plan, null, true, null), Guid.NewGuid(), 0, _ => ValueTask.CompletedTask, null, fx.Ct);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ErasingTheCardDeletesOnlyVerifiedImports()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user