Ejemplo n.º 1
0
        private static void EditFile(string fileName)
        {
            Console.WriteLine(fileName);
            var dados = Path.GetFileNameWithoutExtension(fileName);

            if (dados.IndexOf("-") == -1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("    Above file was ignored, isn't the match pattern Artist - Title.");
                Console.ResetColor();
                return;
            }

            using (var mp3 = new Mp3(fileName, Mp3Permissions.ReadWrite))
            {
                mp3.DeleteAllTags();
                var tag      = new Id3Tag();
                var propinfo = typeof(Id3Tag).GetProperty("Version", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                propinfo.SetValue(tag, Id3Version.V23);
                tag.Artists.Value.Clear();
                tag.Artists.Value.Add(dados.Substring(0, dados.IndexOf("-") - 1).Trim());
                tag.Title.Value = dados.Substring(dados.IndexOf("-") + 1, dados.Length - (dados.IndexOf("-") + 1)).Trim();
                mp3.WriteTag(tag, WriteConflictAction.Replace);
            }
        }