Esempio n. 1
0
        /// <summary>
        /// Load the picture data from the file,
        /// if not done yet.
        /// </summary>
        public void Load()
        {
            // Already loaded ?
            if (file == null)
            {
                return;
            }

            // Load the picture from the stream

            Stream     stream = null;
            ByteVector data   = null;

            try {
                if (stream_size == 0)
                {
                    data = new ByteVector();
                }
                else if (stream_size > 0)
                {
                    stream = file.ReadStream;
                    stream.Seek(stream_offset, SeekOrigin.Begin);

                    int    count = 0, read = 0, needed = (int)stream_size;
                    byte[] buffer = new byte[needed];

                    do
                    {
                        count = stream.Read(buffer, read, needed);

                        read   += count;
                        needed -= count;
                    } while (needed > 0 && count != 0);


                    data = new ByteVector(buffer, read);
                }
                else
                {
                    stream = file.ReadStream;
                    stream.Seek(stream_offset, SeekOrigin.Begin);

                    data = ByteVector.FromStream(stream);
                }
            } finally {
                // Free the resources
                if (stream != null && file != null)
                {
                    file.CloseStream(stream);
                }

                file = null;
            }

            // Decode the raw data if required, by using FieldData
            raw_data = FieldData(data, -(int)FrameHeader.Size(raw_version), raw_version);

            // Get the actual data
            ParseRawData();
        }
Esempio n. 2
0
        protected ByteVector FieldData(ByteVector frameData, int offset, byte version)
        {
            if (frameData == null)
            {
                throw new ArgumentNullException("frameData");
            }
            int data_offset = offset + (int)FrameHeader.Size(version);
            int data_length = (int)Size;

            if ((Flags & (FrameFlags.Compression | FrameFlags.DataLengthIndicator)) != 0)
            {
                data_offset += 4;
                data_length -= 4;
            }
            if ((Flags & FrameFlags.GroupingIdentity) != 0)
            {
                if (frameData.Count >= data_offset)
                {
                    throw new TagLib.CorruptFileException("Frame data incomplete.");
                }
                group_id = frameData[data_offset++];
                data_length--;
            }
            if ((Flags & FrameFlags.Encryption) != 0)
            {
                if (frameData.Count >= data_offset)
                {
                    throw new TagLib.CorruptFileException("Frame data incomplete.");
                }
                encryption_id = frameData[data_offset++];
                data_length--;
            }
            data_length = Math.Min(data_length, frameData.Count - data_offset);
            if (data_length < 0)
            {
                throw new CorruptFileException("Frame size less than zero.");
            }
            ByteVector data = frameData.Mid(data_offset, data_length);

            if ((Flags & FrameFlags.Unsynchronisation) != 0)
            {
                int before_length = data.Count;
                SynchData.ResynchByteVector(data);
                data_length -= (data.Count - before_length);
            }
            if ((Flags & FrameFlags.Encryption) != 0)
            {
                throw new NotImplementedException();
            }
            if ((Flags & FrameFlags.Compression) != 0)
            {
                throw new NotImplementedException();
            }
            return(data);
        }
Esempio n. 3
0
        public static Frame CreateFrame(ByteVector data, ref int offset, byte version, bool alreadyUnsynched)
        {
            int         position = offset;
            FrameHeader header   = new FrameHeader(data.Mid(position, (int)FrameHeader.Size(version)), version);

            offset += (int)(header.FrameSize + FrameHeader.Size(version));
            if (header.FrameId == null)
            {
                throw new System.NotImplementedException();
            }
            foreach (byte b in header.FrameId)
            {
                char c = (char)b;
                if ((c < 'A' || c > 'Z') && (c < '0' || c > '9'))
                {
                    return(null);
                }
            }
            if (alreadyUnsynched)
            {
                header.Flags &= ~FrameFlags.Unsynchronisation;
            }
            if (header.FrameSize == 0)
            {
                header.Flags |= FrameFlags.TagAlterPreservation;
                return(new UnknownFrame(data, position, header, version));
            }
            if ((header.Flags & FrameFlags.Compression) != 0)
            {
                throw new System.NotImplementedException();
            }
            if ((header.Flags & FrameFlags.Encryption) != 0)
            {
                throw new System.NotImplementedException();
            }
            foreach (FrameCreator creator in frame_creators)
            {
                Frame frame = creator(data, position, header, version);
                if (frame != null)
                {
                    return(frame);
                }
            }
            if (header.FrameId == FrameType.TXXX)
            {
                return(new UserTextInformationFrame(data, position, header, version));
            }
            if (header.FrameId[0] == (byte)'T')
            {
                return(new TextInformationFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.UFID)
            {
                return(new UniqueFileIdentifierFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.MCDI)
            {
                return(new MusicCdIdentifierFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.USLT)
            {
                return(new UnsynchronisedLyricsFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.SYLT)
            {
                return(new SynchronisedLyricsFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.COMM)
            {
                return(new CommentsFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.RVA2)
            {
                return(new RelativeVolumeFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.APIC)
            {
                return(new AttachedPictureFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.GEOB)
            {
                return(new GeneralEncapsulatedObjectFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.PCNT)
            {
                return(new PlayCountFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.POPM)
            {
                return(new PopularimeterFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.USER)
            {
                return(new TermsOfUseFrame(data, position, header, version));
            }
            if (header.FrameId == FrameType.PRIV)
            {
                return(new PrivateFrame(data, position, header, version));
            }
            if (header.FrameId[0] == (byte)'W')
            {
                return(new UrlLinkFrame(data, position, header, version));
            }
            return(new UnknownFrame(data, position, header, version));
        }
Esempio n. 4
0
        /// <summary>
        ///    Creates a <see cref="Frame" /> object by reading it from
        ///    raw ID3v2 frame data.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing a raw ID3v2
        ///    frame.
        /// </param>
        /// <param name="offset">
        ///    A <see cref="int" /> value reference specifying at what
        ///    index in <paramref name="data" /> at which the frame
        ///    begins. After reading, it contains the offset of the next
        ///    frame to be read.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> value specifying the ID3v2 version
        ///    the frame in <paramref name="data"/> is encoded in.
        /// </param>
        /// <param name="alreadyUnsynched">
        ///    A <see cref="bool" /> value specifying whether the entire
        ///    tag has already been unsynchronized.
        /// </param>
        /// <returns>
        ///    A <see cref="Frame" /> object read from the data, or <see
        ///    langword="null" /> if none is found.
        /// </returns>
        /// <exception cref="System.NotImplementedException">
        ///    The frame contained in the raw data could not be
        ///    converted to ID3v2 or uses encryption or compression.
        /// </exception>
        public static Frame CreateFrame(ByteVector data,
                                        ref int offset, byte version, bool alreadyUnsynched)
        {
            int position = offset;

            FrameHeader header = new FrameHeader(data.Mid(position,
                                                          (int)FrameHeader.Size(version)), version);

            offset += (int)(header.FrameSize + FrameHeader.Size(
                                version));

            if (header.FrameId == null)
            {
                throw new System.NotImplementedException();
            }

            foreach (byte b in header.FrameId)
            {
                char c = (char)b;
                if ((c < 'A' || c > 'Z') &&
                    (c < '0' || c > '9'))
                {
                    return(null);
                }
            }

            if (alreadyUnsynched)
            {
                // Mark the frame as not Unsynchronozed because the entire
                // tag has already been Unsynchronized
                header.Flags &= ~FrameFlags.Unsynchronisation;
            }

            // Windows Media Player may create zero byte frames.
            // Just send them off as unknown and delete them.
            if (header.FrameSize == 0)
            {
                header.Flags |= FrameFlags.TagAlterPreservation;
                return(new UnknownFrame(data, position, header,
                                        version));
            }

            // TODO: Support Compression.
            if ((header.Flags & FrameFlags.Compression) != 0)
            {
                throw new System.NotImplementedException();
            }

            // TODO: Support Encryption.
            if ((header.Flags & FrameFlags.Encryption) != 0)
            {
                throw new System.NotImplementedException();
            }

            foreach (FrameCreator creator in frame_creators)
            {
                Frame frame = creator(data, position, header,
                                      version);

                if (frame != null)
                {
                    return(frame);
                }
            }

            // This is where things get necissarily nasty.  Here we
            // determine which Frame subclass (or if none is found
            // simply an Frame) based on the frame ID. Since there
            // are a lot of possibilities, that means a lot of if
            // blocks.

            // Text Identification (frames 4.2)
            if (header.FrameId == FrameType.TXXX)
            {
                return(new UserTextInformationFrame(data,
                                                    position, header, version));
            }

            if (header.FrameId [0] == (byte)'T')
            {
                return(new TextInformationFrame(data, position,
                                                header, version));
            }

            // Unique File Identifier (frames 4.1)
            if (header.FrameId == FrameType.UFID)
            {
                return(new UniqueFileIdentifierFrame(data,
                                                     position, header, version));
            }

            // Music CD Identifier (frames 4.5)
            if (header.FrameId == FrameType.MCDI)
            {
                return(new MusicCdIdentifierFrame(data,
                                                  position, header, version));
            }

            // Unsynchronized Lyrics (frames 4.8)
            if (header.FrameId == FrameType.USLT)
            {
                return(new UnsynchronisedLyricsFrame(data,
                                                     position, header, version));
            }

            // Synchronized Lyrics (frames 4.9)
            if (header.FrameId == FrameType.SYLT)
            {
                return(new SynchronisedLyricsFrame(data,
                                                   position, header, version));
            }

            // Comments (frames 4.10)
            if (header.FrameId == FrameType.COMM)
            {
                return(new CommentsFrame(data, position,
                                         header, version));
            }

            // Relative Volume Adjustment (frames 4.11)
            if (header.FrameId == FrameType.RVA2)
            {
                return(new RelativeVolumeFrame(data, position,
                                               header, version));
            }

            // Attached Picture (frames 4.14)
            if (header.FrameId == FrameType.APIC)
            {
                return(new AttachedPictureFrame(data, position,
                                                header, version));
            }

            // General Encapsulated Object (frames 4.15)
            if (header.FrameId == FrameType.GEOB)
            {
                return(new GeneralEncapsulatedObjectFrame(data,
                                                          position, header, version));
            }

            // Play Count (frames 4.16)
            if (header.FrameId == FrameType.PCNT)
            {
                return(new PlayCountFrame(data, position,
                                          header, version));
            }

            // Play Count (frames 4.17)
            if (header.FrameId == FrameType.POPM)
            {
                return(new PopularimeterFrame(data, position,
                                              header, version));
            }

            // Terms of Use (frames 4.22)
            if (header.FrameId == FrameType.USER)
            {
                return(new TermsOfUseFrame(data, position,
                                           header, version));
            }

            // Private (frames 4.27)
            if (header.FrameId == FrameType.PRIV)
            {
                return(new PrivateFrame(data, position, header,
                                        version));
            }

            // Url Link (frames 4.3.1)
            if (header.FrameId[0] == (byte)'W')
            {
                return(new UrlLinkFrame(data, position,
                                        header, version));
            }

            return(new UnknownFrame(data, position, header,
                                    version));
        }
Esempio n. 5
0
        /// <summary>
        ///    Extracts the field data from the raw data portion of an
        ///    ID3v2 frame.
        /// </summary>
        /// <param name="frameData">
        ///    A <see cref="ByteVector" /> object containing fraw frame
        ///    data.
        /// </param>
        /// <param name="offset">
        ///    A <see cref="int" /> value containing the index at which
        ///    the data is contained.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> value containing the ID3v2 version
        ///    of the data.
        /// </param>
        /// <returns>
        ///    A <see cref="ByteVector" /> object containing the
        ///    extracted field data.
        /// </returns>
        /// <remarks>
        ///    This method is necessary for extracting extra data
        ///    prepended to the frame such as the grouping ID.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="frameData" /> is <see langword="null" />.
        /// </exception>
        protected ByteVector FieldData(ByteVector frameData, int offset, byte version)
        {
            if (frameData == null)
            {
                throw new ArgumentNullException(nameof(frameData));
            }

            int data_offset = offset + (int)FrameHeader.Size(version);
            int data_length = (int)Size;

            if ((Flags & (FrameFlags.Compression |
                          FrameFlags.DataLengthIndicator)) != 0)
            {
                data_offset += 4;
                data_length -= 4;
            }

            if ((Flags & FrameFlags.GroupingIdentity) != 0)
            {
                if (frameData.Count >= data_offset)
                {
                    throw new CorruptFileException("Frame data incomplete.");
                }
                group_id = frameData[data_offset++];
                data_length--;
            }

            if ((Flags & FrameFlags.Encryption) != 0)
            {
                if (frameData.Count >= data_offset)
                {
                    throw new CorruptFileException("Frame data incomplete.");
                }
                encryption_id = frameData[data_offset++];
                data_length--;
            }

            data_length = Math.Min(data_length, frameData.Count - data_offset);
            if (data_length < 0)
            {
                throw new CorruptFileException("Frame size less than zero.");
            }

            ByteVector data = frameData.Mid(data_offset, data_length);

            if ((Flags & FrameFlags.Unsynchronisation) != 0)
            {
                int before_length = data.Count;
                SynchData.ResynchByteVector(data);
                data_length -= (data.Count - before_length);
            }

            // FIXME: Implement encryption.
            if ((Flags & FrameFlags.Encryption) != 0)
            {
                throw new NotImplementedException();
            }

            // FIXME: Implement compression.
            if ((Flags & FrameFlags.Compression) != 0)
            {
                throw new NotImplementedException();
            }

            /*
             * if(d->header->compression()) {
             *      ByteVector data(frameDataLength);
             *      uLongf uLongTmp = frameDataLength;
             *      ::uncompress((Bytef *) data.data(),
             *      (uLongf *) &uLongTmp,
             *      (Bytef *) frameData.data() + frameDataOffset,
             *      size());
             *      return data;
             * }
             */

            return(data);
        }
Esempio n. 6
0
        /// <summary>
        ///    Creates a <see cref="Frame" /> object by reading it from
        ///    raw ID3v2 frame data.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing a raw ID3v2
        ///    frame.
        /// </param>
        /// <param name="file">
        ///    A <see cref="File"/> object containing
        ///    abstraction of the file to read.
        ///    Ignored if <paramref name="data"/> is not null.
        /// </param>
        /// <param name="offset">
        ///    A <see cref="int" /> value reference specifying at what
        ///    index in <paramref name="file" />, or in
        ///    <paramref name="data" /> if not null,
        ///    at which the frame begins. After reading, it contains
        ///    the offset of the next frame to be read.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> value specifying the ID3v2 version
        ///    the frame in <paramref name="data"/> is encoded in.
        /// </param>
        /// <param name="alreadyUnsynched">
        ///    A <see cref="bool" /> value specifying whether the entire
        ///    tag has already been unsynchronized.
        /// </param>
        /// <returns>
        ///    A <see cref="Frame" /> object read from the data, or <see
        ///    langword="null" /> if none is found.
        /// </returns>
        /// <exception cref="System.NotImplementedException">
        ///    The frame contained in the raw data could not be
        ///    converted to ID3v2 or uses encryption or compression.
        /// </exception>
        public static Frame CreateFrame(ByteVector data, File file, ref int offset, byte version, bool alreadyUnsynched)
        {
            int position = 0;

            if (data == null)
            {
                file.Seek(offset);
                data = file.ReadBlock((int)FrameHeader.Size(version));
            }
            else
            {
                file     = null;
                position = offset;
            }

            // If the next data is position is 0, assume
            // that we've hit the padding portion of the
            // frame data.

            if (data[position] == 0)
            {
                return(null);
            }

            FrameHeader header = new FrameHeader(data.Mid(position, (int)FrameHeader.Size(version)), version);

            int fileposition = offset + (int)FrameHeader.Size(version);

            offset += (int)(header.FrameSize + FrameHeader.Size(version));

            if (header.FrameId == null)
            {
                throw new System.NotImplementedException();
            }

            foreach (byte b in header.FrameId)
            {
                char c = (char)b;
                if ((c < 'A' || c > 'Z') &&
                    (c < '0' || c > '9'))
                {
                    return(null);
                }
            }

            if (alreadyUnsynched)
            {
                // Mark the frame as not Unsynchronozed because the entire
                // tag has already been Unsynchronized
                header.Flags &= ~FrameFlags.Unsynchronisation;
            }

            // Windows Media Player may create zero byte frames.
            // Just send them off as unknown and delete them.
            if (header.FrameSize == 0)
            {
                header.Flags |= FrameFlags.TagAlterPreservation;
                return(new UnknownFrame(data, position, header, version));
            }

            // TODO: Support Compression.
            if ((header.Flags & FrameFlags.Compression) != 0)
            {
                throw new System.NotImplementedException();
            }

            // TODO: Support Encryption.
            if ((header.Flags & FrameFlags.Encryption) != 0)
            {
                throw new System.NotImplementedException();
            }

            foreach (FrameCreator creator in frame_creators)
            {
                Frame frame = creator(data, position, header, version);

                if (frame != null)
                {
                    return(frame);
                }
            }

            // This is where things get necessarily nasty.  Here we
            // determine which Frame subclass (or if none is found
            // simply an Frame) based on the frame ID. Since there
            // are a lot of possibilities, that means a lot of if
            // blocks.


            // Lazy objects loading handling

            if (file != null)
            {
                // Attached Picture (frames 4.14)
                // General Encapsulated Object (frames 4.15)
                if (header.FrameId == FrameType.APIC ||
                    header.FrameId == FrameType.GEOB)
                {
                    return(new AttachmentFrame(file.FileAbstraction, fileposition, offset - fileposition, header, version));
                }

                // Read remaining part of the frame for the non lazy Frames
                file.Seek(fileposition);
                data.Add(file.ReadBlock(offset - fileposition));
            }


            // Text Identification (frames 4.2)
            if (header.FrameId == FrameType.TXXX)
            {
                return(new UserTextInformationFrame(data, position, header, version));
            }

            if (header.FrameId[0] == (byte)'T')
            {
                return(new TextInformationFrame(data, position, header, version));
            }

            // Involved People List (frames 4.4 in 2.3. in 2.4 this is a TIPL frame)
            if (header.FrameId == FrameType.IPLS)
            {
                return(new TextInformationFrame(data, position,
                                                header, version));
            }

            // Unique File Identifier (frames 4.1)
            if (header.FrameId == FrameType.UFID)
            {
                return(new UniqueFileIdentifierFrame(data, position, header, version));
            }

            // Music CD Identifier (frames 4.5)
            if (header.FrameId == FrameType.MCDI)
            {
                return(new MusicCdIdentifierFrame(data, position, header, version));
            }

            // Unsynchronized Lyrics (frames 4.8)
            if (header.FrameId == FrameType.USLT)
            {
                return(new UnsynchronisedLyricsFrame(data, position, header, version));
            }

            // Synchronized Lyrics (frames 4.9)
            if (header.FrameId == FrameType.SYLT)
            {
                return(new SynchronisedLyricsFrame(data, position, header, version));
            }

            // Comments (frames 4.10)
            if (header.FrameId == FrameType.COMM)
            {
                return(new CommentsFrame(data, position, header, version));
            }

            // Relative Volume Adjustment (frames 4.11)
            if (header.FrameId == FrameType.RVA2)
            {
                return(new RelativeVolumeFrame(data, position, header, version));
            }

            // Attached Picture (frames 4.14)
            // General Encapsulated Object (frames 4.15)
            if (header.FrameId == FrameType.APIC ||
                header.FrameId == FrameType.GEOB)
            {
                return(new AttachmentFrame(data, position, header, version));
            }

            // Play Count (frames 4.16)
            if (header.FrameId == FrameType.PCNT)
            {
                return(new PlayCountFrame(data, position, header, version));
            }

            // Play Count (frames 4.17)
            if (header.FrameId == FrameType.POPM)
            {
                return(new PopularimeterFrame(data, position, header, version));
            }

            // Terms of Use (frames 4.22)
            if (header.FrameId == FrameType.USER)
            {
                return(new TermsOfUseFrame(data, position, header, version));
            }

            // Private (frames 4.27)
            if (header.FrameId == FrameType.PRIV)
            {
                return(new PrivateFrame(data, position, header, version));
            }

            // Url Link (frames 4.3.1)
            if (header.FrameId[0] == (byte)'W')
            {
                return(new UrlLinkFrame(data, position, header, version));
            }

            // Event timing codes (frames 4.6)
            if (header.FrameId == FrameType.ETCO)
            {
                return(new EventTimeCodesFrame(data, position, header, version));
            }

            return(new UnknownFrame(data, position, header, version));
        }
Esempio n. 7
0
        protected ByteVector FieldData(ByteVector frameData, int offset, byte version)
        {
            if (frameData == null)
            {
                throw new ArgumentNullException("frameData");
            }

            int data_offset = offset + (int)FrameHeader.Size(version);
            int data_length = (int)Size;

            /*int uncompressed_data_length;*/

            if ((Flags & (FrameFlags.Compression | FrameFlags.DataLengthIndicator)) != 0)
            {
                /*uncompressed_data_length = (int) frame_data.Mid (data_offset, 4).ToUInt () + 4;*/
                data_offset += 4;
                data_offset -= 4;
            }

            if ((Flags & FrameFlags.GroupingIdentity) != 0)
            {
                group_id = frameData [data_offset++];
                data_length--;
            }

            if ((Flags & FrameFlags.Encryption) != 0)
            {
                encryption_id = frameData [data_offset++];
                data_length--;
            }

            if (data_length > frameData.Count - data_offset)
            {
                throw new CorruptFileException("Frame size exceeds bounds.");
            }
            if (data_length < 0)
            {
                throw new CorruptFileException("Frame size less than zero.");
            }

            ByteVector data = frameData.Mid(data_offset, data_length);

            if ((Flags & FrameFlags.Unsychronisation) != 0)
            {
                SynchData.ResynchByteVector(data);
            }

            // FIXME: Implement encryption.
            if ((Flags & FrameFlags.Encryption) != 0)
            {
                throw new NotImplementedException();
            }

            // FIXME: Implement compression.
            if ((Flags & FrameFlags.Compression) != 0)
            {
                throw new NotImplementedException();
            }

            /*
             * if(d->header->compression()) {
             *    ByteVector data(frameDataLength);
             *    uLongf uLongTmp = frameDataLength;
             *    ::uncompress((Bytef *) data.data(),
             *                (uLongf *) &uLongTmp,
             *                (Bytef *) frameData.data() + frameDataOffset,
             *                size());
             *    return data;
             * }
             */

            return(data);
        }
Esempio n. 8
0
        protected void Parse(ByteVector data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            bool fullTagUnsynch = (header.MajorVersion < 4) && ((header.Flags & HeaderFlags.Unsynchronisation) != 0);

            if (fullTagUnsynch)
            {
                SynchData.ResynchByteVector(data);
            }
            int frame_data_position = 0;
            int frame_data_length   = data.Count;

            if ((header.Flags & HeaderFlags.ExtendedHeader) != 0)
            {
                extended_header = new ExtendedHeader(data, header.MajorVersion);
                if (extended_header.Size <= data.Count)
                {
                    frame_data_position += (int)extended_header.Size;
                    frame_data_length   -= (int)extended_header.Size;
                }
            }
            TextInformationFrame tdrc = null;
            TextInformationFrame tyer = null;
            TextInformationFrame tdat = null;
            TextInformationFrame time = null;

            while (frame_data_position < frame_data_length - FrameHeader.Size(header.MajorVersion))
            {
                if (data[frame_data_position] == 0)
                {
                    break;
                }
                Frame frame = null;
                try
                {
                    frame = FrameFactory.CreateFrame(data, ref frame_data_position, header.MajorVersion, fullTagUnsynch);
                }
                catch (NotImplementedException)
                {
                    continue;
                }
                catch (CorruptFileException)
                {
                    continue;
                }
                if (frame == null)
                {
                    break;
                }
                if (frame.Size == 0)
                {
                    continue;
                }
                AddFrame(frame);
                if (header.MajorVersion == 4)
                {
                    continue;
                }
                if (tdrc == null && frame.FrameId.Equals(FrameType.TDRC))
                {
                    tdrc = frame as TextInformationFrame;
                }
                else if (tyer == null && frame.FrameId.Equals(FrameType.TYER))
                {
                    tyer = frame as TextInformationFrame;
                }
                else if (tdat == null && frame.FrameId.Equals(FrameType.TDAT))
                {
                    tdat = frame as TextInformationFrame;
                }
                else if (time == null && frame.FrameId.Equals(FrameType.TIME))
                {
                    time = frame as TextInformationFrame;
                }
            }
            if (tdrc == null || tdat == null || tdrc.ToString().Length > 4)
            {
                return;
            }
            string year = tdrc.ToString();

            if (year.Length != 4)
            {
                return;
            }
            StringBuilder tdrc_text = new StringBuilder();

            tdrc_text.Append(year);
            if (tdat != null)
            {
                string tdat_text = tdat.ToString();
                if (tdat_text.Length == 4)
                {
                    tdrc_text.Append("-").Append(tdat_text, 0, 2).Append("-").Append(tdat_text, 2, 2);
                    if (time != null)
                    {
                        string time_text = time.ToString();
                        if (time_text.Length == 4)
                        {
                            tdrc_text.Append("T").Append(time_text, 0, 2).Append(":").Append(time_text, 2, 2);
                        }
                        RemoveFrames(FrameType.TIME);
                    }
                }
                RemoveFrames(FrameType.TDAT);
            }
            tdrc.Text = new string[]
            {
                tdrc_text.ToString()
            };
        }