Skip to content

Commit

Permalink
Track.CopyMetadataTo [#59]
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeugma440 committed Jan 1, 2024
1 parent 875984e commit fe7c15d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
38 changes: 38 additions & 0 deletions ATL.unit-test/IO/TrackTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using ATL.AudioData;

namespace ATL.test.IO
{
[TestClass]
public class TrackTest
{
[TestMethod]
public void Track_CopyMetaTo()
{
Track track = new Track();
track.Title = "aaa";
track.Year = 1997;
var fields = new Dictionary<string, string>();
fields.Add("aa", "bb");
fields.Add("cc", "dd");
track.AdditionalFields = fields;


Track track2 = new Track();

Assert.IsNull(track2.Artist);
Assert.AreEqual(0, track2.Year);
Assert.IsNull(track2.AdditionalFields);

track.CopyMetadataTo(track2);

Assert.AreEqual("aaa", track2.Title);
Assert.AreEqual(1997, track2.Year);
Assert.AreEqual(2, track2.AdditionalFields.Count);
Assert.AreEqual("dd", track2.AdditionalFields["cc"]);

track.AdditionalFields["cc"] = "ee";

Assert.AreEqual("dd", track2.AdditionalFields["cc"]); // Test deep copy
}
}
}
60 changes: 60 additions & 0 deletions ATL/Entities/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,66 @@ public async Task<bool> RemoveAsync(MetaDataIOFactory.TagType tagType = MetaData
return result;
}

/// <summary>
/// Copy all metadata to the given track
/// NB : Physical information is not copied
/// </summary>
/// <param name="t">Track to copy metadata to</param>
public void CopyMetadataTo(Track t)
{
t.currentEmbeddedPictures ??= new List<PictureInfo>();
t.currentEmbeddedPictures.Clear();
if (EmbeddedPictures != null)
foreach (var pic in EmbeddedPictures) t.currentEmbeddedPictures.Add(new PictureInfo(pic));

t.Title = Title;
t.Artist = Artist;
t.Composer = Composer;
t.Comment = Comment;
t.Genre = Genre;
t.OriginalArtist = OriginalArtist;
t.OriginalAlbum = OriginalAlbum;
t.Description = Description;
t.Copyright = Copyright;
t.Publisher = Publisher;
t.AlbumArtist = AlbumArtist;
t.Conductor = Conductor;
t.ProductId = ProductId;
t.SortAlbum = SortAlbum;
t.SortAlbumArtist = SortAlbumArtist;
t.SortArtist = SortArtist;
t.SortTitle = SortTitle;
t.Group = Group;
t.SeriesTitle = SeriesTitle;
t.SeriesPart = SeriesPart;
t.LongDescription = LongDescription;
t.Album = Album;
t.isYearExplicit = isYearExplicit;
t.Year = Year;
t.Date = Date;
t.PublishingDate = PublishingDate;
t.TrackNumber = TrackNumber;
t.TrackTotal = TrackTotal;
t.DiscNumber = DiscNumber;
t.DiscTotal = DiscTotal;
t.Popularity = Popularity;
t.BPM = BPM;

t.Chapters ??= new List<ChapterInfo>();
t.Chapters.Clear();
if (Chapters != null)
foreach (var chap in Chapters) t.Chapters.Add(new ChapterInfo(chap));
t.ChaptersTableDescription = ChaptersTableDescription;

if (Lyrics != null) t.Lyrics = new LyricsInfo(Lyrics);
else t.Lyrics = null;

t.AdditionalFields ??= new Dictionary<string, string>();
t.AdditionalFields.Clear();
if (AdditionalFields != null)
foreach (var af in AdditionalFields) t.AdditionalFields.Add(new KeyValuePair<string, string>(af.Key, af.Value));
}

/// FORMATTING UTILITIES

private string processString(string value)
Expand Down

0 comments on commit fe7c15d

Please sign in to comment.