Skip to content

Commit

Permalink
General : Changed the default behaviour so that MP4, FLAC, OGG, MKA a…
Browse files Browse the repository at this point in the history
…nd WMA write into their native tagging system alone upon writing on a metadata-free file (instead of using an APEtag or ID3v2 clutch) [#289]
  • Loading branch information
Zeugma440 committed Nov 30, 2024
1 parent 72ddbf0 commit 8cf896b
Show file tree
Hide file tree
Showing 36 changed files with 79 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ATL.unit-test/IO/HighLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public void TagIO_RW_Padding()
tagIO_RW_AddPadding("MP3/empty.mp3");
tagIO_RW_AddPadding("OGG/empty.ogg", 8); // 8 extra bytes for the segments table extension
tagIO_RW_AddPadding("MP4/chapters_NERO.mp4");
tagIO_RW_AddPadding("FLAC/empty.flac", ATL.Settings.PaddingSize + 4); // Additional padding for the ID3v2 tag + 4 bytes for VorbisComment's PADDING block header
tagIO_RW_AddPadding("FLAC/empty.flac", 4); // Additional padding : 4 bytes for VorbisComment's PADDING block header
}
finally
{
Expand Down
Binary file removed ATL.unit-test/Resources/tmp/AtomicParsley.exe
Binary file not shown.
8 changes: 5 additions & 3 deletions ATL/AudioData/AudioDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,16 @@ public ISet<TagType> getRecommendedMetas()
if (1 == supportedMetas.Count) result.Add(supportedMetas[0]);
else
{
if (audioDataIO is OptimFrog) result.Add(TagType.APE); // TODO this is ugly
if (audioDataIO is OptimFrog) result.Add(TagType.APE); // TODO this is ugly (see #249)
else
{
var id3v2Exists = supportedMetas.Contains(TagType.ID3V2);
bool isNativeRich = audioDataIO.IsNativeMetadataRich && supportedMetas.Exists(meta => meta == TagType.NATIVE);
foreach (var meta in supportedMetas.Where(meta => meta != TagType.ID3V1))
{
if (meta == TagType.ID3V2 || meta == TagType.NATIVE) result.Add(meta); // Default preference go to these
if (meta == TagType.APE && !id3v2Exists) result.Add(meta); // If no ID3v2 support at all
if (meta == TagType.NATIVE && isNativeRich) result.Add(meta);
if (meta == TagType.ID3V2 && !isNativeRich) result.Add(meta); // If poor native metadata
if (meta == TagType.APE && !id3v2Exists && !isNativeRich) result.Add(meta); // If no ID3v2 support and poor native metadata
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/AudioFileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ public List<TagType> GetSupportedMetas()
return audioData.GetSupportedMetas();
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => audioData.IsNativeMetadataRich;
/// <inheritdoc/>
public bool Read(Stream source, AudioDataManager.SizeInfo sizeNfo, MetaDataIO.ReadTagParams readTagParams)
{
return audioData.Read(source, sizeNfo, readTagParams);
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/AA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public int SampleRate
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
/// <inheritdoc/>
public ChannelsArrangement ChannelsArrangement => MONO;
/// <inheritdoc/>
public long AudioDataOffset { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/AAC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public AudioFormat AudioFormat
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
/// <inheritdoc/>
public ChannelsArrangement ChannelsArrangement { get; private set; }

/// <inheritdoc/>
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/AC3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class AC3 : IAudioDataIO
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.APE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
/// <inheritdoc/>
public long AudioDataOffset { get; set; }
/// <inheritdoc/>
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/AIFF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public AudioFormat AudioFormat
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion ATL/AudioData/IO/Ape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ private sealed class ApeDescriptor
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.ID3V1 };
}

/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }

Expand Down
3 changes: 3 additions & 0 deletions ATL/AudioData/IO/CAF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class CAF : MetaDataIO, IAudioDataIO
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}

/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

protected override int getDefaultTagOffset()
{
return TO_BUILTIN;
Expand Down
3 changes: 2 additions & 1 deletion ATL/AudioData/IO/DSF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class DSF : IAudioDataIO, IMetaDataEmbedder
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.ID3V2 };
}

/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
// IMetaDataEmbedder
public long HasEmbeddedID3v2 => id3v2Offset;
public uint ID3v2EmbeddingHeaderSize => 0;
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/DTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class DTS : IAudioDataIO
{
return new List<MetaDataIOFactory.TagType>(); // No supported metas
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/DummyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public DummyReader(string filePath)
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

/// <inheritdoc/>
public bool Read(Stream source, AudioDataManager.SizeInfo sizeNfo, MetaDataIO.ReadTagParams readTagParams)
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/FLAC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public override IList<Format> MetadataFormats
// Native is for VorbisTag
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.ID3V2 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => true;


// ---------- CONSTRUCTORS & INITIALIZERS
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/GYM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class GYM : MetaDataIO, IAudioDataIO
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

// IMetaDataIO
protected override int getDefaultTagOffset()
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/IT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class IT : MetaDataIO, IAudioDataIO
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
/// <inheritdoc/>
public long AudioDataOffset { get; set; }
/// <inheritdoc/>
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/MIDI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ public void Add(MidiEvent evt)
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE }; // Only for comments
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
/// <inheritdoc/>
public long AudioDataOffset { get; set; }
/// <inheritdoc/>
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/MKA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public AudioFormat AudioFormat

protected override MetaDataIOFactory.TagType getImplementedTagType() => MetaDataIOFactory.TagType.NATIVE;

/// <inheritdoc/>
public bool IsNativeMetadataRich => true;
protected override Field getFrameMapping(string zone, string ID, byte tagVersion)
{
Field supportedMetaId = Field.NO_FIELD;
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/MOD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public AudioFormat AudioFormat
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion ATL/AudioData/IO/MP4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public bool isValid()
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V1 };
}

/// <inheritdoc/>
public bool IsNativeMetadataRich => true;
public ChannelsArrangement ChannelsArrangement { get; private set; }

public long AudioDataOffset { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/MPEGaudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ public AudioFormat AudioFormat
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;


// ---------- CONSTRUCTORS & INITIALIZERS
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/MPEGplus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public void computeVersion()
MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V1
};
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/Ogg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ public AudioFormat AudioFormat
// According to id3.org (FAQ), ID3 is not compatible with OGG. Hence ATL does not allow ID3 tags to be written on OGG files; native is for VorbisTag
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => true;

/// <inheritdoc/>
public override IList<Format> MetadataFormats
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/OptimFROG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ public static bool IsValidHeader(byte[] data)
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public bool Read(Stream source, SizeInfo sizeNfo, MetaDataIO.ReadTagParams readTagParams)
{
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/PSF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public AudioFormat AudioFormat
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/S3M.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public AudioFormat AudioFormat
// IMetaDataIO
protected override int getDefaultTagOffset() => TO_BUILTIN;
protected override MetaDataIOFactory.TagType getImplementedTagType() => MetaDataIOFactory.TagType.NATIVE;
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
protected override Field getFrameMapping(string zone, string ID, byte tagVersion)
{
throw new NotImplementedException();
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/SPC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ partial class SPC : MetaDataIO, IAudioDataIO
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.APE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/TAK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class TAK : IAudioDataIO
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.APE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;
public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/TTA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class TTA : IAudioDataIO
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/TwinVQ.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ private sealed class HeaderInfo
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/VGM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class VGM : MetaDataIO, IAudioDataIO
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/WAV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public AudioFormat AudioFormat
// Native for bext, info and iXML chunks
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/WAVPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public void Reset()
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.APE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/WMA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ private void Reset()
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE, MetaDataIOFactory.TagType.ID3V2, MetaDataIOFactory.TagType.APE, MetaDataIOFactory.TagType.ID3V1 };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => true;

/// <inheritdoc/>
protected override Field getFrameMapping(string zone, string ID, byte tagVersion)
Expand Down
2 changes: 2 additions & 0 deletions ATL/AudioData/IO/XM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public AudioFormat AudioFormat
{
return new List<MetaDataIOFactory.TagType> { MetaDataIOFactory.TagType.NATIVE };
}
/// <inheritdoc/>
public bool IsNativeMetadataRich => false;

public long AudioDataOffset { get; set; }
public long AudioDataSize { get; set; }
Expand Down
8 changes: 8 additions & 0 deletions ATL/AudioData/Interfaces/IAudioDataIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ long AudioDataSize
/// <returns>Metadata type supported by the present audio format</returns>
List<MetaDataIOFactory.TagType> GetSupportedMetas();

/// <summary>
/// True if the native tagging system contains a wide array of fields
/// </summary>
bool IsNativeMetadataRich
{
get;
}

/// <summary>
/// Read audio data from the given stream.
/// NB1 : Standard metadata (i.e. ID3v2, ID3v1 and APE) have to be read _before_ calling this method, and their size stored in sizeInfo
Expand Down

0 comments on commit 8cf896b

Please sign in to comment.