Skip to content
6 changes: 3 additions & 3 deletions src/AudioTagger.Console/AudioTagger.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TagLibSharp" Version="2.3.0"/>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.11" />
<PackageReference Include="System.Drawing.Common" Version="10.0.11" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="10.0.11" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.13" />
<PackageReference Include="System.Drawing.Common" Version="10.0.13" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="10.0.13" />
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="6.0.5.128"/>
<PackageReference Include="Spectre.Console" Version="0.57.2" />
<PackageReference Include="FluentResults" Version="4.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions src/AudioTagger.Console/Operations/TagUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private static bool UpdateTags(
}

IEnumerable<Group> matchedTags = match.Groups
.OfType<Group>()
.Where(g => g.Success);
.OfType<Group>()
.Where(g => g.Success);

if (!matchedTags.Any())
{
Expand Down
6 changes: 3 additions & 3 deletions src/AudioTagger.Library/AudioTagger.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="TagLibSharp" Version="2.3.0"/>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.11" />
<PackageReference Include="System.Drawing.Common" Version="10.0.11" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="10.0.11" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="10.0.13" />
<PackageReference Include="System.Drawing.Common" Version="10.0.13" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="10.0.13" />
<PackageReference Include="runtime.osx.10.10-x64.CoreCompat.System.Drawing" Version="6.0.5.128"/>
<PackageReference Include="FluentResults" Version="4.0.0" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/AudioTagger.Library/OutputLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public static Dictionary<string, string> GetTagKeyValuePairs(
{
var lines = new Dictionary<string, string>
{
{ "Title", fileData.Title },
{ "Album Artist(s)", fileData.AlbumArtists.Join() },
{ "Artist(s)", fileData.Artists.Join() },
{ "Title", fileData.Title },
{ "Album", fileData.Album },
{ "Year", fileData.Year.ToString() },
{ "Duration", fileData.Duration.ToString("m\\:ss") }
Expand Down
137 changes: 72 additions & 65 deletions src/AudioTagger.Library/UpdatableFields.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using System.Globalization;
using static System.StringSplitOptions;
using AudioTagger.Library.MediaFiles;

namespace AudioTagger.Library;
Expand All @@ -26,71 +27,75 @@ public UpdatableFields(
{
ArgumentNullException.ThrowIfNull(matchedGroups);

const StringSplitOptions splitOptions = RemoveEmptyEntries | TrimEntries;

foreach (Group element in matchedGroups)
{
if (element.Name == "title")
switch (element.Name)
{
// TODO: Relocate the replacements.
Title = element.Value.Trim().Normalize()
case "albumArtists":
AlbumArtists = element.Value
.Trim().Normalize()
.Replace("___", " ")
.Replace("__", " ")
.Split([";"], splitOptions)
.Select(a => a.Normalize())
.ToArray();
Count++;
break;
case "artists":
Artists = element.Value
.Trim().Normalize()
.Replace("___", " ")
.Replace("__", " ");
Count++;
}
else if (element.Name == "albumArtists")
{
AlbumArtists = element.Value
.Replace("___", " ")
.Replace("__", " ")
.Split([";"],
StringSplitOptions.RemoveEmptyEntries |
StringSplitOptions.TrimEntries)
.Select(a => a.Normalize())
.ToArray();
Count++;
}
else if (element.Name == "artists")
{
Artists = element.Value.Replace("___", " ")
.Replace("__", " ")
.Split([";"],
StringSplitOptions.RemoveEmptyEntries |
StringSplitOptions.TrimEntries)
.Select(a => a.Normalize())
.ToArray();
Count++;
}
else if (element.Name == "album")
{
Album = element.Value.Trim().Normalize()
.Replace("___", " ")
.Replace("__", " ");
Count++;
}
else if (element.Name == "genres")
{
Genres = element.Value.Replace("___", " ")
.Replace("__", " ")
.Split([";"],
StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
.Select(g => g.Normalize())
.ToArray();
Count++;
}
else if (element.Name == "year")
{
Year = uint.TryParse(element.Value, out var parsed) ? parsed : 0;
Count++;
}
else if (element.Name == "trackNo")
{
TrackNo = uint.TryParse(element.Value, out var parsed) ? parsed : null;
Count++;
.Replace("__", " ")
.Split([";"], splitOptions)
.Select(a => a.Normalize())
.ToArray();
Count++;
break;
case "album":
Album = element.Value
.Trim().Normalize()
.Replace("___", " ")
.Replace("__", " ");
Count++;
break;
case "title":
// TODO: Relocate the replacements.
Title = element.Value
.Trim().Normalize()
.Replace("___", " ")
.Replace("__", " ");
Count++;
break;
case "genres":
Genres = element.Value
.Trim().Normalize()
.Replace("___", " ")
.Replace("__", " ")
.Split([";"], splitOptions)
.Select(g => g.Normalize())
.ToArray();
Count++;
break;
case "year":
{
Year = uint.TryParse(element.Value, out var parsed) ? parsed : 0;
Count++;
break;
}
case "trackNo":
{
TrackNo = uint.TryParse(element.Value, out var parsed) ? parsed : null;
Count++;
break;
}
}
}

// If no genre was manually passed in, check the settings for a registered one.
if (Genres?.Any() != true &&
Artists?.Any() == true &&
if (Genres?.Any() is not true &&
Artists?.Any() is true &&
artistsWithGenres.Any())
{
if (artistsWithGenres.Any() &&
Expand All @@ -106,19 +111,21 @@ public UpdatableFields(string tagField, dynamic newValue)
ArgumentNullException.ThrowIfNull(tagField);
ArgumentNullException.ThrowIfNull(newValue);

if (tagField.Equals("year", StringComparison.OrdinalIgnoreCase) &&
const StringComparison comparisonType = StringComparison.OrdinalIgnoreCase;

if (tagField.Equals("year", comparisonType) &&
newValue is int newYear)
{
Year = (uint)newYear;
Count++;
}
else if (tagField.Equals("genre", StringComparison.OrdinalIgnoreCase) &&
else if (tagField.Equals("genre", comparisonType) &&
newValue is string newGenre)
{
Genres = [newGenre];
Count++;
}
else if (tagField.Equals("genre", StringComparison.OrdinalIgnoreCase) &&
else if (tagField.Equals("genre", comparisonType) &&
newValue is string[] newGenres)
{
Genres = newGenres;
Expand All @@ -130,11 +137,6 @@ public Dictionary<string, string> GetUpdateKeyValuePairs(MediaFile fileData)
{
var updateOutput = new Dictionary<string, string>();

if (Title != null && Title != fileData.Title)
{
updateOutput.Add("Title", Title);
}

if (AlbumArtists?.All(a => fileData.AlbumArtists.Contains(a)) == false)
{
updateOutput.Add("Album Artists", string.Join("; ", AlbumArtists));
Expand All @@ -150,6 +152,11 @@ public Dictionary<string, string> GetUpdateKeyValuePairs(MediaFile fileData)
updateOutput.Add("Album", Album);
}

if (Title != null && Title != fileData.Title)
{
updateOutput.Add("Title", Title);
}

if (Year != null && Year != fileData.Year)
{
updateOutput.Add("Year", Year.Value.ToString(CultureInfo.InvariantCulture));
Expand Down
6 changes: 3 additions & 3 deletions src/AudioTagger.Tests/AudioTagger.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="10.0.1">
<PackageReference Include="coverlet.collector" Version="10.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading