/// <summary> /// Writes the given metadata into the given stream using the ID3v1.1 standard /// NB : Metadata fields that are not supported by ID3v1.1 standard (e.g. Composer) won't be written into the stream, even though their value are set /// </summary> /// <param name="tag">Metadata to be written</param> /// <param name="w">Stream to be used</param> /// <returns>True if operation completed successfuly; else false</returns> protected override Int32 write(TagData tag, BinaryWriter w, String zone) { // ID3v1 tags are C-String(null-terminated)-based tags // they are not unicode-encoded, hence the use of ReadOneByteChars w.Write(ID3V1_ID.ToCharArray()); w.Write(Utils.BuildStrictLengthString(tag.Title, 30, '\0').ToCharArray()); w.Write(Utils.BuildStrictLengthString(tag.Artist, 30, '\0').ToCharArray()); w.Write(Utils.BuildStrictLengthString(tag.Album, 30, '\0').ToCharArray()); // ID3v1 standard requires the year w.Write(Utils.BuildStrictLengthString(TrackUtils.ExtractStrYear(tag.RecordingYear), 4, '\0').ToCharArray()); w.Write(Utils.BuildStrictLengthString(tag.Comment, 28, '\0').ToCharArray()); // ID3v1.1 standard w.Write('\0'); w.Write((Byte)Math.Min(TrackUtils.ExtractTrackNumber(tag.TrackNumber), Byte.MaxValue)); Byte genre = 0; if (tag.Genre != null) { for (Byte i = 0; i < MAX_MUSIC_GENRES; i++) { if (tag.Genre.ToUpper().Equals(MusicGenre[i].ToUpper())) { genre = i; break; } } } w.Write(genre); return(7); }
public void TrackUtils_ExtractStrYear() { Assert.AreEqual("1952", TrackUtils.ExtractStrYear("1952")); Assert.AreEqual("1952", TrackUtils.ExtractStrYear("1952.1")); Assert.AreEqual("1952", TrackUtils.ExtractStrYear("1952,1")); Assert.AreEqual("1952", TrackUtils.ExtractStrYear("1952aaa")); Assert.AreEqual("1952", TrackUtils.ExtractStrYear("aaa1952")); Assert.AreEqual("1952", TrackUtils.ExtractStrYear("aa1952aa")); Assert.AreEqual("", TrackUtils.ExtractStrYear("")); Assert.AreEqual("", TrackUtils.ExtractStrYear(null)); Assert.AreEqual("", TrackUtils.ExtractStrYear("aaaa")); Assert.AreEqual("", TrackUtils.ExtractStrYear("999")); }