public static void WriteMP3Tags(string filename, CD cd, int track) { // Im Moment nur MP3 string ext = Path.GetExtension(filename).ToLower(); if (ext != ".mp3" && ext != ".flac" && ext != ".wma" && ext != ".ogg") { return; } using (TagLib.File tagFile = TagLib.File.Create(filename)) { int id3Version = Settings.Current.UseID3Version; int year = cd.Tracks[track].YearRecorded != 0 ? cd.Tracks[track].YearRecorded : cd.YearRecorded; string category = !String.IsNullOrEmpty(cd.Tracks[track].Category) ? cd.Tracks[track].Category : cd.Category; string language = !String.IsNullOrEmpty(cd.Tracks[track].Language) ? cd.Tracks[track].Language : cd.Language; tagFile.Tag.Performers = new string[] { cd.Tracks[track].Artist }; tagFile.Tag.AlbumArtists = new string[] { cd.Artist }; tagFile.Tag.Title = cd.Tracks[track].Title; tagFile.Tag.Comment = cd.Tracks[track].Comment; tagFile.Tag.Track = (uint)cd.Tracks[track].TrackNumber; tagFile.Tag.Album = cd.Title; tagFile.Tag.Year = (uint)year; if (category != null) { tagFile.Tag.Genres = new string[] { category } } ; tagFile.Tag.Composers = new string[] { cd.Tracks[track].Composer }; //TODO!!!!!!!!!!!!!id3Info.ID3v2Info.SetTextFrame("TLAN", language); if (cd.CDSetNumber > 0) { tagFile.Tag.Disc = (uint)cd.CDSetNumber; } //TODO!!!!!!!!id3Info.ID3v2Info.SetTextFrame("PCNT", cd.Tracks[track].PlayCount.ToString()); // Rating ist eine Liste von Einträgen. Wir suchen hier nach dem Eintrag "*****@*****.**". if (cd.Tracks[track].Rating > 0 && ext == ".mp3") { TagLib.Id3v2.PopularimeterFrame popFrame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tagFile.GetTag(TagLib.TagTypes.Id3v2), "*****@*****.**", true); popFrame.User = "******"; popFrame.Rating = (byte)cd.Tracks[track].Rating; popFrame.PlayCount = (ulong)cd.Tracks[track].PlayCount; } tagFile.Tag.BeatsPerMinute = (uint)cd.Tracks[track].Bpm; //TODO!!!!!!!!!!!!!tagFile.Tag.id3Info.ID3v2Info.SetTextFrame("TLEN", cd.Tracks[track].Length > 0 ? cd.Tracks[track].Length.ToString() : ""); try { if (!string.IsNullOrEmpty(cd.CDCoverFrontFilename)) { byte[] filefrontcover = File.ReadAllBytes(Misc.FindCover(cd.CDCoverFrontFilename)); string mimetype; mimetype = GetMIMEType(Path.GetExtension(cd.CDCoverFrontFilename)); MemoryStream memstream = new MemoryStream(filefrontcover); TagLib.Picture pict = new TagLib.Picture(); pict.MimeType = mimetype; pict.Data = memstream.ToArray(); pict.Type = TagLib.PictureType.FrontCover; tagFile.Tag.Pictures = new TagLib.IPicture[] { pict }; } } catch { // Pech gehabt - kein Cover } tagFile.Tag.Lyrics = cd.Tracks[track].Lyrics; try { tagFile.Save(); } catch (Exception e) { System.Windows.Application.Current.Dispatcher.Invoke( new Action(delegate { WPFMessageBox msgBox = new WPFMessageBox(); msgBox.HeaderText = StringTable.WriteID3TagsAccessDeniedTitle; msgBox.Text = string.Format(StringTable.WriteID3TagsAccessDenied, filename); msgBox.Image = "/Big3.Hitbase.SharedResources;component/Images/Info.png"; msgBox.Owner = System.Windows.Application.Current.MainWindow; msgBox.WpfMessageBoxButtons = WpfMessageBoxButtons.OK; msgBox.ZoomImage = false; msgBox.Width = 600; msgBox.Height = 400; msgBox.ShowInTaskbar = false; msgBox.DontShowAgainText = StringTable.DontDisplayAgain; msgBox.SaveAnswer = true; msgBox.SaveAnswerInRegistryKey = "ID3RenameAccessDenied"; msgBox.ShowDialogEventually(); })); } } }