public void TestPrivateFrame() { MockFileSystem fileSystem = new MockFileSystem(); fileSystem.AddFile(@"C:\test.mp3", new MockFileData(System.IO.File.ReadAllBytes(@"TestData\test.mp3"))); File.IFileAbstraction mp3File = fileSystem.File.CreateFileAbstraction(@"C:\test.mp3"); File file = File.Create(mp3File); Tag id3V2Tag = (Tag)file.GetTag(TagTypes.Id3v2, true); // Get the private frame, create if necessary. PrivateFrame frame = PrivateFrame.Get(id3V2Tag, "SW/Uid", true); string uid = Guid.NewGuid().ToString("N"); frame.PrivateData = Encoding.Unicode.GetBytes(uid); file.Save(); File actualFile = File.Create(mp3File); id3V2Tag = (Tag)actualFile.GetTag(TagTypes.Id3v2, true); // Get the private frame, create if necessary. PrivateFrame actualFrame = PrivateFrame.Get(id3V2Tag, "SW/Uid", true); // Set the frame data to your value. I am 90% sure that these are encoded with UTF-16. string actualUid = Encoding.Unicode.GetString(actualFrame.PrivateData.Data); actualUid.Should().Be(uid); }
/// <summary> /// Function to add ID3 transportStreamTimestamp to an AAC file. /// </summary> /// <param name="args"> /// Array of input parameters. Should have 2 elements in it. /// args[0] = file location. /// args[1] = timestamp to be added to the file. /// </param> public static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("There must be 2 command line arguments [file, timestampPts]. Only passed: [" + string.Join(",", args) + "]"); return; } var fileLocation = args[0]; var timestampString = args[1]; var file = File.Create(fileLocation); var offsetPts = Convert.ToInt64(timestampString); var bytes = BitConverter.GetBytes(offsetPts); if (BitConverter.IsLittleEndian) { Array.Reverse(bytes); } var id3v2_tag = (TagLib.Id3v2.Tag)file.GetTag(TagTypes.Id3v2, true); if (id3v2_tag != null) { Console.WriteLine("Updating private frame with timestamp: [" + string.Join(",", bytes) + "]"); // Get the private frame, create if necessary. PrivateFrame frame = PrivateFrame.Get(id3v2_tag, "com.apple.streaming.transportStreamTimestamp", true); frame.PrivateData = bytes; file.Save(); Console.WriteLine("Updated ID3 tag of file: " + fileLocation); } }
static void SetExplicit(string file) { var f = TagLib.File.Create(file); var t = (TagLib.Id3v2.Tag)f.GetTag(TagTypes.Id3v2); var p = PrivateFrame.Get(t, "ITUNESADVISORY", true); p.PrivateData = System.Text.Encoding.Unicode.GetBytes("1"); f.Save(); }
static void Main(string[] args) { var f = TagLib.File.Create(@"I:\song.mp3"); var t = (TagLib.Id3v2.Tag)f.GetTag(TagTypes.Id3v2); var p = PrivateFrame.Get(t, "AlbumType", true); p.PrivateData = System.Text.Encoding.Unicode.GetBytes("TAG CHANGED"); f.Tag.Album = "test"; f.Save(); }
/// <summary> /// Attempt to write a private frame /// </summary> private bool TryWritePrivateFrame(string name, string value) { try { TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)mp3File.GetTag(TagTypes.Id3v2, true); var privateFrame = PrivateFrame.Get(tag, name, true); privateFrame.PrivateData = Encoding.Unicode.GetBytes(value ?? string.Empty); return(true); } catch { return(false); } }
/// <summary> /// Attempt to read a private frame /// </summary> private bool TryReadPrivateFrame(string name, out string value) { try { TagLib.Id3v2.Tag tag = (TagLib.Id3v2.Tag)mp3File.GetTag(TagTypes.Id3v2); var privateFrame = PrivateFrame.Get(tag, name, false); value = Encoding.Unicode.GetString(privateFrame.PrivateData.Data); return(true); } catch { value = string.Empty; return(false); } }
public void WritePrivateFrames_TagsAreWritten() { const string fileName = @"C:\test.mp3"; _mockFileSystem.AddFile(fileName, new MockFileData(System.IO.File.ReadAllBytes(@"TestData\test.mp3"))); File.IFileAbstraction mp3File = _mockFileSystem.File.CreateFileAbstraction(fileName); Dictionary <string, string> values = new Dictionary <string, string> { { "SW/Uid", Guid.NewGuid().ToString("N") } }; _tagTool.WritePrivateFrames(fileName, values); File actualFile = File.Create(mp3File); TagLib.Id3v2.Tag id3V2Tag = (TagLib.Id3v2.Tag)actualFile.GetTag(TagTypes.Id3v2, true); PrivateFrame actualFrame = PrivateFrame.Get(id3V2Tag, "SW/Uid", true); string actualUid = Encoding.Unicode.GetString(actualFrame.PrivateData.Data); actualUid.Should().Be(values["SW/Uid"]); }