public void EncodeSizeTest(int size) { byte[] rezult = ID3v2.SizeHelper.EncodeSize(size); TagLib.ByteVector vec = TagLib.Id3v2.SynchData.FromUInt((uint)size); Assert.AreEqual(vec.Data, rezult); }
//TagLib.Mpeg4.AppleTag private static string appleCustomTag(TagLib.Mpeg4.AppleTag atags, string key) { var type = atags.GetType(); var mi = type.GetMethod("FixId", BindingFlags.NonPublic | BindingFlags.Static); if (mi is null) { return(null); } var bvKey = new TagLib.ByteVector(key); var aBvKey = mi.Invoke(atags, new object[] { bvKey }) as TagLib.ReadOnlyByteVector; var tag = atags.GetText(aBvKey); if (tag.Length > 1) { var sb = new StringBuilder(); foreach (string s in tag) { if (sb.Length > 0) { sb.Append("; "); } sb.Append(s); } return(sb.ToString()); } else { return(tag.FirstOrDefault()); } }
public void GetSizeTest(byte[] rawData) { uint rezult = (uint)ID3v2.SizeHelper.GetSize(rawData); TagLib.ByteVector vec = new TagLib.ByteVector(rawData, rawData.Length); uint expected = TagLib.Id3v2.SynchData.ToUInt(vec); Assert.AreEqual(expected, rezult); }
/// <summary> /// get the sha1 of media file data (not including tag info) /// </summary> /// <param name="file"></param> /// <returns></returns> public static byte[] MediaSHA1(TagLib.File file) { try { int len = (int)file.InvariantEndPosition - (int)file.InvariantStartPosition; file.Seek(file.InvariantStartPosition); // TagLib.ByteVector vector = file.ReadBlock(len); // byte[] data = vector.Data; return(Utility.CryptoFunctions.SHA1(data)); } catch (OutOfMemoryException e) { Trace.WriteLine("OutOfMemoryException - " + file, Utility.Logger.Level.Error.ToString()); return(null); } }
/// <summary> /// タグ書込み /// </summary> /// <param name="row"></param> private void SaveTag(Row row) { string path = StringUtil.NullToBlank(row[(int)ColIndex.FullPath]); string extension = StringUtil.NullToBlank(row[(int)ColIndex.Extension]); string title = StringUtil.NullToBlank(row[(int)ColIndex.Title]); uint year = 0; DateTime releaseDate = DateTime.Parse("1900/1/1"); string date = StringUtil.NullToBlank(row[(int)ColIndex.ReleaseDate]); if (DateTime.TryParse(date, out releaseDate)) { year = (uint)releaseDate.Year; } if (extension.ToLower() == ".mp4") { //MP4のみ記入 var tagFile = TagLib.File.Create(path); tagFile.Tag.Title = title; tagFile.Tag.Year = year; tagFile.Tag.Performers = new string[] { StringUtil.NullToBlank(row[(int)ColIndex.Artist]) }; tagFile.Tag.Genres = new string[] { StringUtil.NullToBlank(row[(int)ColIndex.Genres]) }; tagFile.Tag.Comment = StringUtil.NullToBlank(row[(int)ColIndex.Comment]); //画像 Image img = this.TargetGrid.GetCellImage(row.Index, (int)ColIndex.Image); var ic = new System.Drawing.ImageConverter(); var ba = (byte[])ic.ConvertTo(img, typeof(byte[])); var byteVector = new TagLib.ByteVector(ba); var pic = new TagLib.Picture(byteVector); pic.Type = TagLib.PictureType.FrontCover; pic.Description = "Cover"; pic.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; tagFile.Tag.Pictures = new TagLib.IPicture[] { pic }; tagFile.Save(); } //リネーム var f = new FileInfo(path); f.MoveTo(f.DirectoryName + @"\" + StringUtil.ReplaceWindowsFileNGWord2Wide(title) + extension.ToLower()); }
public static TagLib.Picture ConvertToPicture(this Bitmap bitmap) { if (bitmap != null) { MemoryStream memoryStream = new MemoryStream(); bitmap.Save(memoryStream, ImageFormat.Png); memoryStream.Position = 0; TagLib.ByteVector vs = TagLib.ByteVector.FromStream(memoryStream); TagLib.Picture newpic = new TagLib.Picture(vs); vs.Clear(); memoryStream.Close(); return(newpic); } return(null); }
public void AddAlbumArt(byte[] encoded) { var data = new TagLib.ByteVector(encoded); var picture = new TagLib.Picture(data); picture.Type = TagLib.PictureType.FrontCover; _albumArt.Add(picture); }
internal static Stream ToStream(this TagLib.ByteVector aVector) { return(new MemoryStream(aVector.Data)); }
public void writeArtwork(TagLib.ByteVector picData) { Util.writePictureData(picData, this); }