Console.Write("Input the path of the file you want to edit: ");
string path = Console.ReadLine() ?? throw new Exception();
path = path.Substring(1, path.Length - 2);
Console.WriteLine("Path: {0}", path);
Console.WriteLine("Current metadata: ");
Console.WriteLine(new string('-', 30));
GetMetadata(path);
Console.WriteLine(new string('-', 30));
ChangeMetadata(path);
Console.WriteLine("New metadata: ");
Console.WriteLine(new string('-', 30));
GetMetadata(path);
Console.WriteLine(new string('-', 30));
static void GetMetadata(string path)
{
var tFile = TagLib.File.Create(path);
string title, artist, album, genre;
uint trackNumber, year;
title = tFile.Tag.Title;
artist = tFile.Tag.FirstPerformer;
album = tFile.Tag.Album;
trackNumber = tFile.Tag.Track;
genre = tFile.Tag.FirstGenre;
year = tFile.Tag.Year;
foreach (var item in new string[] { title, artist, album, genre, trackNumber.ToString(), year.ToString() })
{
Console.WriteLine(string.IsNullOrEmpty(item) ? "none" : item);
}
}
// Change Artist, Album, Track no., Genre, Title, Year
static void ChangeMetadata(string path)
{
var tFile = TagLib.File.Create(path);
string[] uintMessages = { "Insert track no.: ", "Insert year: " };
Console.Write("Insert song title: ");
tFile.Tag.Title = Console.ReadLine();
Console.Write("Insert artist name: ");
tFile.Tag.Performers = new string[1];
tFile.Tag.Performers[0] = Console.ReadLine();
Console.Write("Insert album name: ");
tFile.Tag.Album = Console.ReadLine();
Console.Write("Insert genre: ");
tFile.Tag.Genres = new string[1];
tFile.Tag.Genres[0] = Console.ReadLine();
tFile.Tag.Track = ReadUInt(uintMessages[0]);
tFile.Tag.Year = ReadUInt(uintMessages[1]);
tFile.Save();
}
static uint ReadUInt(string message)
{
uint val;
do
Console.Write(message);
while (!uint.TryParse(Console.ReadLine(), out val));
return val;
}