diff --git a/src/TaglibSharp.Tests/FileFormats/Id3BothFormatTest.cs b/src/TaglibSharp.Tests/FileFormats/Id3BothFormatTest.cs index adcccc2c..c60a0268 100644 --- a/src/TaglibSharp.Tests/FileFormats/Id3BothFormatTest.cs +++ b/src/TaglibSharp.Tests/FileFormats/Id3BothFormatTest.cs @@ -133,5 +133,49 @@ public void TestCreateId3Tags () file = File.Create (tempFile); Assert.AreEqual (TagTypes.Id3v1 | TagTypes.Id3v2, file.TagTypes); } + + [Test] + public void TestCreateId3SeparateTags () + { + string tempFile = TestPath.Samples + "tmpwrite_sample_createid3tags.mp3"; + + System.IO.File.Copy (sample_file, tempFile, true); + + // Remove All Tags first + var file = File.Create (tempFile); + file.RemoveTags (TagTypes.AllTags); + file.Save (); + + // No TagTypes should exist + TagLib.Mpeg.AudioFile.CreateID3V1Tags = false; + TagLib.Mpeg.AudioFile.CreateID3V2Tags = false; + file = File.Create (tempFile); + Assert.AreEqual (TagTypes.None, file.TagTypes); + file.RemoveTags (TagTypes.AllTags); + file.Save (); + + // Only V1 TagTypes should exist + TagLib.Mpeg.AudioFile.CreateID3V1Tags = true; + TagLib.Mpeg.AudioFile.CreateID3V2Tags = false; + file = File.Create (tempFile); + Assert.AreEqual (TagTypes.Id3v1, file.TagTypes); + file.RemoveTags (TagTypes.AllTags); + file.Save (); + + // Only V2 TagTypes should exist + TagLib.Mpeg.AudioFile.CreateID3V1Tags = false; + TagLib.Mpeg.AudioFile.CreateID3V2Tags = true; + file = File.Create (tempFile); + Assert.AreEqual (TagTypes.Id3v2, file.TagTypes); + file.RemoveTags (TagTypes.AllTags); + file.Save (); + + // Both V1 and V2 TagTypes should exist + TagLib.Mpeg.AudioFile.CreateID3V1Tags = true; + TagLib.Mpeg.AudioFile.CreateID3V2Tags = true; + file = File.Create (tempFile); + Assert.AreEqual (TagTypes.Id3v1 | TagTypes.Id3v2, file.TagTypes); + file.Save (); + } } } diff --git a/src/TaglibSharp/Mpeg/AudioFile.cs b/src/TaglibSharp/Mpeg/AudioFile.cs index ccfbee41..8bbbd70e 100644 --- a/src/TaglibSharp/Mpeg/AudioFile.cs +++ b/src/TaglibSharp/Mpeg/AudioFile.cs @@ -71,10 +71,16 @@ public class AudioFile : TagLib.NonContainer.File #region Private Static Fields /// - /// Specifies whether or not to create ID3v1 and - /// ID3v2 tags when they don't exist.. + /// Specifies whether or not to create ID3v1 + /// tag when it doesn't exist. /// - private static bool create_id3_tags = true; + private static bool create_id3_v1_tags = true; + + /// + /// Specifies whether or not to create ID3v2 + /// tag when it doesn't exist. + /// + private static bool create_id3_v2_tags = true; #endregion @@ -187,6 +193,63 @@ public AudioFile (IFileAbstraction abstraction) public static bool CreateID3Tags { get { return create_id3_tags; } set { create_id3_tags = value; } + get { + if (create_id3_v1_tags && create_id3_v2_tags) { + return true; + } else if (!create_id3_v1_tags && !create_id3_v2_tags) { + return false; + } + + throw new InvalidOperationException("Inconsistent V1 and V2 state."); + } + set { + create_id3_v1_tags = value; + create_id3_v2_tags = value; + } + } + + /// + /// Gets and sets whether or not to create an ID3v1 tag + /// automatically when it is not existing. + /// + /// + /// if the tag is to be created automatically. + /// Otherwise, . + /// + /// + /// Sometimes an MP3 file should not contain an ID3v1 Tag. + /// By setting this property to , + /// no ID3v1 Tag will be created when creating the file, + /// if it doesn't exist. + /// It needs to be created explicitly if needed. + /// The default is which means that + /// an ID3v1 tag is created when it doesn't exist. + /// + public static bool CreateID3V1Tags { + get { return create_id3_v1_tags; } + set { create_id3_v1_tags = value; } + } + + /// + /// Gets and sets whether or not to create an ID3v2 tag + /// automatically when it is not existing. + /// + /// + /// if the tag is to be created automatically. + /// Otherwise, . + /// + /// + /// Sometimes an MP3 file should not contain an ID3v2 Tag. + /// By setting this property to , + /// no ID3v1 Tag will be created when creating the file, + /// if it doesn't exist. + /// It needs to be created explicitly if needed. + /// The default is which means that + /// an ID3v2 tag is created when it doesn't exist. + /// + public static bool CreateID3V2Tags { + get { return create_id3_v2_tags; } + set { create_id3_v2_tags = value; } } #endregion @@ -290,8 +353,8 @@ protected override void ReadStart (long start, ReadStyle propertiesStyle) protected override void ReadEnd (long end, ReadStyle propertiesStyle) { // Creation of ID3v1 and ID3v2 tags based on CreateID3Tags property - GetTag (TagTypes.Id3v1, create_id3_tags); - GetTag (TagTypes.Id3v2, create_id3_tags); + GetTag (TagTypes.Id3v1, create_id3_v1_tags); + GetTag (TagTypes.Id3v2, create_id3_v2_tags); } ///