/// <summary> /// Shows how to read APEV2 tags in MP3 format /// Feature is supported in version 17.9.0 or greater of the API /// </summary> public static void ReadApev2Tag() { //ExStart:ReadApev2TagMp3 // initialize Mp3Format. If file is not Mp3 then appropriate exception will throw. using (Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // get APEv2 tag Apev2Metadata apev2 = mp3Format.APEv2; //NOTE: please remember you may use different approaches to getting metadata // second approach apev2 = (Apev2Metadata)MetadataUtility.ExtractSpecificMetadata(Common.MapSourceFilePath(filePath), MetadataType.APEv2); // check if APEv2 tag is presented if (apev2 != null) { // Display tag properties Console.WriteLine("Album: {0}", apev2.Album); Console.WriteLine("Artist: {0}", apev2.Artist); Console.WriteLine("Comment: {0}", apev2.Comment); Console.WriteLine("Genre: {0}", apev2.Genre); Console.WriteLine("Title: {0}", apev2.Title); Console.WriteLine("Track: {0}", apev2.Track); } } //ExEnd:ReadApev2TagMp3 }
/// <summary> /// Read ID3v2 tag in MP3 format /// Supported ID3v2.3 and ID3v2.4, ID3v2.2 is obsolete by ID3.org /// </summary> public static void ReadID3v2Tag() { try { //ExStart:ReadID3v2Tag // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // get ID3 v2 tag Id3v2Tag id3v2 = mp3Format.Id3v2; if (id3v2 != null) { // write ID3v2 version Console.WriteLine("Version: {0}", id3v2.Version); // write known frames' values Console.WriteLine("Album: {0}", id3v2.Album); Console.WriteLine("Comment: {0}", id3v2.Comment); Console.WriteLine("Composers: {0}", id3v2.Composers); // in trial mode only first 5 frames are available TagFrame[] idFrames = id3v2.Frames; foreach (TagFrame tagFrame in idFrames) { Console.WriteLine("Frame: {0}, value: {1}", tagFrame.Name, tagFrame.GetFormattedValue()); } } //ExEnd:ReadID3v2Tag } catch (Exception ex) { Console.WriteLine(ex.Message); } }
// <summary> /// Update ID3v2 Tag Using Stream /// </summary> public static void UpdateID3v2TagUsingStream() { using (Stream stream = File.Open(Common.MapDestinationFilePath(filePath), FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (Mp3Format format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // get id3v2 tag Id3v2Tag id3Tag = format.Id3v2Properties ?? new Id3v2Tag(); // set artist id3Tag.Artist = "A-ha"; // set title id3Tag.Title = "Take on me"; // set band id3Tag.Band = "A-ha"; // set comment id3Tag.Comment = "GroupDocs.Metadata creator"; // set track number id3Tag.TrackNumber = "5"; // set year id3Tag.Year = "1986"; // update ID3v2 tag format.UpdateId3v2(id3Tag); format.Save(stream); } // The stream is still open here } }
/// <summary> /// Update or Remove Image Cover tag from ID3 audio tag /// Feature is supported in version 18.2 or greater of the API /// </summary> public static void UpdateOrRemoveImageCoverID3() { try { // init Mp3Format class using (Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // get id3v2 var metadata = mp3Format.GetId3v2Tag(); if (metadata == null) { return; } // remove image cover metadata.RemoveImageCover(); // update metadata mp3Format.UpdateId3v2(metadata); // and store to other file mp3Format.Save(Common.MapDestinationFilePath(filePath)); } } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Updates ID3v1 tag in MP3 format /// </summary> /// public static void UpdateID3v1Tag() { try { //ExStart:UpdateID3v1Tag // initialize Mp3Format class using (Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath)))) { // create id3v1 tag Id3v1Tag id3Tag = new Id3v1Tag(); // set artist id3Tag.Artist = "A-ha"; // set title id3Tag.Title = "Take on me"; // update ID3v1 tag mp3Format.UpdateId3v1(id3Tag); // and commit changes mp3Format.Save(); } //ExEnd:UpdateID3v1Tag } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Reads Lyrics3 tag in Mp3 format /// </summary> public static void ReadLyrics3Tag() { try { //ExStart:ReadLayrics3TagInMp3 // initialize Mp3Format class using (Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath)))) { // get Lyrics3 v2.00 tag Lyrics3Tag lyrics3Tag = mp3Format.Lyrics3v2; // check if Lyrics3 is presented. It could be absent. if (lyrics3Tag != null) { // Display defined tag values Console.WriteLine("Album: {0}", lyrics3Tag.Album); Console.WriteLine("Artist: {0}", lyrics3Tag.Artist); Console.WriteLine("Track: {0}", lyrics3Tag.Track); // get all fields presented in Lyrics3Tag Lyrics3Field[] allFields = lyrics3Tag.Fields; foreach (Lyrics3Field lyrics3Field in allFields) { Console.WriteLine("Name: {0}, value: {1}", lyrics3Field.Name, lyrics3Field.Value); } } } //ExEnd:ReadLayrics3TagInMp3 } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Reads Id3 metadata directly in MP3 format /// </summary> public static void ReadId3MetadataDirectly() { //ExStart:ReadId3MetadataInMp3Directly // init Mp3Format class Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath)); // read album in ID3 v1 MetadataProperty album = mp3Format[MetadataKey.Id3v1.Album]; Console.WriteLine(album); // read title in ID3 v2 MetadataProperty title = mp3Format[MetadataKey.Id3v2.Title]; Console.WriteLine(title); // create custom ID3v2 key // TCOP is used for 'Copyright' property according to the ID3 specification MetadataKey copyrightKey = new MetadataKey(MetadataType.Id3v2, "TCOP"); // read copyright property MetadataProperty copyright = mp3Format[copyrightKey]; Console.WriteLine(copyright); //ExEnd:ReadId3MetadataInMp3Directly }
public void Test_Mp3_1() { var fn = @"Targets\Singles\01-Phantom.mp3"; using (var fs = new FileStream(fn, FileMode.Open)) { var hdr = new byte[0x2C]; fs.Read(hdr, 0, hdr.Length); Mp3Format.Model mp3Model = Mp3Format.CreateModel(fs, hdr, fn); Mp3Format mp3 = mp3Model.Data; Assert.IsNotNull(mp3); Assert.AreEqual(Severity.Warning, mp3.Issues.MaxSeverity); Assert.AreEqual(2, mp3.Issues.Items.Count); Assert.IsTrue(mp3.HasId3v1Phantom); var repairMessage = mp3Model.RepairPhantomTag(true); Assert.IsNull(repairMessage); mp3Model.CalcHashes(Hashes.Intrinsic, Validations.None); Assert.IsFalse(mp3.IsBadHeader); Assert.IsFalse(mp3.IsBadData); } }
/// <summary> /// Read ID3v2 Tag Using Stream /// </summary> public static void ReadID3v2TagUsingStream() { using (Stream stream = File.Open(Common.MapSourceFilePath(filePath), FileMode.Open, FileAccess.ReadWrite)) { using (Mp3Format format = new Mp3Format(stream)) { // get ID3 v2 tag Id3v2Tag id3v2 = format.Id3v2Properties ?? new Id3v2Tag(); if (id3v2 != null) { // write ID3v2 version Console.WriteLine("Version: {0}", id3v2.Version); // write known frames' values Console.WriteLine("Title: {0}", id3v2.Title); Console.WriteLine("Artist: {0}", id3v2.Artist); Console.WriteLine("Album: {0}", id3v2.Album); Console.WriteLine("Comment: {0}", id3v2.Comment); Console.WriteLine("Composers: {0}", id3v2.Composers); Console.WriteLine("Band: {0}", id3v2.Band); Console.WriteLine("Track Number: {0}", id3v2.TrackNumber); Console.WriteLine("Year: {0}", id3v2.Year); // in trial mode only first 5 frames are available TagFrame[] idFrames = id3v2.Frames; foreach (TagFrame tagFrame in idFrames) { Console.WriteLine("Frame: {0}, value: {1}", tagFrame.Name, tagFrame.GetFormattedValue()); } } } // The stream is still open here } }
/// <summary> /// Read MPEG audio information /// </summary> /// public static void ReadMPEGAudioInfo() { try { //ExStart:ReadMPEGAudioInfo // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // get MPEG audio info MpegAudio audioInfo = mp3Format.AudioDetails; // display MPEG audio version Console.WriteLine("MPEG audio version: {0}", audioInfo.MpegAudioVersion); // display layer version Console.WriteLine("Layer version: {0}", audioInfo.LayerVersion); // display protected bit Console.WriteLine("Is protected: {0}", audioInfo.IsProtected); //ExEnd:ReadMPEGAudioInfo } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Update ID3v1 tag using properties /// Feature is supported in version 18.2 or greater of the API /// </summary> public static void UpdateID3v1TagUsingProperties() { try { // init Mp3Format class using (Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // get id3v1 tag Id3v1Tag id3Tag = mp3Format.Id3v1Properties; // set artist id3Tag.Artist = "A-ha"; // set comment id3Tag.Comment = "By GroupDocs.Metadata"; // set title id3Tag.Title = "Take on me"; // set year id3Tag.Year = "1986"; // and commit changes mp3Format.Save(); } } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Validate ID3 input metadata before saving /// Feature is supported in version 18.2 or greater of the API /// </summary> public static void ValidateID3Metadata() { try { //init Mp3Format class using (Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // set album but with invalid length mp3Format.Id3v1Properties.Album = "this is very looooooooong album name but must be less 30 characters"; try { // and commit changes mp3Format.Save(); } catch (Shared.Exceptions.GroupDocsException e) { //e.Message is "Property 'album': Length could not be grater then 30" Console.WriteLine(e); } } } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Read Image Cover from ID3 audio tag /// Feature is supported in version 18.2 or greater of the API /// </summary> public static void ReadImageCoverID3() { try { // init Mp3Format class using (Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // get id3v2 var metadata = mp3Format.GetId3v2Tag(); // check if ID3v2 is exist if (metadata == null) { return; } // read APIC frames var frames = metadata["APIC"]; if (frames != null && frames.Length == 1) { // get AttachedPictureFrame AttachedPictureFrame picture = (AttachedPictureFrame)frames[0]; // use 'jpeg' as default extension string extension = ".jpeg"; string mimeType = picture.MIMEType; // try resolve extension from MIME if (mimeType != null) { if (mimeType.Contains("jpg")) { extension = ".jpeg"; } else if (mimeType.Contains("bmp")) { extension = ".bmp"; } else if (mimeType.Contains("png")) { extension = ".png"; } } // prepare file name string file = string.Format(Common.MapDestinationFilePath(filePath), extension); // and store it to the file system System.IO.File.WriteAllBytes(file, picture.PictureData); } } } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Update Lyrics3 Tag /// This method is supportd by version 18.10 or greater. /// </summary> public static void UpdateLyrics3Tag() { using (Mp3Format format = new Mp3Format(Common.MapSourceFilePath(filePath))) { format.Lyrics3v2Properties.Album = "test album"; format.Lyrics3v2Properties.Artist = "test artist"; format.Lyrics3v2Properties.AdditionalInfo = "test info"; format.Lyrics3v2Properties.Lyrics = "[00:01] test lyrics"; format.Save(Common.MapDestinationFilePath(filePath)); } }
public static void RemoveAPEV2Tag() { //ExStart:RemoveAPEV2Tag // initialize Mp3Format. If file is not Mp3 then appropriate exception will throw. Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath)); // remove APE v2.0 tag mp3Format.RemoveAPEv2(); // and commit changes mp3Format.Save(); //ExEnd:RemoveAPEV2Tag }
public static void CleanMetadata() { //ExStart:CleanMetadata // initialize Mp3Format. If file is not Mp3 then appropriate exception will throw. Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath)); // removes id3/lyrics/ape tags mp3Format.CleanMetadata(); // and commit changes mp3Format.Save(); //ExEnd:CleanMetadata }
/// <summary> /// Removes ID3v2 tag in MP3 format /// </summary> public static void RemoveID3v2Tag() { //ExStart:RemoveID3v2Tag // init Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // remove ID3v2 tag mp3Format.RemoveId3v2(); // and commit changes mp3Format.Save(); //ExEnd:RemoveID3v2Tag }
public void UnitMp3_BadCRC() { var fName1 = @"Targets\Singles\02-WalkedOn.mp3"; using (Stream fs = new FileStream(fName1, FileMode.Open)) { var hdr = new byte[0x2C]; fs.Read(hdr, 0, hdr.Length); Mp3Format.Model mp3Model = Mp3Format.CreateModel(fs, hdr, fName1); mp3Model.CalcHashes(Hashes.Intrinsic, Validations.None); Assert.IsTrue(mp3Model.Data.IsBadData); Assert.AreEqual(Severity.Error, mp3Model.Data.Issues.MaxSeverity); } }
/// <summary> /// Update Lyrics3 Tag by replacing whole field collection /// This method is supportd by version 18.10 or greater. /// </summary> public static void UpdateLyrics3TagByReplacingWholefieldCollection() { using (Mp3Format format = new Mp3Format(Common.MapSourceFilePath(filePath))) { Lyrics3Field[] fields = new Lyrics3Field[] { new Lyrics3Field("EAL", "test album"), new Lyrics3Field("EAR", "test artist"), new Lyrics3Field("INF", "test info"), new Lyrics3Field("LYR", "[00:01] test lyrics"), }; format.Lyrics3v2Properties.Fields = fields; format.Save(Common.MapDestinationFilePath(filePath)); } }
/// <summary> /// Update Lyrics3 Tag by replacing whole tag /// This method is supportd by version 18.10 or greater. /// </summary> public static void UpdateLyrics3TagByReplacingWholeTag() { using (Mp3Format format = new Mp3Format(Common.MapSourceFilePath(filePath))) { Lyrics3Tag tag = new Lyrics3Tag(); tag.Fields = new Lyrics3Field[] { new Lyrics3Field("EAL", "test album"), new Lyrics3Field("EAR", "test artist"), new Lyrics3Field("INF", "test info"), new Lyrics3Field("LYR", "[00:01] test lyrics"), }; format.UpdateLyrics3v2(tag); format.Save(Common.MapDestinationFilePath(filePath)); } }
/// <summary> /// Read additional properties from ID3v2 tag /// Feature is supported in version 18.2 or greater of the API /// </summary> public static void ReadAdditionalID3v2Properties() { try { // init Mp3Format class using (Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // get ID3 v2 tag Id3v2Tag id3v2 = mp3Format.Id3v2; if (id3v2 != null) { // read sub-title Console.WriteLine("Subtitle: {0}", id3v2.Subtitle); // read musical key Console.WriteLine("Musical key: {0}", id3v2.MusicalKey); // read length in milliseconds Console.WriteLine("Length in milliseconds: {0}", id3v2.LengthInMilliseconds); // read original album Console.WriteLine("Original album: {0}", id3v2.OriginalAlbum); // read size in bytes. Please note that is present TSIZ tag and may be overrided by invalid value Console.WriteLine("Original album: {0}", id3v2.SizeInBytes); // read TSRC value Console.WriteLine("Original album: {0}", id3v2.ISRC); // read TSSE value Console.WriteLine("Original album: {0}", id3v2.SoftwareHardware); // read PCNT value Console.WriteLine("Original album: {0}", id3v2.PlayCounter); } // and close input stream mp3Format.Dispose(); } } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Read ID3v1 tag in MP3 format /// </summary> /// public static void ReadID3v1Tag() { try { //ExStart:ReadID3v1Tag // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // get ID3v1 tag Id3v1Tag id3V1 = mp3Format.Id3v1; //NOTE: please remember you may use different approaches to getting metadata // second approach //id3V1 = (Id3v1Tag)MetadataUtility.ExtractSpecificMetadata(file, MetadataType.Id3v1); // check if ID3v1 is presented. It could be absent in Mpeg file. if (id3V1 != null) { // Display version Console.WriteLine("ID3v1 version: {0}", id3V1.Version); // Display tag properties Console.WriteLine("Album: {0}", id3V1.Album); Console.WriteLine("Artist: {0}", id3V1.Artist); Console.WriteLine("Comment: {0}", id3V1.Comment); Console.WriteLine("Genre: {0}", id3V1.Genre); Console.WriteLine("Title: {0}", id3V1.Title); Console.WriteLine("Year: {0}", id3V1.Year); if (id3V1.Version == "ID3v1.1") { // Track number is presented only in ID3 v1.1 Console.WriteLine("Track number: {0}", id3V1.TrackNumber); } } //ExEnd:ReadID3v1Tag } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Updates ID3v2 tag in MP3 format /// </summary> /// public static void UpdateID3v2Tag() { try { //ExStart:UpdateID3v2Tag // initialize Mp3Format class using (Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath)))) { // get id3v2 tag Id3v2Tag id3Tag = mp3Format.Id3v2 ?? new Id3v2Tag(); // set artist id3Tag.Artist = "A-ha"; // set title id3Tag.Title = "Take on me"; // set band id3Tag.Band = "A-ha"; // set comment id3Tag.Comment = "GroupDocs.Metadata creator"; // set track number id3Tag.TrackNumber = "5"; // set year id3Tag.Year = "1986"; // update ID3v2 tag mp3Format.UpdateId3v2(id3Tag); // and commit changes mp3Format.Save(); } //ExEnd:UpdateID3v2Tag } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Update ID3v2 tag using properties /// Feature is supported in version 18.2 or greater of the API /// </summary> public static void UpdateID3v2TagUsingProperties() { try { // init Mp3Format class using (Mp3Format mp3Format = new Mp3Format(Common.MapSourceFilePath(filePath))) { // get id3v2 tag. It creates new tag if metadata not exist so user does not need to check it by null. Id3v2Tag id3Tag = mp3Format.Id3v2Properties; // set artist id3Tag.Artist = "A-ha"; // set title id3Tag.Title = "Take on me"; // set band id3Tag.Band = "A-ha"; // set comment id3Tag.Comment = "GroupDocs.Metadata creator"; // set track number id3Tag.TrackNumber = "5"; // set year id3Tag.Year = "1986"; // and commit changes mp3Format.Save(); } } catch (Exception exp) { Console.WriteLine(exp.Message); } }
/// <summary> /// Reads ID3v1 tag in MP3 format /// </summary> /// public static void ReadID3v1Tag() { try { //ExStart:ReadID3v1Tag // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // get ID3v1 tag Id3v1Tag id3V1 = mp3Format.Id3v1; //NOTE: please remember you may use different approaches to getting metadata // second approach //id3V1 = (Id3v1Tag)MetadataUtility.ExtractSpecificMetadata(file, MetadataType.Id3v1); // check if ID3v1 is presented. It could be absent in Mpeg file. if (id3V1 != null) { // Display version Console.WriteLine("ID3v1 version: {0}", id3V1.Version); // Display tag properties Console.WriteLine("Album: {0}", id3V1.Album); Console.WriteLine("Artist: {0}", id3V1.Artist); Console.WriteLine("Comment: {0}", id3V1.Comment); Console.WriteLine("Genre: {0}", id3V1.Genre); Console.WriteLine("Title: {0}", id3V1.Title); Console.WriteLine("Year: {0}", id3V1.Year); if (id3V1.Version == "ID3v1.1") { // Track number is presented only in ID3 v1.1 Console.WriteLine("Track number: {0}", id3V1.TrackNumber); } } //ExEnd:ReadID3v1Tag } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Reads MPEG audio information /// </summary> /// public static void ReadMPEGAudioInfo() { try { //ExStart:ReadMPEGAudioInfo // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // get MPEG audio info MpegAudio audioInfo = mp3Format.AudioDetails; // display MPEG audio version Console.WriteLine("MPEG audio version: {0}", audioInfo.MpegAudioVersion); // display layer version Console.WriteLine("Layer version: {0}", audioInfo.LayerVersion); // display protected bit Console.WriteLine("Is protected: {0}", audioInfo.IsProtected); //ExEnd:ReadMPEGAudioInfo } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Reads Lyrics3 tag in Mp3 format /// </summary> public static void ReadLayrics3Tag() { try { //ExStart:ReadLayrics3TagInMp3 // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // get Lyrics3 v2.00 tag Lyrics3Tag lyrics3Tag = mp3Format.Lyrics3v2; // check if Lyrics3 is presented. It could be absent. if (lyrics3Tag != null) { // Display defined tag values Console.WriteLine("Album: {0}", lyrics3Tag.Album); Console.WriteLine("Artist: {0}", lyrics3Tag.Artist); Console.WriteLine("Track: {0}", lyrics3Tag.Track); // get all fields presented in Lyrics3Tag Lyrics3Field[] allFields = lyrics3Tag.Fields; foreach (Lyrics3Field lyrics3Field in allFields) { Console.WriteLine("Name: {0}, value: {1}", lyrics3Field.Name, lyrics3Field.Value); } } //ExEnd:ReadLayrics3TagInMp3 } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// Reads ID3v2 tag in MP3 format /// Supported ID3v2.3 and ID3v2.4, ID3v2.2 is obsolete by ID3.org /// </summary> public static void ReadID3v2Tag() { try { //ExStart:ReadID3v2Tag // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // get ID3 v2 tag Id3v2Tag id3v2 = mp3Format.Id3v2; if (id3v2 != null) { // write ID3v2 version Console.WriteLine("Version: {0}", id3v2.Version); // write known frames' values Console.WriteLine("Album: {0}", id3v2.Album); Console.WriteLine("Comment: {0}", id3v2.Comment); Console.WriteLine("Composers: {0}", id3v2.Composers); // in trial mode only first 5 frames are available TagFrame[] idFrames = id3v2.Frames; foreach (TagFrame tagFrame in idFrames) { Console.WriteLine("Frame: {0}, value: {1}", tagFrame.Name, tagFrame.GetFormattedValue()); } } //ExEnd:ReadID3v2Tag } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void ValidateMp3s(Hashes fileHash) { Bind.mp3Models = new List <Mp3Format.Model>(); int id3v1Count = 0, id3v23Count = 0, id3v24Count = 0; foreach (FileInfo mp3Info in Bind.mp3Infos) { Owner.SetCurrentFile(mp3Info.Name, Granularity.Verbose); using (var ffs = new FileStream(mp3Info.FullName, FileMode.Open, FileAccess.Read)) { var buf = new byte[0x2C]; int got = ffs.Read(buf, 0, buf.Length); Mp3Format.Model mp3Model = Mp3Format.CreateModel(ffs, buf, mp3Info.FullName); if (mp3Model == null) { Bind.MaxTrackSeverity = Severity.Error; Owner.ReportLine("Doesn't seem to be a MP3.", Severity.Error, Bind.Signature != null); } else { Mp3Format mp3 = mp3Model.Data; mp3Model.CalcHashes(Hashes.Intrinsic | Owner.Data.HashFlags | fileHash, Owner.Data.ValidationFlags); if (mp3.IsBadHeader) { ++Owner.Data.Mp3Format.TotalHeaderErrors; } if (mp3.IsBadData) { ++Owner.Data.Mp3Format.TotalDataErrors; } if (mp3.Lame != null) { if (Bind.RipProfile == null) { Bind.RipProfile = mp3.Lame.Profile; } else if (Bind.RipProfile != mp3.Lame.Profile) { mp3Model.IssueModel.Add($"Profile {mp3.Lame.Profile} inconsistent with rip profile of {Bind.RipProfile}."); } } if (mp3.HasId3v1) { ++id3v1Count; } if (mp3.HasId3v2) { if (mp3.Id3v2Major == 3) { ++id3v23Count; } else if (mp3.Id3v2Major == 4) { ++id3v24Count; } } IssueTags tags = Owner.Data.IsFussy? IssueTags.Fussy : IssueTags.None; mp3Model.IssueModel.Escalate(IssueTags.HasApe, tags | IssueTags.Substandard | IssueTags.Overstandard); if (Bind.MaxTrackSeverity < mp3.Issues.MaxSeverity) { Bind.MaxTrackSeverity = mp3.Issues.MaxSeverity; } Bind.mp3Models.Add(mp3Model); Owner.ReportFormat(mp3, Bind.Signature != null); } ++Owner.Data.Mp3Format.TrueTotal; ++Owner.Data.TotalFiles; if (mp3Model != null) { mp3Model.ClearFile(); } if (Bind.MaxTrackSeverity >= Severity.Fatal) { return; } } } if (new string[] { "V2", "V0", "C320" }.Any(x => x == Bind.RipProfile)) { LogModel.IssueModel.Add($"All tracks profile {Bind.RipProfile}.", Severity.Noise); } else { LogModel.IssueModel.Add($"Profile {Bind.RipProfile} is substandard.", Severity.Error, IssueTags.Substandard); } if (id3v1Count > 0 && id3v1Count != Bind.mp3Infos.Length) { LogModel.IssueModel.Add("Tracks have incomplete ID3v1 tagging."); } if (id3v23Count > 0 && id3v24Count > 0) { LogModel.IssueModel.Add("Tracks inconsistently tagged both ID3v2.3 and ID3v2.4."); } }
/// <summary> /// Updates ID3v1 tag in MP3 format /// </summary> /// public static void UpdateID3v1Tag() { try { //ExStart:UpdateID3v1Tag // initialize Mp3Format class Mp3Format mp3Format = new Mp3Format((Common.MapSourceFilePath(filePath))); // create id3v1 tag Id3v1Tag id3Tag = new Id3v1Tag(); // set artist id3Tag.Artist = "A-ha"; // set title id3Tag.Title = "Take on me"; // update ID3v1 tag mp3Format.UpdateId3v1(id3Tag); // and commit changes mp3Format.Save(); //ExEnd:UpdateID3v1Tag } catch (Exception ex) { Console.WriteLine(ex.Message); } }