Skip to content

Commit

Permalink
Fall back to the first supported metadata format if none of the selec…
Browse files Browse the repository at this point in the history
…ted formats is able to write to the file
  • Loading branch information
Zeugma440 committed Aug 10, 2020
1 parent a5a8dcb commit 5bbd3a4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
20 changes: 16 additions & 4 deletions ATL/AudioData/AudioDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,22 @@ public IList<int> getAvailableMetas()
{
IList<int> result = new List<int>();

if (hasMeta(MetaDataIOFactory.TAG_ID3V1)) result.Add(MetaDataIOFactory.TAG_ID3V1);
if (hasMeta(MetaDataIOFactory.TAG_ID3V2)) result.Add(MetaDataIOFactory.TAG_ID3V2);
if (hasMeta(MetaDataIOFactory.TAG_APE)) result.Add(MetaDataIOFactory.TAG_APE);
if (hasMeta(MetaDataIOFactory.TAG_NATIVE)) result.Add(MetaDataIOFactory.TAG_NATIVE);
foreach(int tagType in Enum.GetValues(typeof(MetaDataIOFactory.TagType)))
{
if (hasMeta(tagType)) result.Add(tagType);
}

return result;
}

public IList<int> getSupportedMetas()
{
IList<int> result = new List<int>();

foreach (int tagType in Enum.GetValues(typeof(MetaDataIOFactory.TagType)))
{
if (audioDataIO.IsMetaSupported(tagType)) result.Add(tagType);
}

return result;
}
Expand Down
12 changes: 10 additions & 2 deletions ATL/AudioData/AudioFileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,20 @@ public AudioFileIO(Stream stream, String mimeType, bool readEmbeddedPictures, bo
public void Save(TagData data)
{
IList<int> availableMetas = audioManager.getAvailableMetas();
IList<int> supportedMetas = audioManager.getSupportedMetas();

// File has no existing metadata
// => Try writing with one of the metas set in the Settings
if (0 == availableMetas.Count)
{
foreach (int i in Settings.DefaultTagsWhenNoMetadata)
{
availableMetas.Add(i);
if (supportedMetas.Contains(i)) availableMetas.Add(i);
}

// File does not support any of the metas we want to write
// => Use the first supported meta available
if (0 == availableMetas.Count && supportedMetas.Count > 0) availableMetas.Add(supportedMetas[0]);
}

float written = 0;
Expand All @@ -108,7 +115,8 @@ public void Remove(int tagType = MetaDataIOFactory.TAG_ANY)
if (MetaDataIOFactory.TAG_ANY == tagType)
{
metasToRemove = audioManager.getAvailableMetas();
} else
}
else
{
metasToRemove = new List<int>() { tagType };
}
Expand Down
14 changes: 12 additions & 2 deletions ATL/AudioData/MetaDataIOFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ public class MetaDataIOFactory
// Count of the types defined above, excluding "any" type
public static readonly int TAG_TYPE_COUNT = 4;

// Defines the default reading priority of the metadata
private int[] tagPriority;
public enum TagType
{
ID3V1 = TAG_ID3V1,
ID3V2 = TAG_ID3V2,
APE = TAG_APE,
NATIVE = TAG_NATIVE,
ANY = TAG_ANY
}


// Defines the default reading priority of the metadata
private int[] tagPriority;

// Defines whether the next created metadatareaders should use cross-tag reading
private bool m_enableCrossReading = true;
Expand Down

0 comments on commit 5bbd3a4

Please sign in to comment.