Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/AudioTagger.Console/Operations/TagStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void Start(
const int mostCommonYearCount = 15;

var mostCommonYears = mediaFiles
// .Where(f => f.Year != 0)
.GroupBy(f => f.Year)
.ToDictionary(f => f.Key, f => f.Count())
.OrderByDescending(f => f.Value)
Expand Down Expand Up @@ -196,13 +195,9 @@ private static void PrintToTable(
{
Border = TableBorder.None
};

table.AddColumns(columnNames.Select(n => $"[gray]{n}[/]").ToArray());
// table.Columns[0].Width = rows.Max(r => r[0].Length + 3);
// table.Columns[1].Width = rows.Max(r => Math.Max(r[1].Length + 3, 6));
// if (columnNames.Count > 2)
// {
// table.Columns[2].Width = rows.Max(r => Math.Max(r[1].Length + 3, 6));
// }

if (justifications != null)
{
for (int i = 0; i < justifications.Count; i++)
Expand Down
16 changes: 2 additions & 14 deletions src/AudioTagger.Console/Operations/TagUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static bool UpdateTags(
: [];

UpdatableFields updateableFields = new(matchedTags, artistsWithGenres);
Dictionary<string, string> proposedUpdates = updateableFields.GetUpdateKeyValuePairs(mediaFile);
var proposedUpdates = updateableFields.GetUpdateKeyValuePairs(mediaFile);

if (proposedUpdates.None())
{
Expand All @@ -114,19 +114,8 @@ private static bool UpdateTags(
return shouldCancel;
}

// Print the filename
//printer.PrintDivider(mediaFile.FileNameOnly, ConsoleColor.Cyan);

// Print the current tag data.
// printer.Print(OutputLine.GetTagPrintedLines(mediaFile), 1, 0);

printer.PrintTagDataToTable(mediaFile, proposedUpdates, false);

// Show the proposed updates and ask the user to confirm.
// printer.Print("Apply these updates?", 0, 0, string.Empty, ConsoleColor.Yellow);
// foreach (var update in proposedUpdates)
// printer.Print(update.Line);

if (doConfirm)
{
const string no = "No";
Expand Down Expand Up @@ -169,8 +158,7 @@ private static bool UpdateTags(
return shouldCancel;
}

//printer.Print("Updates saved", ResultType.Success, 0, 1);
AnsiConsole.MarkupLine("[green]Updates saved[/]" + Environment.NewLine);
printer.Print("Updates saved", ResultType.Success, 0, 1);
return shouldCancel;
}

Expand Down
2 changes: 0 additions & 2 deletions src/AudioTagger.Console/Operations/TagUpdaterGenreOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ private static void UpdateGenreTag(MediaFile mediaFile,
printer.Print($"No {updateType} updates needed for \"{mediaFile.FileNameOnly}\".", fgColor: ConsoleColor.DarkGray);
}

// printer.PrintTagDataToTable(mediaFile, proposedUpdates, false);

// Make the tag updates
try
{
Expand Down
4 changes: 1 addition & 3 deletions src/AudioTagger.Console/Operations/TagUpdaterYearOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void Start(IReadOnlyCollection<MediaFile> mediaFiles,
catch (Exception ex)
{
printer.Error($"Error updating {mediaFile.FileNameOnly}: {ex.Message}");
//printer.PrintException(ex);
errorFiles.Add(mediaFile.FileNameOnly);
}
}
Expand Down Expand Up @@ -105,8 +104,7 @@ private static bool UpdateTags(MediaFile mediaFile, IPrinter printer, ref bool d
return shouldCancel;
}

//printer.Print("Updates saved", ResultType.Success, 0, 1);
AnsiConsole.MarkupLine("[green]Updates saved[/]" + Environment.NewLine);
printer.Print("Updates saved", ResultType.Success, 0, 1);
return shouldCancel;
}

Expand Down
5 changes: 1 addition & 4 deletions src/AudioTagger.Library/Genres/GenreService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ public static Result<Dictionary<string, string>> Read(string? genreFileName)
}

Dictionary<string, string> artistsWithGenres = [];

try
{
using TextFieldParser csvParser = new(genreFileName);
// csvParser.CommentTokens = ["#"];
csvParser.SetDelimiters(Delimiters);
csvParser.HasFieldsEnclosedInQuotes = false;
// csvParser.ReadLine(); // Skip header row

while (!csvParser.EndOfData)
{
Expand All @@ -64,6 +63,4 @@ public static Result<Dictionary<string, string>> Read(string? genreFileName)
return Result.Fail(ex.Message);
}
}

private static string EscapeQuotationMarks(string text) => text.Replace("\"", "\\\"");
}
87 changes: 0 additions & 87 deletions src/AudioTagger.Library/OutputLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ public sealed class OutputLine
{
public List<LineSubString> Line { get; } = [];

private OutputLine() { }

public OutputLine(LineSubString lineParts)
{
Line = [lineParts];
}

public OutputLine(params LineSubString[] lineParts)
{
Line = lineParts.ToList();
Expand All @@ -23,86 +16,6 @@ public OutputLine(string text, ConsoleColor? fgColor = null, ConsoleColor? bgCol
Line.Add(new LineSubString(text, fgColor, bgColor));
}

public void Add(LineSubString lineParts)
{
Line.Add(lineParts);
}

public void Add(string text, ConsoleColor? fgColor = null, ConsoleColor? bgColor = null)
{
Line.Add(new LineSubString(text, fgColor, bgColor));
}

public static OutputLine TagDataWithHeader(string tagName,
IReadOnlyList<LineSubString> tagData,
string prependLine = "")
{
const int spacesToPrepend = 4;
int spacesToAppend = 13 - tagName.Length; // TODO: Calculate this instead

var lineOutput = new OutputLine();

lineOutput.Add(prependLine);
lineOutput.Add(new string(' ', spacesToPrepend));
lineOutput.Add(tagName);
lineOutput.Add(new string(' ', spacesToAppend));

foreach (LineSubString part in tagData)
lineOutput.Add(part);

return lineOutput;
}

public static OutputLine TagDataWithHeader(string tagName, string tagData,
string prependLine = "")
{
return TagDataWithHeader(
tagName,
new List<LineSubString> { new(tagData) },
prependLine);
}

public static IList<OutputLine> GetTagPrintedLines(MediaFile fileData)
{
var lines = new List<OutputLine>
{
TagDataWithHeader("Title", fileData.Title),
TagDataWithHeader("Artist(s)", fileData.Artists.Join()),
TagDataWithHeader("Album", fileData.Album),
TagDataWithHeader("Year", fileData.Year.ToString()),
TagDataWithHeader("Duration", fileData.Duration.ToString("m\\:ss"))
};

int genreCount = fileData.Genres.Length;
lines.Add(TagDataWithHeader("Genre(s)", string.Join(", ", fileData.Genres) +
(genreCount > 1 ? $" ({genreCount})" : string.Empty)));

string bitrate = fileData.BitRate.ToString();
string sampleRate = fileData.SampleRate.ToString("#,##0");

// Create formatted quality line
const string genreSeparator = " ";
lines.Add(
TagDataWithHeader(
"Quality",
new List<LineSubString>
{
new(bitrate),
new(" kbps" + genreSeparator, ConsoleColor.DarkGray),
new(sampleRate),
new(" kHz" + genreSeparator, ConsoleColor.DarkGray),
new(fileData.ReplayGainSummary())
}));

if (fileData.Composers.Length > 0)
lines.Add(TagDataWithHeader("Composers", fileData.Composers.Join()));

if (fileData.Comments.HasText())
lines.Add(TagDataWithHeader("Comment", fileData.Comments));

return lines;
}

public static Dictionary<string, string> GetTagKeyValuePairs(
MediaFile fileData,
bool includeComments)
Expand Down
Loading
Loading