/// <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);
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        protected override object AddNewCore()
        {
            IPrivateFrame frame1 = new PrivateFrame();

            base.Add(frame1);
            return(frame1);
        }
Beispiel #4
0
        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();
        }
        protected override object AddNewCore()
        {
            IPrivateFrame privateFrame = new PrivateFrame();

            Add(privateFrame);

            // Not necessary to hook up event handlers, base class calls InsertItem

            return(privateFrame);
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
        private static Id3Frame DecodePrivate(byte[] data)
        {
            var frame = new PrivateFrame();

            byte[] splitterSequence = TextEncodingHelper.GetSplitterBytes(Id3TextEncoding.Iso8859_1);
            byte[] ownerIdBytes     = ByteArrayHelper.GetBytesUptoSequence(data, 0, splitterSequence);
            frame.OwnerId = TextEncodingHelper.GetString(ownerIdBytes, 0, ownerIdBytes.Length, Id3TextEncoding.Iso8859_1);
            frame.Data    = new byte[data.Length - ownerIdBytes.Length - splitterSequence.Length];
            Array.Copy(data, ownerIdBytes.Length + splitterSequence.Length, frame.Data, 0, frame.Data.Length);
            return(frame);
        }
Beispiel #8
0
        private void SetPRIV(FrameFlagSet ffs, byte[] data)
        {
            PrivateFrame frame = new PrivateFrame(ffs, data);

            if (this._PRIV == null || this._PRIV.Length == 0)
            {
                this._PRIV = new PrivateFrame[] { frame };
            }
            else
            {
                this._PRIV = Generic.Add(this._PRIV, frame);
            }
        }
Beispiel #9
0
 /// <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);
     }
 }
Beispiel #10
0
 /// <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);
     }
 }
Beispiel #11
0
        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"]);
        }
Beispiel #12
0
        public override void WriteToStream(System.IO.Stream stream)
        {
            PrivateFrame frame  = (PrivateFrame)this.FrameToWrite;
            List <Field> fields = new List <Field>();

            // Declare the fields to write.
            fields.Add(TextField.CreateTextField(frame.OwnerIdentifier, EncodingScheme.Ascii));
            fields.Add(new BinaryField(frame.PrivateData, 0, frame.PrivateData.Length));

            // Write the header
            int length = 0;

            foreach (Field f in fields)
            {
                length += f.Length;
            }
            HeaderWriter.WriteHeader(stream, new FrameHeader(this.FrameID, length));

            // Write the fields
            foreach (Field f in fields)
            {
                f.WriteToStream(stream);
            }
        }
Beispiel #13
0
 public PrivateFrameWriter(PrivateFrame frameToWrite, Writers.FrameHeaderWriter frameHeaderWriter, string frameID, EncodingScheme encoding)
     : base(frameToWrite, frameHeaderWriter, frameID, encoding)
 {
 }
Beispiel #14
0
 public PrivateFrameWriter(PrivateFrame frameToWrite, Writers.FrameHeaderWriter frameHeaderWriter, string frameID, EncodingScheme encoding)
     : base(frameToWrite, frameHeaderWriter, frameID, encoding)
 {
 }