Example #1
0
        /// <summary>Creates the specified header.</summary>
        /// <param name="header">The header.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="contentSize">Size of the frame content.</param>
        /// <returns></returns>
        /// <exception cref="NotSupportedException"></exception>
        public static ID3v2FrameHeader Create(ID3v2Header header, string id, ID3v2FrameFlags flags, int contentSize)
        {
            switch (header.Version)
            {
            case 2: return(CreateVersion2(header, id, contentSize));

            case 3: return(CreateVersion3(header, id, flags, contentSize));

            case 4: return(CreateVersion4(header, id, flags, contentSize));

            default: throw new NotSupportedException(string.Format("Unsupported ID3v2 Version {0}", header.Version));
            }
        }
Example #2
0
        void ParseVersion2(byte[] data)
        {
            HeaderSize = 6;
            ID         = ASCII.GetString(data, 0, 3);
            Flags      = new ID3v2FrameFlags();
            var size = 0;

            for (var i = 3; i < 6; i++)
            {
                size = (size << 8) | data[i];
            }

            ContentSize = size;
        }
Example #3
0
        void ParseVersion3(byte[] data)
        {
            HeaderSize = 10;
            ID         = ASCII.GetString(data, 0, 4);
            var flags = (ID3v2d3FrameFlags)((data[8] << 8) | data[9]);

            Flags = ID3v2FrameFlags.FromID3v2d3(flags);
            var size = 0;

            for (var i = 4; i < 8; i++)
            {
                size = (size << 8) | data[i];
            }

            ContentSize = size;
        }
Example #4
0
        void ParseVersion4(byte[] data)
        {
            HeaderSize = 10;
            ID         = ASCII.GetCleanString(data, 0, 4);
            var flags = (ID3v2d4FrameFlags)((data[8] << 8) | data[9]);

            Flags = ID3v2FrameFlags.FromID3v2d4(flags);
            var size = 0;

            for (var i = 4; i < 8; i++)
            {
                if (data[i] > 0x7F)
                {
                    throw new InvalidDataException("ID3v2.4 Header with invalid non-unsynced size value found.");
                }
                size = (size << 7) | data[i];
            }
            ContentSize = size;
        }
Example #5
0
        /// <summary>Creates a version3 header.</summary>
        /// <param name="header">The header.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="contentSize">Size of the frame content.</param>
        /// <returns></returns>
        /// <exception cref="ArgumentException">Invalid identifier!.</exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public static ID3v2FrameHeader CreateVersion3(ID3v2Header header, string id, ID3v2FrameFlags flags, int contentSize)
        {
            if (id.Length != 4)
            {
                throw new ArgumentException("Invalid identifier!", nameof(id));
            }

            var data = ASCII.GetBytes(id + "      ");
            var f    = (ushort)flags.ToID3v2d3Flags();

            data[9] = (byte)(f & 0xFF);
            data[8] = (byte)(f >> 8);
            for (var i = 7; i >= 4; i--)
            {
                data[i]       = (byte)(contentSize & 0xFF);
                contentSize >>= 8;
            }
            if (contentSize > 0)
            {
                throw new ArgumentOutOfRangeException(nameof(contentSize));
            }

            return(new ID3v2FrameHeader(header, data));
        }