Skip to content

Commit 9fb97d9

Browse files
committed
fixes for #72, #70, #51 and #49
1 parent 8d7689f commit 9fb97d9

File tree

11 files changed

+69
-47
lines changed

11 files changed

+69
-47
lines changed

cli-tester/cli-tester.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0"/>
13-
<PackageReference Include="Spectre.Console" Version="0.44.0"/>
12+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
13+
<PackageReference Include="Spectre.Console" Version="0.49.1" />
1414
</ItemGroup>
1515

1616
</Project>

tone.Tests/tone.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1414
<PackageReference Include="Moq.AutoMock" Version="3.5.0" />
1515
<PackageReference Include="Sandreas.Files" Version="1.1.2" />
1616
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />

tone/Metadata/Formats/ChptFmtNativeMetadataFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ChptFmtNativeMetadataFormat : IMetadataFormat
2424

2525
public async Task<Result<IMetadata, string>> ReadAsync(Stream input)
2626
{
27-
var track = new MetadataTrack();
27+
var track = new MetadataTrackHolder();
2828

2929
using var sr = new StreamReader(input);
3030
var lines = ReadLines(sr).ToArray();

tone/Metadata/Formats/FfmetadataFormat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public class FfmetadataFormat : IMetadataFormat
224224
};
225225
public async Task<Result<IMetadata, string>> ReadAsync(Stream input)
226226
{
227-
var metadata = new MetadataTrack();
227+
var metadata = new MetadataTrackHolder();
228228
using var sr = new StreamReader(input);
229229

230230
if (sr.Peek() < 0)
@@ -362,7 +362,7 @@ private static bool TryParseTimeBaseInMilliseconds(string value, out decimal tim
362362
return false;
363363
}
364364

365-
private Dictionary<string, string> ReadSectionProperties(TextReader sr, SectionType currentSectionType,
365+
private Dictionary<string, string> ReadSectionProperties(TextReader sr, SectionType _,
366366
out SectionType nextSectionType)
367367
{
368368
var properties = new Dictionary<string, string>();

tone/Metadata/Taggers/AbstractFilesystemTagger.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task<Status<string>> UpdateAsync(IMetadata metadata, IMetadata? ori
3434
return Ok();
3535
}
3636

37-
var audioFile = _fs?.FileInfo.FromFileName(metadata.Path);
37+
var audioFile = metadata.Path == null ? null : _fs.FileInfo.New(metadata.Path);
3838
if (audioFile == null)
3939
{
4040
return Error($"Could not create fileInfo for file {metadata.Path}");
@@ -46,26 +46,23 @@ public async Task<Status<string>> UpdateAsync(IMetadata metadata, IMetadata? ori
4646
if (_forcedImportFilename == "")
4747
{
4848
preferredFileName = BuildPreferredFileName(audioFile);
49-
metadataFiles = _fs?.Directory.EnumerateFiles(audioFile.DirectoryName)
50-
.Select(f => _fs.FileInfo.FromFileName(f))
51-
.Where(FilterCallback).ToArray() ?? Empty<IFileInfo>();
49+
metadataFiles = audioFile.DirectoryName == null ? Empty<IFileInfo>() : _fs.Directory.EnumerateFiles(audioFile.DirectoryName)
50+
.Select(f => _fs.FileInfo.New(f))
51+
.Where(FilterCallback).ToArray();
5252
}
5353
else
5454
{
5555
preferredFileName = null;
56-
var forcedFile = _fs?.FileInfo.FromFileName(_forcedImportFilename);
56+
var forcedFile = _fs.FileInfo.New(_forcedImportFilename);
5757
metadataFiles = Empty<IFileInfo>();
58-
59-
if (forcedFile != null)
58+
59+
if (!forcedFile.Exists)
60+
{
61+
forcedFile = _fs.FileInfo.New(_fs.Path.Combine(audioFile.DirectoryName ?? "", _forcedImportFilename));
62+
}
63+
if (forcedFile is { Exists: true })
6064
{
61-
if (!forcedFile.Exists)
62-
{
63-
forcedFile = _fs?.FileInfo.FromFileName(_fs.Path.Combine(audioFile.DirectoryName ?? "", _forcedImportFilename));
64-
}
65-
if (forcedFile is { Exists: true })
66-
{
67-
metadataFiles = new[] { forcedFile };
68-
}
65+
metadataFiles = new[] { forcedFile };
6966
}
7067
}
7168

@@ -75,11 +72,7 @@ public async Task<Status<string>> UpdateAsync(IMetadata metadata, IMetadata? ori
7572
preferredFile = metadataFiles.FirstOrDefault(f => f.Name == preferredFileName) ?? preferredFile;
7673
}
7774

78-
await using var stream = _fs?.File.OpenRead(preferredFile.FullName);
79-
if (stream == null)
80-
{
81-
return Error($"Could not open file ${preferredFile.FullName}");
82-
}
75+
await using var stream = _fs.File.OpenRead(preferredFile.FullName);
8376

8477
var parsedMeta = await _parser.ReadAsync(stream);
8578
return !parsedMeta ? Error(parsedMeta.Error) : TransferPropertiesCallback(parsedMeta.Value, metadata);

tone/Metadata/Taggers/CoverTagger.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public CoverTagger(IFileSystem fs, ICoverTaggerSettings settings) {
3737
}
3838
public async Task<Status<string>> UpdateAsync(IMetadata metadata, IMetadata? originalMetadata = null)
3939
{
40-
if(_autoload && _covers.Count == 0 && metadata.BasePath!=null)
40+
// covers need a local copy to prevent re-use of covers when batch taggingy
41+
var covers = _covers.ToList();
42+
if(_autoload && covers.Count == 0 && metadata.BasePath!=null)
4143
{
4244
var dir = _fs.GetContainingDirectory(metadata.BasePath);
4345
if(dir.Exists){
@@ -46,15 +48,15 @@ public async Task<Status<string>> UpdateAsync(IMetadata metadata, IMetadata? ori
4648
// 1 - MyTitle.cover.jpg
4749
// 1 - MyTitle.cover.png
4850
// 1 - MyTitle.cover[0].jpg
49-
_covers.AddRange( _fs.Directory
51+
covers.AddRange( _fs.Directory
5052
.GetFiles(dir.FullName)
5153
.Select(p => _fs.FileInfo.New(p))
5254
.Where(HasCoverExtension));
5355
}
5456
}
5557

5658

57-
var potentialCovers = _covers.Where(HasCoverExtension).ToImmutableArray();
59+
var potentialCovers = covers.Where(HasCoverExtension).ToImmutableArray();
5860

5961
var validGroups = potentialCovers.ToLookup(IsValidCover);
6062
var validCovers = validGroups[true].ToImmutableArray();

tone/Metadata/Taggers/FfmetadataTagger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public FfmetadataTagger(IFileSystem? fileSystem, FfmetadataFormat parser, string
1717

1818
protected override string? BuildPreferredFileName(IFileInfo audioFile) => ConcatPreferredFileName(audioFile, DefaultFileSuffix);
1919

20-
protected override bool FilterCallback(IFileInfo f) => f.Name.EndsWith(DefaultFileSuffix);
20+
protected override bool FilterCallback(IFileInfo f) => f.Name.EndsWith(DefaultFileSuffix) || f.Name.EndsWith(".ffmetadata");
2121

2222
protected override Status<string> TransferPropertiesCallback(IMetadata parsedMetaValue, IMetadata metadata)
2323
{

tone/Metadata/Taggers/IdTaggers/Audible/AudibleIdTagger.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Net.Http;
66
using System.Text.RegularExpressions;
77
using System.Threading.Tasks;
8-
using ATL;
98
using HtmlAgilityPack;
109
using Newtonsoft.Json;
1110
using OperationResult;
@@ -98,7 +97,7 @@ public async Task<Status<string>> UpdateAsync(IMetadata metadata, IMetadata? ori
9897

9998
private async Task<IMetadata> TransferMetaAsync(Product? product, ChapterInfo? chapters)
10099
{
101-
IMetadata newMeta = new MetadataTrack();
100+
IMetadata newMeta = new MetadataTrackHolder();
102101

103102
if (product != null)
104103
{
@@ -118,7 +117,7 @@ private async Task<IMetadata> TransferMetaAsync(Product? product, ChapterInfo? c
118117
// newMeta.EncodedBy = "";
119118
// newMeta.EncoderSettings = "";
120119
// newMeta.EncodingTool = "";
121-
var genre = product.CategoryLadders?.FirstOrDefault()?.Ladder.FirstOrDefault()?.Name;
120+
var genre = product.CategoryLadders.FirstOrDefault()?.Ladder.FirstOrDefault()?.Name;
122121
if (genre == null)
123122
{
124123
newMeta.Genre = genre;
@@ -168,7 +167,7 @@ private async Task<IMetadata> TransferMetaAsync(Product? product, ChapterInfo? c
168167

169168
TransferChapters(newMeta, chapters);
170169

171-
return newMeta;
170+
return await Task.FromResult(newMeta);
172171
}
173172

174173
private void TransferChapters(IMetadata newMeta, ChapterInfo? chapters)
@@ -225,6 +224,7 @@ private void TransferChapters(IMetadata newMeta, ChapterInfo? chapters)
225224
return chapterInfos;
226225
}
227226

227+
/*
228228
private async Task<PictureInfo?> LoadCoverAsync(string? imageUrl)
229229
{
230230
try
@@ -245,6 +245,7 @@ private void TransferChapters(IMetadata newMeta, ChapterInfo? chapters)
245245
}
246246
return null;
247247
}
248+
*/
248249

249250
private string StripTags(string input)
250251
{

tone/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.IO.Abstractions;
45
using System.Linq;
56
using System.Net.Http;
@@ -47,7 +48,6 @@
4748
// Settings.MP3_parseExactDuration = true; // more exact duration, takes longer
4849

4950
var settingsProvider = new CustomCommandSettingsProvider();
50-
5151
var services = new ServiceCollection();
5252
services.AddSingleton<ILogger>(_ =>
5353
{
@@ -231,7 +231,7 @@
231231
config.UseStrictParsing();
232232
config.CaseSensitivity(CaseSensitivity.None);
233233
config.SetApplicationName("tone");
234-
config.SetApplicationVersion("0.1.9");
234+
config.SetApplicationVersion("0.2.0");
235235
config.ValidateExamples();
236236
config.AddCommand<DumpCommand>("dump")
237237
.WithDescription("dump metadata for files and directories (directories are traversed recursively)")
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Release Notes
2+
3+
## Fixed
4+
- #72 - `--auto-import` fails under specific circumstances
5+
- #70 - improve ID3v2 support for narrator tag
6+
- #51 - incorrect next track ID after import chapters
7+
- #49 - auto importing covers uses the same cover for every audio file
8+
9+
## Changed
10+
- Upgraded `atldotnet` library
11+
- Upgraded all dependencies to the latest version
12+
13+
14+
## Setup instructions
15+
16+
`tone` is released as single monolithic binary, so you don't need a setup file or any dependencies (not even a `.NET` runtime). Download the `tone`
17+
release for your platform, extract it and run it via command line. If you need help choosing your download, here are some hints:
18+
19+
- For Windows, only the x64 platform is available... choose `-win-x64.zip`
20+
- For `musl` (an alternative C library) choose your arch prefixed by `musl` (usually this is used in alpine `docker` images and other lightweight distributions)
21+
- For standard Linux (like *Fedora*, *Ubuntu*, etc.), it is recommended choose your arch without `musl` prefix
22+
- For *macOS* you might need to run `xattr -rd com.apple.quarantine tone` after extracting to remove `quarantine` flag
23+
24+

0 commit comments

Comments
 (0)