public void DevTests() { using (var mp3 = new Mp3File(@"E:\Temp\Audio\BasicTagsWithImage.mp3", Mp3Permissions.ReadWrite)) { mp3.DeleteAllTags(); var tag = new Id3Tag(); var frontCover = new PictureFrame { Description = "The Front Cover", MimeType = "image/jpg", PictureType = PictureType.FrontCover }; frontCover.LoadImage(@"E:\Temp\Audio\FrontCover.jpg"); tag.Pictures.Add(frontCover); var fileIcon = new PictureFrame { Description = "The File Icon", MimeType = "image/png", PictureType = PictureType.Other }; fileIcon.LoadImage(@"E:\Temp\Audio\MSN.png"); tag.Pictures.Add(fileIcon); mp3.WriteTag(tag); foreach (Id3Frame frame in tag) { Console.WriteLine(frame); } } }
public void ReproduceTest() { using (var mp3 = new Mp3File(@"E:\Temp\Audio\BasicTagsWithImage.mp3", Mp3Permissions.ReadWrite)) { mp3.DeleteAllTags(); var tag = new Id3Tag(); var pic = new PictureFrame { Description = "The Front Cover", EncodingType = Id3TextEncoding.Iso8859_1 }; pic.LoadImage(@"E:\Temp\Audio\FrontCover.jpg"); tag.Pictures.Add(pic); mp3.WriteTag(tag, 2, 3); } using (var mp3 = new Mp3File(@"E:\Temp\Audio\BasicTagsWithImage.mp3")) { Id3Tag tag = mp3.GetTag(2, 3); PictureFrame pic = tag.OfType <PictureFrame>().First(); pic.SaveImage(@"E:\Temp\FrontCoverSaved.jpg"); } }
static void Main(string[] args) { var root = args[0]; var newRoot = args[1]; if (!Directory.Exists(root) || new DirectoryInfo(root) == new DirectoryInfo(newRoot)) { Environment.Exit(1); } var warnings = 0; CheckCreateDirectory(newRoot); var logPath = Path.Combine(newRoot, "log.txt"); using (var log = new StreamWriter(new FileInfo(logPath).Open(FileMode.Create)) { AutoFlush = true }) { try { var files = Directory.GetFiles(root, "*.mp3", SearchOption.AllDirectories); foreach (var file in files) { using (var mp3 = new Mp3File(file)) { var end = mp3.GetTag(Id3TagFamily.FileEndTag); var tag = mp3.GetTag(Id3TagFamily.FileStartTag); if (tag != null) { tag.MergeWith(end); } else { tag = end; } //log.WriteLine("{0,-3} | {1,-50} | {2,-50} | {3,-50}", start.Track.Value, start.Band.Value, start.Album.Value, start.Title.Value); var bandPath = Path.Combine(newRoot, FixDirectoryPath(GetArtist(tag, log, file))); CheckCreateDirectory(bandPath); var albumPath = Path.Combine(bandPath, FixDirectoryPath(GetAlbum(tag, log, file))); CheckCreateDirectory(albumPath); var newFileName = FixFilePath(string.Format("{0} {1}.mp3", FixTrack(tag.Track), GetTitle(tag, log, file))).Trim(); var titlePath = Path.Combine(albumPath, newFileName); if (!File.Exists(titlePath) || new FileInfo(file).Length == new FileInfo(titlePath).Length) { File.Copy(file, titlePath, true); using (var newMp3 = new Mp3File(titlePath, Mp3Permissions.ReadWrite)) { Thread.Sleep(TimeSpan.FromMilliseconds(1)); newMp3.DeleteAllTags(); newMp3.WriteTag(tag, WriteConflictAction.Replace); } //log.WriteLine("File '{0}' copied to '{1}'", file, albumPath); } else { log.WriteLine("*** WARNING: File '{0}' already exists with different length", titlePath); warnings++; } } Console.Write('.'); } log.WriteLine(); log.WriteLine("Ready with {0} warning(s)", warnings); log.WriteLine(); var newFiles = Directory.GetFiles(newRoot, "*.mp3", SearchOption.AllDirectories); log.WriteLine("Started with {0} MP3 files, ended up with {1}.", files.Length, newFiles.Length); } catch (Exception exception) { log.WriteLine(); log.WriteLine("*** ERROR: {0}", exception.Message); log.WriteLine(exception.StackTrace); } Process.Start(logPath); } }