Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Put Extract audio on the video donut's back face when upgrading

cre8ive-marketing94ec0a77a8bf
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index 15e65f5d..1dd65645 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -753,6 +753,7 @@ internal static class SettingsMigrations
// v33: everyday tools (compress image / video / audio, video from images, extract audio, merge videos / audio,
// remove metadata), after "Motion Photo (Android)" as in a new library, and on the back faces of the
// built-in donuts before "One ZIP" where they have room and the user hasn't put them there already.
+ // "Extract audio" replaces the plain M4A slice on the video donut's back.
if (from < 33)
changed |= AddMediaTools(presets, profiles);
return changed;
@@ -763,7 +764,7 @@ internal static class SettingsMigrations
[
("images", ["compress-image", "remove-metadata"]),
("pdf", ["remove-metadata"]),
- ("video", ["compress-video", "merge-videos"]),
+ ("video", ["compress-video", "merge-videos", "extract-audio"]),
("audio", ["compress-audio", "merge-audio", "remove-metadata"]),
];
@@ -783,6 +784,18 @@ internal static class SettingsMigrations
{
if (profiles.FirstOrDefault(p => p.Id == profileId) is not { BackPresetIds: { } back } profile)
continue;
+ // "Extract audio" writes the same M4A as the plain M4A slice, copying the sound where it can: it takes that
+ // slice's place on the video donut's back, or comes in with the other tools when there is room.
+ if (profileId == "video" && !back.Contains("extract-audio") && !profile.PresetIds.Contains("extract-audio")
+ && presets.Any(p => p.Id == "extract-audio"))
+ {
+ var m4a = back.IndexOf("to-m4a");
+ if (m4a >= 0)
+ {
+ back[m4a] = "extract-audio";
+ changed = true;
+ }
+ }
foreach (var id in ids)
{
if (back.Contains(id) || profile.PresetIds.Contains(id) || back.Count >= ToolbarProfile.MaxSlices
diff --git a/tests/Filee.Core.Tests/MediaToolTests.cs b/tests/Filee.Core.Tests/MediaToolTests.cs
index 6fb8d43f..e48fe033 100644
--- a/tests/Filee.Core.Tests/MediaToolTests.cs
+++ b/tests/Filee.Core.Tests/MediaToolTests.cs
@@ -79,6 +79,9 @@ public class MediaToolTests
var profiles = BuiltInData.CreateProfiles();
foreach (var profile in profiles)
profile.BackPresetIds!.RemoveAll(ToolIds.Contains);
+ // The video donut's back face of schema 32, with the plain M4A slice.
+ profiles.Single(p => p.Id == "video").BackPresetIds = ["mp4-av1", "to-webp", "extract-frames-png", "extract-frames-jpg",
+ "live-photo-iphone", "motion-photo-android", "to-m4a", "to-wav", "to-flac", "zip-all"];
// A back face the user filled up stays as it is.
var pdf = profiles.Single(p => p.Id == "pdf");
while (pdf.BackPresetIds!.Count < ToolbarProfile.MaxSlices)
@@ -90,13 +93,27 @@ public class MediaToolTests
Assert.All(ToolIds, id => Assert.Single(presets, p => p.Id == id));
var audio = profiles.Single(p => p.Id == "audio").BackPresetIds!;
Assert.Equal(["to-alac", "compress-audio", "merge-audio", "remove-metadata", "zip-all"], audio);
+ // "Extract audio" takes the M4A slice's place; the new library's back face is what an upgraded one gets.
var video = profiles.Single(p => p.Id == "video").BackPresetIds!;
- Assert.Equal(["compress-video", "merge-videos", "zip-all"], video.TakeLast(3));
+ Assert.Equal(BuiltInData.CreateProfiles().Single(p => p.Id == "video").BackPresetIds, video);
Assert.Equal(full, pdf.BackPresetIds);
Assert.False(SettingsMigrations.ApplyToLibrary(32, presets, profiles)); // once only
Assert.False(SettingsMigrations.ApplyToLibrary(AppSettings.CurrentSchemaVersion, presets, profiles));
}
+ [Fact]
+ public void Extract_audio_comes_onto_a_video_back_face_without_the_m4a_slice_when_there_is_room()
+ {
+ var presets = BuiltInData.CreatePresets().Where(p => !ToolIds.Contains(p.Id)).ToList();
+ var profiles = BuiltInData.CreateProfiles();
+ var video = profiles.Single(p => p.Id == "video");
+ video.BackPresetIds = ["mp4-av1", "to-wav", "zip-all"];
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(32, presets, profiles));
+
+ Assert.Equal(["mp4-av1", "to-wav", "compress-video", "merge-videos", "extract-audio", "zip-all"], video.BackPresetIds);
+ }
+
[Fact]
public async Task Merge_videos_joins_the_clips_in_order_into_one_file_named_after_the_first()
{
diff --git a/tests/Filee.Engines.Tests/MediaToolRealTests.cs b/tests/Filee.Engines.Tests/MediaToolRealTests.cs
index 44f0c195..d8c3d7ef 100644
--- a/tests/Filee.Engines.Tests/MediaToolRealTests.cs
+++ b/tests/Filee.Engines.Tests/MediaToolRealTests.cs
@@ -244,7 +244,7 @@ public class MediaToolRealTests(EngineFixture fx) : IClassFixture<EngineFixture>
var folder = fx.NewFolder();
var chapters = Path.Combine(folder, "chapters.txt");
await File.WriteAllTextAsync(chapters, ";FFMETADATA1\ntitle=Secret trip\nartist=Jane Doe\n" +
- "[CHAPTER]\nTIMEBASE=1/1000\nSTART=0\nEND=1000\ntitle=Arrival\n");
+ "[CHAPTER]\nTIMEBASE=1/1000\nSTART=0\nEND=1000\ntitle=Arrival\n", TestContext.Current.CancellationToken);
var clip = Path.Combine(folder, "trip.mp4");
await FfmpegAsync(
[
@@ -267,7 +267,7 @@ public class MediaToolRealTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.False(after.Tags.ContainsKey(tag), tag);
Assert.DoesNotContain(after.Streams, s => s.Tags.Values.Any(v => v.Contains("Jane", StringComparison.Ordinal)));
Assert.Equal(0, after.Chapters);
- var bytes = Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output));
+ var bytes = Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output, TestContext.Current.CancellationToken));
Assert.DoesNotContain("Secret trip", bytes);
Assert.DoesNotContain("+37.5665", bytes);
Assert.Equal(await StreamHashAsync(clip, "v"), await StreamHashAsync(output, "v"));
@@ -289,7 +289,7 @@ public class MediaToolRealTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.Equal("mp3", after.Audio!.Codec);
Assert.False(after.Tags.ContainsKey("title"));
Assert.False(after.Tags.ContainsKey("artist"));
- Assert.DoesNotContain("Jane Doe", Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output)));
+ Assert.DoesNotContain("Jane Doe", Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output, TestContext.Current.CancellationToken)));
Assert.Equal(await StreamHashAsync(song, "a"), await StreamHashAsync(output, "a"));
}
@@ -319,7 +319,7 @@ public class MediaToolRealTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.True(string.IsNullOrEmpty(clean.Comment));
Assert.Equal((400u, 300u), (clean.Width, clean.Height));
Assert.InRange(clean.Quality, 78u, 82u); // saved at the photo's own quality, not above it
- var bytes = Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output));
+ var bytes = Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output, TestContext.Current.CancellationToken));
Assert.DoesNotContain("Filee Camera", bytes);
Assert.DoesNotContain("Jane", bytes);
}
@@ -348,7 +348,7 @@ public class MediaToolRealTests(EngineFixture fx) : IClassFixture<EngineFixture>
Assert.True(string.IsNullOrEmpty(clean.Info.Author));
Assert.True(string.IsNullOrEmpty(clean.Info.Title));
}
- var bytes = Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output));
+ var bytes = Encoding.Latin1.GetString(await File.ReadAllBytesAsync(output, TestContext.Current.CancellationToken));
Assert.DoesNotContain("Jane Doe", bytes);
Assert.DoesNotContain("Secret contract", bytes);
Assert.DoesNotContain("confidential", bytes);