Skip to content

Commit 54e536f

Browse files
committed
Added a property to influence auto creation of nonexisting ID3 tags when opening a file
1 parent d4a75ba commit 54e536f

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

src/TaglibSharp/Mpeg/AudioFile.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ public class AudioFile : TagLib.NonContainer.File
6868
#endregion
6969

7070

71+
#region Private Static Fields
72+
73+
/// <summary>
74+
/// Specifies whether or not to create ID3v1 and
75+
/// ID3v2 tags when they don't exist..
76+
/// </summary>
77+
private static bool create_id3_tags = true;
78+
79+
#endregion
80+
7181

7282
#region Constructors
7383

@@ -154,6 +164,33 @@ public AudioFile (IFileAbstraction abstraction)
154164
#endregion
155165

156166

167+
#region Public Static Properties
168+
169+
/// <summary>
170+
/// Gets and sets whether or not to create ID3v1 and
171+
/// ID3v2 tags automatically when they are not existing.
172+
/// </summary>
173+
/// <value>
174+
/// <see langword="true" /> if tags to be created automatically.
175+
/// Otherwise, <see langword="false" />.
176+
/// </value>
177+
/// <remarks>
178+
/// <para>Sometimes a MP3 file should only contain ID3v1 and no
179+
/// ID3v2 Tags. Or instead of ID3v2 Tags APE Tags should be used.
180+
/// By setting this property to <see langword="false" />,
181+
/// no ID3v1 and Id3v2 Tags will be created when creating the file,
182+
/// if they don't exist.
183+
/// They need to be created explicitly if needed.</para>
184+
/// <para>The default is <see langword="true" /> which means that
185+
/// ID3v1 and Id3v2 tags are created when they don't exist.</para>
186+
/// </remarks>
187+
public static bool CreateID3Tags {
188+
get { return create_id3_tags; }
189+
set { create_id3_tags = value; }
190+
}
191+
192+
#endregion
193+
157194

158195
#region Public Methods
159196

@@ -252,9 +289,9 @@ protected override void ReadStart (long start, ReadStyle propertiesStyle)
252289
/// </param>
253290
protected override void ReadEnd (long end, ReadStyle propertiesStyle)
254291
{
255-
// Make sure we have ID3v1 and ID3v2 tags.
256-
GetTag (TagTypes.Id3v1, true);
257-
GetTag (TagTypes.Id3v2, true);
292+
// Creation of ID3v1 and ID3v2 tags based on CreateID3Tags property
293+
GetTag (TagTypes.Id3v1, create_id3_tags);
294+
GetTag (TagTypes.Id3v2, create_id3_tags);
258295
}
259296

260297
/// <summary>

0 commit comments

Comments
 (0)