Beispiel #1
0
        public void ReadFrom(TagReadingInfo tagReadingInfo, Stream stream)
        {
            int             num1     = Utils.ReadInt32(stream);
            ID3v2TagVersion version1 = tagReadingInfo.TagVersion;

            if (num1 >= 0x41000000)
            {
                string text1 = string.Format("FrameID found when expected extended header at position {0}", stream.Position - 4);
                Trace.WriteLine(text1);
                stream.Seek((long)(-4), SeekOrigin.Current);
                this.m_IsCRCDataPresent = false;
                this.m_PaddingSize      = 0;
                this.m_TotalFrameCRC    = 0;
            }
            else
            {
                byte num2 = Utils.ReadByte(stream);
                Utils.ReadByte(stream);
                this.m_IsCRCDataPresent = (num2 & 0x80) == 0x80;
                this.m_PaddingSize      = Utils.ReadInt32(stream);
                if (this.m_IsCRCDataPresent)
                {
                    this.m_TotalFrameCRC = Utils.ReadInt32(stream);
                }
                else
                {
                    this.m_TotalFrameCRC = 0;
                }
            }
        }
Beispiel #2
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 > 0)
     {
         this.UserEmail = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
         if (num1 > 0)
         {
             this.Rating = Utils.ReadByte(stream, ref num1);
             if (num1 > 0)
             {
                 byte[] buffer1 = Utils.Read(stream, num1);
                 this.PlayCount = Utils.ConvertToInt64(buffer1);
             }
             else
             {
                 this.PlayCount = 0;
             }
         }
         else
         {
             this.Rating = 0;
             this.PlayCount = 0;
         }
     }
     else
     {
         this.UserEmail = null;
         this.Rating = 0;
         this.PlayCount = 0;
     }
 }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 >= 4)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream, ref num1);
         this.MimeType = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
         if (num1 > 0)
         {
             this.FileName = Utils.ReadString(this.TextEncoding, stream, ref num1);
             if (num1 > 0)
             {
                 this.Description = Utils.ReadString(this.TextEncoding, stream, ref num1);
                 if (num1 > 0)
                 {
                     this.EncapsulatedObject = Utils.Read(stream, num1);
                     num1 = 0;
                 }
             }
         }
     }
     if (num1 > 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
 public void ReadFrom(TagReadingInfo tagReadingInfo, Stream stream)
 {
     int num1 = Utils.ReadInt32(stream);
     ID3v2TagVersion version1 = tagReadingInfo.TagVersion;
     if (num1 >= 0x41000000)
     {
         string text1 = string.Format("FrameID found when expected extended header at position {0}", stream.Position - 4);
         Trace.WriteLine(text1);
         stream.Seek((long) (-4), SeekOrigin.Current);
         this.m_IsCRCDataPresent = false;
         this.m_PaddingSize = 0;
         this.m_TotalFrameCRC = 0;
     }
     else
     {
         byte num2 = Utils.ReadByte(stream);
         Utils.ReadByte(stream);
         this.m_IsCRCDataPresent = (num2 & 0x80) == 0x80;
         this.m_PaddingSize = Utils.ReadInt32(stream);
         if (this.m_IsCRCDataPresent)
         {
             this.m_TotalFrameCRC = Utils.ReadInt32(stream);
         }
         else
         {
             this.m_TotalFrameCRC = 0;
         }
     }
 }
Beispiel #5
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 >= 1)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream, ref num1);
         if (num1 >= 3)
         {
             this.LanguageCode = Utils.ReadString(EncodingType.ISO88591, stream, 3);
             num1 -= 3;
             if (num1 > 0)
             {
                 this.Value = Utils.ReadString(this.TextEncoding, stream, num1);
                 num1 = 0;
             }
         }
         else
         {
             this.LanguageCode = "eng";
         }
     }
     else
     {
         this.TextEncoding = EncodingType.ISO88591;
         this.LanguageCode = "eng";
     }
     if (num1 > 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 != 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
     throw new NotImplementedException();
 }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     if (this.m_FrameHeader.FrameSizeExcludingAdditions > 0)
     {
         this.TOC = Utils.Read(stream, this.m_FrameHeader.FrameSizeExcludingAdditions);
     }
     else
     {
         this.TOC = null;
     }
 }
Beispiel #8
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     long num2 = 0;
     while (num1 > 0)
     {
         num2 = num2 << 8;
         num2 += Utils.ReadByte(stream, ref num1);
     }
     this.Value = new Nullable<long>(num2);
 }
Beispiel #9
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 > 0)
     {
         this.OwnerIdentifier = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
         if (num1 > 0)
         {
             this.PrivateData = Utils.Read(stream, num1);
         }
     }
 }
Beispiel #10
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     if (this.m_FrameHeader.FrameSizeExcludingAdditions >= 1)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream);
         this.Value = Utils.ReadString(this.m_TextEncoding, stream, this.m_FrameHeader.FrameSizeExcludingAdditions - 1);
     }
     else
     {
         this.TextEncoding = EncodingType.ISO88591;
         this.Value = "";
     }
 }
Beispiel #11
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     if (this.m_FrameHeader.FrameSizeExcludingAdditions > 0)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream);
         int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions - 1;
         this.Description = Utils.ReadString(this.TextEncoding, stream, ref num1);
         this.Value = Utils.ReadString(EncodingType.ISO88591, stream, num1);
     }
     else
     {
         this.Description = "";
         this.Value = "";
     }
 }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     int num2 = (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v22) ? 3 : 4;
     if (num1 > num2)
     {
         this.FrameIdentifier = Utils.ReadString(EncodingType.ISO88591, stream, num2);
         num1 -= num2;
         this.Url = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
         this.AdditionalData = Utils.Read(stream, num1);
     }
     else
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     if (this.m_FrameHeader.FrameSizeExcludingAdditions >= 4)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream);
         this.LanguageCode = Utils.ReadString(EncodingType.ISO88591, stream, 3);
         int num1 = (this.m_FrameHeader.FrameSizeExcludingAdditions - 1) - 3;
         this.ContentDescriptor = Utils.ReadString(this.TextEncoding, stream, ref num1);
         this.Text = Utils.ReadString(this.m_TextEncoding, stream, num1);
     }
     else
     {
         string text1 = string.Format("Under-sized ({0} bytes) unsynchronized text frame at position {1}", this.m_FrameHeader.FrameSizeExcludingAdditions, stream.Position);
         Trace.WriteLine(text1);
         this.LanguageCode = "eng";
         this.ContentDescriptor = "";
         this.Text = "";
     }
 }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     this.m_InvolvedPersons.Clear();
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 > 0)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream, ref num1);
         while (num1 > 0)
         {
             string text1 = Utils.ReadString(this.TextEncoding, stream, ref num1);
             string text2 = Utils.ReadString(this.TextEncoding, stream, ref num1);
             if (!string.IsNullOrEmpty(text1) || !string.IsNullOrEmpty(text2))
             {
                 IInvolvedPerson person1 = this.m_InvolvedPersons.AddNew();
                 person1.Involvement = text1;
                 person1.Name = text2;
             }
         }
     }
 }
Beispiel #15
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 > 0)
     {
         this.OwnerIdentifier = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
         if (num1 >= 4)
         {
             this.PreviewStart = Utils.ReadInt16(stream, ref num1);
             this.PreviewLength = Utils.ReadInt16(stream, ref num1);
             if (num1 > 0)
             {
                 this.EncryptionInfo = Utils.Read(stream, num1);
                 num1 = 0;
             }
             else
             {
                 this.EncryptionInfo = null;
             }
         }
         else
         {
             this.PreviewStart = 0;
             this.PreviewLength = 0;
             this.EncryptionInfo = null;
         }
     }
     else
     {
         this.OwnerIdentifier = null;
         this.PreviewStart = 0;
         this.PreviewLength = 0;
         this.EncryptionInfo = null;
     }
     if (num1 != 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
Beispiel #16
0
        public void ReadFrom(TagReadingInfo tagReadingInfo, Stream stream)
        {
            //Guard.ArgumentNotNull(stream, "stream");

            int size = stream.ReadInt32();

            // Test for a possible FrameID (0x41 = 'A')
            // Most likely the extended header bit is set but
            // there is no extended header.  Set the stream back
            // to its original position and return.
            if (size >= 0x41000000)
            {
                string msg = string.Format("FrameID found when expected extended header at position {0}", stream.Position - 4);
                Trace.WriteLine(msg);

                stream.Seek(-4, SeekOrigin.Current);
                _isCRCDataPresent = false;
                _paddingSize      = 0;
                _totalFrameCRC    = 0;
                return;
            }

            byte flags1 = stream.Read1();
            byte flags2 = stream.Read1();

            _isCRCDataPresent = ((flags1 & 0x80) == 0x80);

            _paddingSize = stream.ReadInt32();

            if (_isCRCDataPresent)
            {
                _totalFrameCRC = (uint)stream.ReadInt32();
            }
            else
            {
                _totalFrameCRC = 0;
            }
        }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.Reset();
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 > 0)
     {
         this.OwnerIdentifier = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
         if (num1 > 0)
         {
             this.MethodSymbol = Utils.ReadByte(stream, ref num1);
             if (num1 > 0)
             {
                 this.EncryptionData = Utils.Read(stream, num1);
                 num1 = 0;
             }
         }
     }
     if (num1 != 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
Beispiel #18
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_LanguageItems.Clear();
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 >= 4)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream, ref num1);
         string text1 = Utils.ReadString(this.TextEncoding, stream, ref num1);
         if (text1.Length != 3)
         {
             if ((text1.ToLower() == "english") || (text1.ToLower() == "en"))
             {
                 this.Items.AddNew().LanguageCode = "eng";
             }
             else
             {
                 foreach (KeyValuePair<string, string> pair1 in LanguageHelper.Languages)
                 {
                     if (pair1.Value.ToLower() == text1.ToLower())
                     {
                         this.Items.AddNew().LanguageCode = pair1.Key;
                         break;
                     }
                 }
             }
         }
         else
         {
             this.Items.AddNew().LanguageCode = text1;
         }
     }
     if (num1 > 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
        public void ReadFrom(TagReadingInfo tagReadingInfo, Stream stream)
        {
            //Guard.ArgumentNotNull(stream, "stream");

            int size = stream.ReadInt32();

            // Test for a possible FrameID (0x41 = 'A')
            // Most likely the extended header bit is set but
            // there is no extended header.  Set the stream back
            // to its original position and return.
            if (size >= 0x41000000)
            {
                string msg = string.Format("FrameID found when expected extended header at position {0}", stream.Position - 4);
                Trace.WriteLine(msg);

                stream.Seek(-4, SeekOrigin.Current);
                _isCRCDataPresent = false;
                _paddingSize = 0;
                _totalFrameCRC = 0;
                return;
            }

            byte flags1 = stream.Read1();
            byte flags2 = stream.Read1();

            _isCRCDataPresent = ((flags1 & 0x80) == 0x80);

            _paddingSize = stream.ReadInt32();

            if (_isCRCDataPresent)
            {
                _totalFrameCRC = (uint)stream.ReadInt32();
            }
            else
            {
                _totalFrameCRC = 0;
            }
        }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FractionAtIndex.Clear();
     throw new NotImplementedException();
 }
Beispiel #21
0
 public ID3v2ExtendedHeader(TagReadingInfo tagReadingInfo, Stream stream)
 {
     ReadFrom(tagReadingInfo, stream);
 }
Beispiel #22
0
 public void ReadStream(Stream stream)
 {
     if (Utils.ReadString(EncodingType.ISO88591, stream, 3) == "ID3")
     {
         int num2;
         int num3;
         this.m_ID3v2Header = new ID3v2Header(stream, false);
         TagReadingInfo info1 = new TagReadingInfo(this.m_ID3v2Header.TagVersion);
         if (this.m_ID3v2Header.UsesUnsynchronization)
         {
             info1.TagVersionOptions = TagVersionOptions.Unsynchronized;
         }
         else
         {
             info1.TagVersionOptions = TagVersionOptions.None;
         }
         if (this.m_ID3v2Header.HasExtendedHeader)
         {
             this.m_ID3v2ExtendedHeader = new ID3v2ExtendedHeader(info1, stream);
         }
         int num1 = (info1.TagVersion == ID3v2TagVersion.ID3v22) ? 3 : 4;
         if (this.m_ID3v2Header.TagVersion != ID3v2TagVersion.ID3v24)
         {
             if (this.m_ID3v2Header.TagVersion == ID3v2TagVersion.ID3v22)
             {
                 bool flag4 = true;
                 num2 = 0;
                 num3 = (this.m_ID3v2Header.TagSize - this.m_ID3v2ExtendedHeader.SizeIncludingSizeBytes) - num1;
                 long num8 = stream.Position;
                 Utils.Read(stream, num1);
                 UnknownFrame frame1 = new UnknownFrame(null, info1, stream);
                 num2 += frame1.FrameHeader.FrameSizeTotal;
                 if (num2 < num3)
                 {
                     byte[] buffer2 = Utils.Read(stream, num1);
                     if (((buffer2[0] < 0x30) || (buffer2[0] > 90)) && (((buffer2[1] >= 0x30) && (buffer2[1] <= 90)) && ((buffer2[2] >= 0x30) && (buffer2[2] <= 90))))
                     {
                         Trace.WriteLine("ID3v2.2 frame size off by 1 byte");
                         flag4 = false;
                     }
                 }
                 stream.Position = num8;
                 if (!flag4)
                 {
                     info1.TagVersionOptions |= TagVersionOptions.AddOneByteToSize;
                 }
             }
         }
         else
         {
             bool flag1 = true;
             num2 = 0;
             num3 = (this.m_ID3v2Header.TagSize - this.m_ID3v2ExtendedHeader.SizeIncludingSizeBytes) - num1;
             long num4 = stream.Position;
             while (num2 < num3)
             {
                 byte[] buffer1 = Utils.Read(stream, num1);
                 if ((((buffer1[0] < 0x30) || (buffer1[0] > 90)) || ((buffer1[1] < 0x30) || (buffer1[1] > 90))) || (((buffer1[2] < 0x30) || (buffer1[2] > 90)) || ((buffer1[3] < 0x30) || (buffer1[3] > 90))))
                 {
                     if ((buffer1[0] != 0) && (buffer1[0] != 0xff))
                     {
                     }
                     break;
                 }
                 int num5 = Utils.ReadInt32(stream);
                 if (num5 > 0xff)
                 {
                     if ((num5 & 0x80) == 0x80)
                     {
                         flag1 = false;
                         break;
                     }
                     if ((num5 & 0x8000) == 0x8000)
                     {
                         flag1 = false;
                         break;
                     }
                     if ((num5 & 0x800000) == 0x800000)
                     {
                         flag1 = false;
                         break;
                     }
                     if (((num2 + num5) + 10) == this.m_ID3v2Header.TagSize)
                     {
                         flag1 = false;
                         break;
                     }
                     stream.Seek((long)(-4), SeekOrigin.Current);
                     int  num6  = Utils.ReadInt32SyncSafe(stream);
                     long num7  = stream.Position;
                     bool flag2 = true;
                     bool flag3 = true;
                     if (((num7 + num5) + 2) >= num3)
                     {
                         flag1 = true;
                         break;
                     }
                     stream.Seek((num7 + num5) + 2, SeekOrigin.Begin);
                     buffer1 = Utils.Read(stream, num1);
                     if ((((buffer1[0] < 0x30) || (buffer1[0] > 90)) || ((buffer1[1] < 0x30) || (buffer1[1] > 90))) || (((buffer1[2] < 0x30) || (buffer1[2] > 90)) || ((buffer1[3] < 0x30) || (buffer1[3] > 90))))
                     {
                         flag3 = false;
                     }
                     stream.Seek((num7 + num6) + 2, SeekOrigin.Begin);
                     buffer1 = Utils.Read(stream, num1);
                     if ((((buffer1[0] < 0x30) || (buffer1[0] > 90)) || ((buffer1[1] < 0x30) || (buffer1[1] > 90))) || (((buffer1[2] < 0x30) || (buffer1[2] > 90)) || ((buffer1[3] < 0x30) || (buffer1[3] > 90))))
                     {
                         flag2 = false;
                     }
                     if (flag3 != flag2)
                     {
                         flag1 = flag2;
                     }
                     break;
                 }
                 stream.Seek((long)(num5 + 2), SeekOrigin.Current);
                 num2 += num5 + 10;
             }
             stream.Position = num4;
             if (!flag1)
             {
                 info1.TagVersionOptions |= TagVersionOptions.UseNonSyncSafeFrameSizeID3v24;
             }
         }
         num3 = (this.m_ID3v2Header.TagSize - this.m_ID3v2ExtendedHeader.SizeIncludingSizeBytes) - num1;
         base.Read(stream, this.m_ID3v2Header.TagVersion, info1, num3, num1);
     }
 }
Beispiel #23
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 public abstract void Read(TagReadingInfo tagReadingInfo, Stream stream);
 public ID3v2ExtendedHeader(TagReadingInfo tagReadingInfo, Stream stream)
 {
     ReadFrom(tagReadingInfo, stream);
 }
Beispiel #26
0
        public void Read(TagReadingInfo tagReadingInfo, ref Stream stream)
        {
            this.m_TagVersion = tagReadingInfo.TagVersion;
            bool flag1 = (tagReadingInfo.TagVersionOptions & TagVersionOptions.Unsynchronized) == TagVersionOptions.Unsynchronized;

            if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v23)
            {
                if (!flag1)
                {
                    this.m_FrameSize = Utils.ReadInt32(stream);
                }
                else
                {
                    this.m_FrameSize = Utils.ReadInt32Unsynchronized(stream);
                }
                this.m_FrameSizeExcludingAdditions = this.m_FrameSize;
                byte num1 = Utils.ReadByte(stream);
                byte num2 = Utils.ReadByte(stream);
                this.IsTagAlterPreservation  = (num1 & 0x80) == 0x80;
                this.IsFileAlterPreservation = (num1 & 0x40) == 0x40;
                this.IsReadOnly   = (num1 & 0x20) == 0x20;
                this.IsCompressed = (num2 & 0x80) == 0x80;
                bool flag2 = (num2 & 0x40) == 0x40;
                bool flag3 = (num2 & 0x20) == 0x20;
                if (this.IsCompressed)
                {
                    this.DecompressedSize = Utils.ReadInt32(stream);
                    this.m_FrameSizeExcludingAdditions -= 4;
                }
                else
                {
                    this.DecompressedSize = 0;
                }
                if (flag2)
                {
                    this.EncryptionMethod = new Nullable <byte>(Utils.ReadByte(stream));
                    this.m_FrameSizeExcludingAdditions--;
                }
                else
                {
                    this.EncryptionMethod = new Nullable <byte>();
                }
                if (flag3)
                {
                    this.GroupingIdentity = new Nullable <byte>(Utils.ReadByte(stream));
                    this.m_FrameSizeExcludingAdditions--;
                }
                else
                {
                    this.GroupingIdentity = new Nullable <byte>();
                }
                if (flag1)
                {
                    stream = Utils.ReadUnsynchronizedStream(stream, this.m_FrameSize);
                }
            }
            else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v22)
            {
                if (!flag1)
                {
                    this.m_FrameSize = Utils.ReadInt24(stream);
                }
                else
                {
                    this.m_FrameSize = Utils.ReadInt24Unsynchronized(stream);
                }
                if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.AddOneByteToSize) == TagVersionOptions.AddOneByteToSize)
                {
                    this.m_FrameSize++;
                }
                this.m_FrameSizeExcludingAdditions = this.m_FrameSize;
                this.IsTagAlterPreservation        = false;
                this.IsFileAlterPreservation       = false;
                this.IsReadOnly       = false;
                this.IsCompressed     = false;
                this.DecompressedSize = 0;
                this.EncryptionMethod = new Nullable <byte>();
                this.GroupingIdentity = new Nullable <byte>();
                if (flag1)
                {
                    stream = Utils.ReadUnsynchronizedStream(stream, this.m_FrameSize);
                }
            }
            else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v24)
            {
                if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.UseNonSyncSafeFrameSizeID3v24) == TagVersionOptions.UseNonSyncSafeFrameSizeID3v24)
                {
                    this.m_FrameSize = Utils.ReadInt32(stream);
                }
                else
                {
                    this.m_FrameSize = Utils.ReadInt32SyncSafe(stream);
                }
                this.m_FrameSizeExcludingAdditions = this.m_FrameSize;
                Utils.ReadByte(stream);
                Utils.ReadByte(stream);
            }
            if (this.IsCompressed)
            {
                stream                = Utils.DecompressFrame(stream, this.FrameSizeExcludingAdditions);
                this.IsCompressed     = false;
                this.DecompressedSize = 0;
                this.m_FrameSizeExcludingAdditions = (int)stream.Length;
            }
        }
Beispiel #27
0
        internal void Read(Stream stream, ID3v2TagVersion tagVersion, TagReadingInfo tagReadingInfo, int readUntil, int frameIDSize)
        {
            Dictionary<string, IBindingList> multipleOccurrenceFrames = GetMultipleOccurrenceFrames(tagVersion);
            Dictionary<string, IFrame> singleOccurrenceFrames = GetSingleOccurrenceFrames(tagVersion);

            int bytesRead = 0;
            while (bytesRead < readUntil)
            {
                byte[] frameIDBytes = stream.Read(frameIDSize);

                // If character is not a letter or number, padding reached, audio began,
                // or otherwise the frame is not readable
                if (frameIDSize == 4)
                {
                    if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A ||
                        frameIDBytes[1] < 0x30 || frameIDBytes[1] > 0x5A ||
                        frameIDBytes[2] < 0x30 || frameIDBytes[2] > 0x5A ||
                        frameIDBytes[3] < 0x30 || frameIDBytes[3] > 0x5A)
                    {
                        // TODO: Try to keep reading and look for a valid frame
                        if (frameIDBytes[0] != 0 && frameIDBytes[0] != 0xFF)
                        {
                            string msg = string.Format("Out of range FrameID - 0x{0:X}|0x{1:X}|0x{2:X}|0x{3:X}",
                                frameIDBytes[0], frameIDBytes[1], frameIDBytes[2], frameIDBytes[3]);
                            if (ByteUtils.ISO88591GetString(frameIDBytes) != "MP3e")
                            {
                                string tmpBadFrameID = ByteUtils.ISO88591GetString(frameIDBytes).TrimEnd('\0');
                                Trace.WriteLine(msg + " - " + tmpBadFrameID);
                            }
                        }

                        break;
                    }
                }
                else if (frameIDSize == 3)
                {
                    if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A ||
                        frameIDBytes[1] < 0x30 || frameIDBytes[1] > 0x5A ||
                        frameIDBytes[2] < 0x30 || frameIDBytes[2] > 0x5A)
                    {
                        // TODO: Try to keep reading and look for a valid frame
                        if (frameIDBytes[0] != 0 && frameIDBytes[0] != 0xFF)
                        {
                            string msg = string.Format("Out of range FrameID - 0x{0:X}|0x{1:X}|0x{2:X}",
                                frameIDBytes[0], frameIDBytes[1], frameIDBytes[2]);
                            Trace.WriteLine(msg);
                            Trace.WriteLine(ByteUtils.ISO88591GetString(frameIDBytes));
                        }

                        break;
                    }
                }

                string frameID = ByteUtils.ISO88591GetString(frameIDBytes);

                // TODO: Take out
                //Console.WriteLine(tmpFrameID); // TODO: take out
                /*
                    COMM Frames:
                    SoundJam_CDDB_TrackNumber
                    SoundJam_CDDB_1
                    iTunNORM
                    iTunSMPB
                    iTunes_CDDB_IDs
                    iTunes_CDDB_1
                    iTunes_CDDB_TrackNumber
                 */

                IFrame frame;
                do
                {
                    IBindingList bindingList;
                    if (singleOccurrenceFrames.TryGetValue(frameID, out frame))
                    {
                        frame.Read(tagReadingInfo, stream);
                        bytesRead += frame.FrameHeader.FrameSizeTotal;
                        //m_ReadFrames.Add(tmpFrame);
                    }
                    else if (multipleOccurrenceFrames.TryGetValue(frameID, out bindingList))
                    {
                        frame = (IFrame)bindingList.AddNew();
                        frame.Read(tagReadingInfo, stream);
                        //m_ReadFrames.Add(tmpFrame);
                        bytesRead += frame.FrameHeader.FrameSizeTotal;
                    }
                    else
                    {
                        if (tagVersion == ID3v2TagVersion.ID3v24)
                        {
                            string newFrameID;
                            if (_id3v24FrameAliases.TryGetValue(frameID, out newFrameID))
                                frameID = newFrameID;
                            else
                                break;
                        }
                        else if (tagVersion == ID3v2TagVersion.ID3v23)
                        {
                            string newFrameID;
                            if (_id3v23FrameAliases.TryGetValue(frameID, out newFrameID))
                                frameID = newFrameID;
                            else
                                break;
                        }
                        else
                        {
                            break;
                        }
                    }
                } while (frame == null);

                // Frame is unknown
                if (frame == null)
                {
                    if (frameID != "NCON" &&  // non standard (old music match)
                        frameID != "MJMD" && // Non standard frame (Music Match XML)
                        frameID != "TT22" && // 000.00 - maybe meant to be 3 letter TT2 frame, and value be 2000.00? still makes no sense
                        frameID != "PCST" && // null data
                        frameID != "TCAT" && // category (ie, comedy) (distorted view)
                        frameID != "TKWD" && // looks like blog tags "comedy funny weird", etc (distorted view)
                        frameID != "TDES" && // xml file - used by distortedview.com
                        frameID != "TGID" && // url (from distortedview)
                        frameID != "WFED" && // url (thanks distortedview)
                        frameID != "CM1" && // some kind of comment, seen in ID3v2.2
                        frameID != "TMB" && // ripped by something other, not in spec
                        frameID != "RTNG" &&
                        frameID != "XDOR" && // year
                        frameID != "XSOP" && // looks like artist, "Allman Brothers Band, The"
                        frameID != "TENK") // itunes encoder (todo: add alias?)
                    {
                        /*String msg = String.Format("Unrecognized FrameID '{0}' (not critical)", tmpFrameID);
                        Trace.WriteLine(msg);*/
                    }

                    UnknownFrame unknownFrame = new UnknownFrame(frameID, tagReadingInfo, stream);
                    _unknownFrames.Add(unknownFrame);
                    //m_ReadFrames.Add(tmpUNKN);
                    bytesRead += unknownFrame.FrameHeader.FrameSizeTotal;
                }
            }

            // Process iTunes comments
            foreach (var comment in new List<IComments>(m_CommentsList))
            {
                if (comment.Description != null && comment.Description.StartsWith("iTun"))
                {
                    m_CommentsList.Remove(comment);
                    m_iTunesCommentsList.Add(comment);
                }
            }

            // Process genre // TODO: may need cleanup
            if (!string.IsNullOrEmpty(m_Genre.Value))
            {
                if (m_Genre.Value.StartsWith("("))
                {
                    int closeIndex = m_Genre.Value.IndexOf(')');
                    if (closeIndex != -1)
                    {
                        if (closeIndex != m_Genre.Value.Length - 1)
                        {
                            // Take text description
                            m_Genre.Value = m_Genre.Value.Substring(closeIndex + 1, m_Genre.Value.Length - (closeIndex + 1));
                        }
                        else
                        {
                            // Lookup genre value
                            string innerValue = m_Genre.Value.Substring(1, closeIndex - 1);
                            int innerValueResult;
                            if (int.TryParse(innerValue, out innerValueResult))
                            {
                                if (GenreHelper.GenreByIndex.Length > innerValueResult && innerValueResult >= 0)
                                {
                                    m_Genre.Value = GenreHelper.GenreByIndex[innerValueResult];
                                }
                                else
                                {
                                    Trace.WriteLine("Unrecognized genre");
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Unrecognized genre");
                            }
                        }
                    }
                }
            }
        }
Beispiel #28
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 >= 6)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream, ref num1);
         if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v22)
         {
             Utils.ReadString(EncodingType.ISO88591, stream, 3);
             num1 -= 3;
         }
         else
         {
             this.MimeType = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
         }
         this.PictureType = (IdSharp.Tagging.ID3v2.PictureType) Utils.ReadByte(stream, ref num1);
         this.Description = Utils.ReadString(this.TextEncoding, stream, ref num1);
         if (num1 > 0)
         {
             byte[] buffer1 = Utils.Read(stream, num1);
             num1 = 0;
             this.m_ReadingTag = true;
             try
             {
                 this.m_PictureCached = false;
                 this.PictureData = buffer1;
                 goto Label_00D1;
             }
             finally
             {
                 this.m_ReadingTag = false;
             }
         }
         this.PictureData = null;
     }
     else
     {
         this.TextEncoding = EncodingType.ISO88591;
         this.Description = null;
         this.MimeType = null;
         this.PictureType = IdSharp.Tagging.ID3v2.PictureType.CoverFront;
         this.PictureData = null;
     }
 Label_00D1:
     if (num1 > 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
Beispiel #29
0
 public abstract void Read(TagReadingInfo tagReadingInfo, Stream stream);
Beispiel #30
0
        public void Read(TagReadingInfo tagReadingInfo, ref Stream stream)
        {
            // TODO: Some tags have the length INCLUDE the extra ten bytes of the tag header.
            // Handle this (don't corrupt MP3 on rewrite)

            m_TagVersion = tagReadingInfo.TagVersion;

            bool usesUnsynchronization = ((tagReadingInfo.TagVersionOptions & TagVersionOptions.Unsynchronized) == TagVersionOptions.Unsynchronized);

            if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v23)
            {
                if (!usesUnsynchronization)
                {
                    m_FrameSize = stream.ReadInt32();
                }
                else
                {
                    m_FrameSize = ID3v2Utils.ReadInt32Unsynchronized(stream);
                }

                m_FrameSizeExcludingAdditions = m_FrameSize;

                byte byte0 = stream.Read1();
                byte byte1 = stream.Read1();

                // First byte
                IsTagAlterPreservation  = ((byte0 & 0x80) == 0x80);
                IsFileAlterPreservation = ((byte0 & 0x40) == 0x40);
                IsReadOnly = ((byte0 & 0x20) == 0x20);

                // Second byte
                IsCompressed = ((byte1 & 0x80) == 0x80);
                bool tmpIsEncrypted        = ((byte1 & 0x40) == 0x40);
                bool tmpIsGroupingIdentity = ((byte1 & 0x20) == 0x20);

                // Additional bytes

                // Compression
                if (IsCompressed)
                {
                    DecompressedSize = stream.ReadInt32();
                    m_FrameSizeExcludingAdditions -= 4;
                }
                else
                {
                    DecompressedSize = 0;
                }

                // Encryption
                if (tmpIsEncrypted)
                {
                    EncryptionMethod = stream.Read1();
                    m_FrameSizeExcludingAdditions -= 1;
                }
                else
                {
                    EncryptionMethod = null;
                }

                // Grouping Identity
                if (tmpIsGroupingIdentity)
                {
                    GroupingIdentity = stream.Read1();
                    m_FrameSizeExcludingAdditions -= 1;
                }
                else
                {
                    GroupingIdentity = null;
                }

                if (usesUnsynchronization)
                {
                    stream = ID3v2Utils.ReadUnsynchronizedStream(stream, m_FrameSize);
                }
            }
            else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v22)
            {
                if (!usesUnsynchronization)
                {
                    m_FrameSize = stream.ReadInt24();
                }
                else
                {
                    m_FrameSize = ID3v2Utils.ReadInt24Unsynchronized(stream);
                }

                if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.AddOneByteToSize) == TagVersionOptions.AddOneByteToSize)
                {
                    m_FrameSize++;
                }
                m_FrameSizeExcludingAdditions = m_FrameSize;

                // These fields are not supported in ID3v2.2
                IsTagAlterPreservation  = false;
                IsFileAlterPreservation = false;
                IsReadOnly       = false;
                IsCompressed     = false;
                DecompressedSize = 0;
                EncryptionMethod = null;
                GroupingIdentity = null;

                if (usesUnsynchronization)
                {
                    stream = ID3v2Utils.ReadUnsynchronizedStream(stream, m_FrameSize);
                }
            }
            else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v24)
            {
                if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.UseNonSyncSafeFrameSizeID3v24) == TagVersionOptions.UseNonSyncSafeFrameSizeID3v24)
                {
                    m_FrameSize = stream.ReadInt32();
                }
                else
                {
                    m_FrameSize = ID3v2Utils.ReadInt32SyncSafe(stream);
                }

                m_FrameSizeExcludingAdditions = m_FrameSize;

                byte byte0 = stream.Read1();
                byte byte1 = stream.Read1();

                bool hasDataLengthIndicator = ((byte1 & 0x01) == 0x01);
                usesUnsynchronization = ((byte1 & 0x03) == 0x03);
                if (hasDataLengthIndicator)
                {
                    m_FrameSizeExcludingAdditions -= 4;
                    stream.Seek(4, SeekOrigin.Current); // skip data length indicator
                }

                if (usesUnsynchronization)
                {
                    stream = ID3v2Utils.ReadUnsynchronizedStream(stream, m_FrameSize);
                }

                // TODO - finish parsing
            }

            if (IsCompressed)
            {
                stream           = ID3v2Utils.DecompressFrame(stream, FrameSizeExcludingAdditions);
                IsCompressed     = false;
                DecompressedSize = 0;
                m_FrameSizeExcludingAdditions = (int)stream.Length;
            }
        }
Beispiel #31
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     int num1 = this.m_FrameHeader.FrameSizeExcludingAdditions;
     if (num1 > 0)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream, ref num1);
         if (num1 > 0)
         {
             this.MimeType = Utils.ReadString(EncodingType.ISO88591, stream, ref num1);
             if (num1 > 1)
             {
                 byte num2 = Utils.ReadByte(stream, ref num1);
                 this.m_IsMpegOrAac = (num2 & 1) == 0;
                 this.EquivalentText = Utils.ReadString(this.TextEncoding, stream, ref num1);
                 if (num1 > 0)
                 {
                     this.m_AudioData = Utils.Read(stream, num1);
                     num1 = 0;
                 }
             }
             else
             {
                 this.EquivalentText = null;
                 this.m_AudioData = null;
             }
         }
         else
         {
             this.MimeType = null;
             this.EquivalentText = null;
             this.m_AudioData = null;
         }
     }
     else
     {
         this.TextEncoding = EncodingType.ISO88591;
         this.MimeType = null;
         this.EquivalentText = null;
         this.m_AudioData = null;
     }
     if (num1 > 0)
     {
         stream.Seek((long) num1, SeekOrigin.Current);
     }
 }
Beispiel #32
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     if (this.m_FrameHeader.FrameSizeExcludingAdditions >= 1)
     {
         this.TextEncoding = (EncodingType) Utils.ReadByte(stream);
         if (this.m_FrameHeader.FrameSizeExcludingAdditions >= 4)
         {
             string text1 = Utils.ReadString(EncodingType.ISO88591, stream, 3);
             int num1 = (this.m_FrameHeader.FrameSizeExcludingAdditions - 1) - 3;
             string text2 = Utils.ReadString(this.TextEncoding, stream, ref num1);
             bool flag1 = false;
             if (!LanguageHelper.Languages.ContainsKey(text1.ToLower()) && (text1.ToLower() != "xxx"))
             {
                 if (text1.StartsWith("en"))
                 {
                     text1 = "";
                 }
                 flag1 = true;
                 if (num1 == 0)
                 {
                     this.Description = "";
                 }
                 else
                 {
                     this.Description = text1 + text2;
                 }
                 this.LanguageCode = "eng";
             }
             else
             {
                 this.LanguageCode = text1;
                 this.Description = text2;
             }
             if (num1 > 0)
             {
                 this.Value = Utils.ReadString(this.TextEncoding, stream, num1);
             }
             else if (flag1)
             {
                 if (text1.Contains("\0"))
                 {
                     this.Value = "";
                 }
                 else
                 {
                     this.Value = text1 + text2;
                 }
             }
             else
             {
                 this.Value = "";
             }
         }
         else
         {
             string text3 = string.Format("Under-sized ({0} bytes) COMM frame at position {1}", this.m_FrameHeader.FrameSizeExcludingAdditions, stream.Position);
             Trace.WriteLine(text3);
             this.LanguageCode = "eng";
             this.Value = "";
         }
     }
     else
     {
         string text4 = string.Format("Under-sized ({0} bytes) COMM frame at position {1}", this.m_FrameHeader.FrameSizeExcludingAdditions, stream.Position);
         Trace.WriteLine(text4);
         this.LanguageCode = "eng";
         this.Value = "";
     }
 }
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_MusicianCreditsItemBindingList.Clear();
     throw new NotImplementedException();
 }
Beispiel #34
0
 public void Read(TagReadingInfo tagReadingInfo, Stream stream)
 {
     this.m_FrameHeader.Read(tagReadingInfo, ref stream);
     this.Value = Utils.ReadString(EncodingType.ISO88591, stream, this.m_FrameHeader.FrameSizeExcludingAdditions);
 }
Beispiel #35
0
        public void Read(TagReadingInfo tagReadingInfo, ref Stream stream)
        {
            // TODO: Some tags have the length INCLUDE the extra ten bytes of the tag header.
            // Handle this (don't corrupt MP3 on rewrite)

            m_TagVersion = tagReadingInfo.TagVersion;

            bool usesUnsynchronization = ((tagReadingInfo.TagVersionOptions & TagVersionOptions.Unsynchronized) == TagVersionOptions.Unsynchronized);

            if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v23)
            {
                if (!usesUnsynchronization)
                    m_FrameSize = stream.ReadInt32();
                else
                    m_FrameSize = ID3v2Utils.ReadInt32Unsynchronized(stream);

                m_FrameSizeExcludingAdditions = m_FrameSize;

                byte byte0 = stream.Read1();
                byte byte1 = stream.Read1();

                // First byte
                IsTagAlterPreservation = ((byte0 & 0x80) == 0x80);
                IsFileAlterPreservation = ((byte0 & 0x40) == 0x40);
                IsReadOnly = ((byte0 & 0x20) == 0x20);

                // Second byte
                IsCompressed = ((byte1 & 0x80) == 0x80);
                bool tmpIsEncrypted = ((byte1 & 0x40) == 0x40);
                bool tmpIsGroupingIdentity = ((byte1 & 0x20) == 0x20);

                // Additional bytes

                // Compression
                if (IsCompressed)
                {
                    DecompressedSize = stream.ReadInt32();
                    m_FrameSizeExcludingAdditions -= 4;
                }
                else
                {
                    DecompressedSize = 0;
                }

                // Encryption
                if (tmpIsEncrypted)
                {
                    EncryptionMethod = stream.Read1();
                    m_FrameSizeExcludingAdditions -= 1;
                }
                else
                {
                    EncryptionMethod = null;
                }

                // Grouping Identity
                if (tmpIsGroupingIdentity)
                {
                    GroupingIdentity = stream.Read1();
                    m_FrameSizeExcludingAdditions -= 1;
                }
                else
                {
                    GroupingIdentity = null;
                }

                if (usesUnsynchronization)
                {
                    stream = ID3v2Utils.ReadUnsynchronizedStream(stream, m_FrameSize);
                }
            }
            else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v22)
            {
                if (!usesUnsynchronization)
                    m_FrameSize = stream.ReadInt24();
                else
                    m_FrameSize = ID3v2Utils.ReadInt24Unsynchronized(stream);

                if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.AddOneByteToSize) == TagVersionOptions.AddOneByteToSize)
                {
                    m_FrameSize++;
                }
                m_FrameSizeExcludingAdditions = m_FrameSize;

                // These fields are not supported in ID3v2.2
                IsTagAlterPreservation = false;
                IsFileAlterPreservation = false;
                IsReadOnly = false;
                IsCompressed = false;
                DecompressedSize = 0;
                EncryptionMethod = null;
                GroupingIdentity = null;

                if (usesUnsynchronization)
                {
                    stream = ID3v2Utils.ReadUnsynchronizedStream(stream, m_FrameSize);
                }
            }
            else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v24)
            {
                if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.UseNonSyncSafeFrameSizeID3v24) == TagVersionOptions.UseNonSyncSafeFrameSizeID3v24)
                    m_FrameSize = stream.ReadInt32();
                else
                    m_FrameSize = ID3v2Utils.ReadInt32SyncSafe(stream);

                m_FrameSizeExcludingAdditions = m_FrameSize;

                byte byte0 = stream.Read1();
                byte byte1 = stream.Read1();

                bool hasDataLengthIndicator = ((byte1 & 0x01) == 0x01);
                usesUnsynchronization = ((byte1 & 0x03) == 0x03);
                if (hasDataLengthIndicator)
                {
                    m_FrameSizeExcludingAdditions -= 4;
                    stream.Seek(4, SeekOrigin.Current); // skip data length indicator
                }

                if (usesUnsynchronization)
                {
                    stream = ID3v2Utils.ReadUnsynchronizedStream(stream, m_FrameSize);
                }

                // TODO - finish parsing
            }

            if (IsCompressed)
            {
                stream = ID3v2Utils.DecompressFrame(stream, FrameSizeExcludingAdditions);
                IsCompressed = false;
                DecompressedSize = 0;
                m_FrameSizeExcludingAdditions = (int)stream.Length;
            }
        }
Beispiel #36
0
        /// <summary>
        /// Reads the raw data from a specified stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        public void Read(Stream stream)
        {
            // Check for 'ID3' marker
            byte[] identifier = stream.Read(3);
            if (!(identifier[0] == 0x49 && identifier[1] == 0x44 && identifier[2] == 0x33))
            {
                return;
            }

            // Read the header
            _id3v2Header = new ID3v2Header(stream, false);

            TagReadingInfo tagReadingInfo = new TagReadingInfo(_id3v2Header.TagVersion);

            if (_id3v2Header.UsesUnsynchronization)
            {
                tagReadingInfo.TagVersionOptions = TagVersionOptions.Unsynchronized;
            }
            else
            {
                tagReadingInfo.TagVersionOptions = TagVersionOptions.None;
            }

            if (_id3v2Header.HasExtendedHeader)
            {
                _id3v2ExtendedHeader = new ID3v2ExtendedHeader(tagReadingInfo, stream);
            }

            int frameIDSize = (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v22 ? 3 : 4);
            int bytesRead;
            int readUntil;

            #region <<< ID3v2.4 - Guess if syncsafe frame size was used or not >>>

            if (_id3v2Header.TagVersion == ID3v2TagVersion.ID3v24)
            {
                bool isID3v24SyncSafe = true;

                bytesRead = 0;
                readUntil = _id3v2Header.TagSize - _id3v2ExtendedHeader.SizeIncludingSizeBytes - frameIDSize;
                long initialPosition = stream.Position;
                while (bytesRead < readUntil)
                {
                    byte[] frameIDBytes = stream.Read(frameIDSize);

                    // TODO: Noticed some tags contain 0x00 'E' 'N' as a FrameID.  Frame is well structured
                    // and other frames follow.  I believe the below (keep reading+looking) will cover this issue.

                    // If character is not a letter or number, padding reached, audio began,
                    // or otherwise the frame is not readable
                    if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A ||
                        frameIDBytes[1] < 0x30 || frameIDBytes[1] > 0x5A ||
                        frameIDBytes[2] < 0x30 || frameIDBytes[2] > 0x5A ||
                        frameIDBytes[3] < 0x30 || frameIDBytes[3] > 0x5A)
                    {
                        // TODO: Try to keep reading and look for a valid frame
                        if (frameIDBytes[0] != 0 && frameIDBytes[0] != 0xFF)
                        {
                            /*String msg = String.Format("Out of range FrameID - 0x{0:X}|0x{1:X}|0x{2:X}|0x{3:X}",
                             *                         tmpFrameIDBytes[0], tmpFrameIDBytes[1], tmpFrameIDBytes[2],
                             *                         tmpFrameIDBytes[3]);
                             * Trace.WriteLine(msg);*/
                        }

                        break;
                    }

                    int frameSize = stream.ReadInt32();
                    if (frameSize > 0xFF)
                    {
                        if ((frameSize & 0x80) == 0x80)
                        {
                            isID3v24SyncSafe = false; break;
                        }
                        if ((frameSize & 0x8000) == 0x8000)
                        {
                            isID3v24SyncSafe = false; break;
                        }
                        if ((frameSize & 0x800000) == 0x800000)
                        {
                            isID3v24SyncSafe = false; break;
                        }

                        if (bytesRead + frameSize + 10 == _id3v2Header.TagSize)
                        {
                            // Could give a false positive, but relatively unlikely (famous last words, huh?)
                            isID3v24SyncSafe = false;
                            break;
                        }
                        else
                        {
                            stream.Seek(-4, SeekOrigin.Current); // go back to read sync-safe version
                            int syncSafeFrameSize = ID3v2Utils.ReadInt32SyncSafe(stream);

                            long currentPosition = stream.Position;

                            bool isValidAtSyncSafe    = true;
                            bool isValidAtNonSyncSafe = true;

                            // TODO - if it's the last frame and there is padding, both would indicate false
                            // Use the one that returns some padding bytes opposed to bytes with non-zero values (could be frame data)

                            // If non sync-safe reads past the end of the tag, then it's sync safe
                            // Testing non-sync safe since it will always be bigger than the sync safe integer
                            if (currentPosition + frameSize + 2 >= readUntil)
                            {
                                isID3v24SyncSafe = true; break;
                            }

                            // Test non-sync safe
                            stream.Seek(currentPosition + frameSize + 2, SeekOrigin.Begin);
                            frameIDBytes = stream.Read(frameIDSize);
                            if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A ||
                                frameIDBytes[1] < 0x30 || frameIDBytes[1] > 0x5A ||
                                frameIDBytes[2] < 0x30 || frameIDBytes[2] > 0x5A ||
                                frameIDBytes[3] < 0x30 || frameIDBytes[3] > 0x5A)
                            {
                                isValidAtNonSyncSafe = false;
                            }

                            // Test sync-safe
                            stream.Seek(currentPosition + syncSafeFrameSize + 2, SeekOrigin.Begin);
                            frameIDBytes = stream.Read(frameIDSize);
                            if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A ||
                                frameIDBytes[1] < 0x30 || frameIDBytes[1] > 0x5A ||
                                frameIDBytes[2] < 0x30 || frameIDBytes[2] > 0x5A ||
                                frameIDBytes[3] < 0x30 || frameIDBytes[3] > 0x5A)
                            {
                                isValidAtSyncSafe = false;
                            }

                            // if they're equal, we'll just have to go with syncsafe, since that's the spec

                            if (isValidAtNonSyncSafe != isValidAtSyncSafe)
                            {
                                isID3v24SyncSafe = isValidAtSyncSafe;
                            }
                            break;
                        }
                    }

                    stream.Seek(frameSize + 2, SeekOrigin.Current);
                    bytesRead += frameSize + 10;
                }

                stream.Position = initialPosition;
                if (isID3v24SyncSafe == false)
                {
                    tagReadingInfo.TagVersionOptions |= TagVersionOptions.UseNonSyncSafeFrameSizeID3v24;
                }
            }
            else if (_id3v2Header.TagVersion == ID3v2TagVersion.ID3v22)
            {
                bool isID3v22CorrectSize = true;

                bytesRead = 0;
                readUntil = _id3v2Header.TagSize - _id3v2ExtendedHeader.SizeIncludingSizeBytes - frameIDSize;
                long initialPosition = stream.Position;

                stream.Read(frameIDSize);
                UnknownFrame unknownFrame = new UnknownFrame(null, tagReadingInfo, stream);
                bytesRead += unknownFrame.FrameHeader.FrameSizeTotal;
                if (bytesRead < readUntil)
                {
                    byte[] frameIDBytes = stream.Read(frameIDSize);

                    // TODO: Noticed some tags contain 0x00 'E' 'N' as a FrameID.  Frame is well structured
                    // and other frames follow.  I believe the below (keep reading+looking) will cover this issue.

                    // If character is not a letter or number, padding reached, audio began,
                    // or otherwise the frame is not readable
                    if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A)
                    {
                        if (frameIDBytes[1] >= 0x30 && frameIDBytes[1] <= 0x5A &&
                            frameIDBytes[2] >= 0x30 && frameIDBytes[2] <= 0x5A)
                        {
                            Trace.WriteLine("ID3v2.2 frame size off by 1 byte");
                            isID3v22CorrectSize = false;
                        }
                    }
                }

                stream.Position = initialPosition;
                if (isID3v22CorrectSize == false)
                {
                    tagReadingInfo.TagVersionOptions |= TagVersionOptions.AddOneByteToSize;
                }
            }

            #endregion <<< ID3v2.4 - Guess if syncsafe frame size was used or not >>>

            readUntil = _id3v2Header.TagSize - _id3v2ExtendedHeader.SizeIncludingSizeBytes - frameIDSize;
            Read(stream, _id3v2Header.TagVersion, tagReadingInfo, readUntil, frameIDSize);
        }
Beispiel #37
0
        internal void Read(Stream stream, ID3v2TagVersion tagVersion, TagReadingInfo tagReadingInfo, int readUntil, int frameIDSize)
        {
            Dictionary <string, IBindingList> multipleOccurrenceFrames = GetMultipleOccurrenceFrames(tagVersion);
            Dictionary <string, IFrame>       singleOccurrenceFrames   = GetSingleOccurrenceFrames(tagVersion);

            int bytesRead = 0;

            while (bytesRead < readUntil)
            {
                byte[] frameIDBytes = stream.Read(frameIDSize);

                // If character is not a letter or number, padding reached, audio began,
                // or otherwise the frame is not readable
                if (frameIDSize == 4)
                {
                    if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A ||
                        frameIDBytes[1] < 0x30 || frameIDBytes[1] > 0x5A ||
                        frameIDBytes[2] < 0x30 || frameIDBytes[2] > 0x5A ||
                        frameIDBytes[3] < 0x30 || frameIDBytes[3] > 0x5A)
                    {
                        // TODO: Try to keep reading and look for a valid frame
                        if (frameIDBytes[0] != 0 && frameIDBytes[0] != 0xFF)
                        {
                            string msg = string.Format("Out of range FrameID - 0x{0:X}|0x{1:X}|0x{2:X}|0x{3:X}",
                                                       frameIDBytes[0], frameIDBytes[1], frameIDBytes[2], frameIDBytes[3]);
                            if (ByteUtils.ISO88591GetString(frameIDBytes) != "MP3e")
                            {
                                string tmpBadFrameID = ByteUtils.ISO88591GetString(frameIDBytes).TrimEnd('\0');
                                Trace.WriteLine(msg + " - " + tmpBadFrameID);
                            }
                        }

                        break;
                    }
                }
                else if (frameIDSize == 3)
                {
                    if (frameIDBytes[0] < 0x30 || frameIDBytes[0] > 0x5A ||
                        frameIDBytes[1] < 0x30 || frameIDBytes[1] > 0x5A ||
                        frameIDBytes[2] < 0x30 || frameIDBytes[2] > 0x5A)
                    {
                        // TODO: Try to keep reading and look for a valid frame
                        if (frameIDBytes[0] != 0 && frameIDBytes[0] != 0xFF)
                        {
                            string msg = string.Format("Out of range FrameID - 0x{0:X}|0x{1:X}|0x{2:X}",
                                                       frameIDBytes[0], frameIDBytes[1], frameIDBytes[2]);
                            Trace.WriteLine(msg);
                            Trace.WriteLine(ByteUtils.ISO88591GetString(frameIDBytes));
                        }

                        break;
                    }
                }

                string frameID = ByteUtils.ISO88591GetString(frameIDBytes);

                // TODO: Take out
                //Console.WriteLine(tmpFrameID); // TODO: take out

                /*
                 *  COMM Frames:
                 *  SoundJam_CDDB_TrackNumber
                 *  SoundJam_CDDB_1
                 *  iTunNORM
                 *  iTunSMPB
                 *  iTunes_CDDB_IDs
                 *  iTunes_CDDB_1
                 *  iTunes_CDDB_TrackNumber
                 */

                IFrame frame;
                do
                {
                    IBindingList bindingList;
                    if (singleOccurrenceFrames.TryGetValue(frameID, out frame))
                    {
                        frame.Read(tagReadingInfo, stream);
                        bytesRead += frame.FrameHeader.FrameSizeTotal;
                        //m_ReadFrames.Add(tmpFrame);
                    }
                    else if (multipleOccurrenceFrames.TryGetValue(frameID, out bindingList))
                    {
                        frame = (IFrame)bindingList.AddNew();
                        frame.Read(tagReadingInfo, stream);
                        //m_ReadFrames.Add(tmpFrame);
                        bytesRead += frame.FrameHeader.FrameSizeTotal;
                    }
                    else
                    {
                        if (tagVersion == ID3v2TagVersion.ID3v24)
                        {
                            string newFrameID;
                            if (_id3v24FrameAliases.TryGetValue(frameID, out newFrameID))
                            {
                                frameID = newFrameID;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else if (tagVersion == ID3v2TagVersion.ID3v23)
                        {
                            string newFrameID;
                            if (_id3v23FrameAliases.TryGetValue(frameID, out newFrameID))
                            {
                                frameID = newFrameID;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                } while (frame == null);

                // Frame is unknown
                if (frame == null)
                {
                    if (frameID != "NCON" && // non standard (old music match)
                        frameID != "MJMD" && // Non standard frame (Music Match XML)
                        frameID != "TT22" && // 000.00 - maybe meant to be 3 letter TT2 frame, and value be 2000.00? still makes no sense
                        frameID != "PCST" && // null data
                        frameID != "TCAT" && // category (ie, comedy) (distorted view)
                        frameID != "TKWD" && // looks like blog tags "comedy funny weird", etc (distorted view)
                        frameID != "TDES" && // xml file - used by distortedview.com
                        frameID != "TGID" && // url (from distortedview)
                        frameID != "WFED" && // url (thanks distortedview)
                        frameID != "CM1" &&  // some kind of comment, seen in ID3v2.2
                        frameID != "TMB" &&  // ripped by something other, not in spec
                        frameID != "RTNG" &&
                        frameID != "XDOR" && // year
                        frameID != "XSOP" && // looks like artist, "Allman Brothers Band, The"
                        frameID != "TENK")   // itunes encoder (todo: add alias?)
                    {
                        /*String msg = String.Format("Unrecognized FrameID '{0}' (not critical)", tmpFrameID);
                         * Trace.WriteLine(msg);*/
                    }

                    UnknownFrame unknownFrame = new UnknownFrame(frameID, tagReadingInfo, stream);
                    _unknownFrames.Add(unknownFrame);
                    //m_ReadFrames.Add(tmpUNKN);
                    bytesRead += unknownFrame.FrameHeader.FrameSizeTotal;
                }
            }

            // Process iTunes comments
            for (int i = 0; i < m_CommentsList.Count;)
            {
                var comment = m_CommentsList[i];
                if (comment.Description?.StartsWith("iTun", StringComparison.Ordinal) == true)
                {
                    m_CommentsList.RemoveAt(i);
                    m_iTunesCommentsList.Add(comment);
                }
                else
                {
                    i++;
                }
            }

            // Process genre // TODO: may need cleanup
            if (!string.IsNullOrEmpty(m_Genre.Value))
            {
                if (m_Genre.Value.StartsWith("("))
                {
                    int closeIndex = m_Genre.Value.IndexOf(')');
                    if (closeIndex != -1)
                    {
                        if (closeIndex != m_Genre.Value.Length - 1)
                        {
                            // Take text description
                            m_Genre.Value = m_Genre.Value.Substring(closeIndex + 1, m_Genre.Value.Length - (closeIndex + 1));
                        }
                        else
                        {
                            // Lookup genre value
                            string innerValue = m_Genre.Value.Substring(1, closeIndex - 1);
                            int    innerValueResult;
                            if (int.TryParse(innerValue, out innerValueResult))
                            {
                                if (GenreHelper.GenreByIndex.Length > innerValueResult && innerValueResult >= 0)
                                {
                                    m_Genre.Value = GenreHelper.GenreByIndex[innerValueResult];
                                }
                                else
                                {
                                    Trace.WriteLine("Unrecognized genre");
                                }
                            }
                            else
                            {
                                Trace.WriteLine("Unrecognized genre");
                            }
                        }
                    }
                }
            }
        }
Beispiel #38
0
 public void ReadStream(Stream stream)
 {
     if (Utils.ReadString(EncodingType.ISO88591, stream, 3) == "ID3")
     {
         int num2;
         int num3;
         this.m_ID3v2Header = new ID3v2Header(stream, false);
         TagReadingInfo info1 = new TagReadingInfo(this.m_ID3v2Header.TagVersion);
         if (this.m_ID3v2Header.UsesUnsynchronization)
         {
             info1.TagVersionOptions = TagVersionOptions.Unsynchronized;
         }
         else
         {
             info1.TagVersionOptions = TagVersionOptions.None;
         }
         if (this.m_ID3v2Header.HasExtendedHeader)
         {
             this.m_ID3v2ExtendedHeader = new ID3v2ExtendedHeader(info1, stream);
         }
         int num1 = (info1.TagVersion == ID3v2TagVersion.ID3v22) ? 3 : 4;
         if (this.m_ID3v2Header.TagVersion != ID3v2TagVersion.ID3v24)
         {
             if (this.m_ID3v2Header.TagVersion == ID3v2TagVersion.ID3v22)
             {
                 bool flag4 = true;
                 num2 = 0;
                 num3 = (this.m_ID3v2Header.TagSize - this.m_ID3v2ExtendedHeader.SizeIncludingSizeBytes) - num1;
                 long num8 = stream.Position;
                 Utils.Read(stream, num1);
                 UnknownFrame frame1 = new UnknownFrame(null, info1, stream);
                 num2 += frame1.FrameHeader.FrameSizeTotal;
                 if (num2 < num3)
                 {
                     byte[] buffer2 = Utils.Read(stream, num1);
                     if (((buffer2[0] < 0x30) || (buffer2[0] > 90)) && (((buffer2[1] >= 0x30) && (buffer2[1] <= 90)) && ((buffer2[2] >= 0x30) && (buffer2[2] <= 90))))
                     {
                         Trace.WriteLine("ID3v2.2 frame size off by 1 byte");
                         flag4 = false;
                     }
                 }
                 stream.Position = num8;
                 if (!flag4)
                 {
                     info1.TagVersionOptions |= TagVersionOptions.AddOneByteToSize;
                 }
             }
         }
         else
         {
             bool flag1 = true;
             num2 = 0;
             num3 = (this.m_ID3v2Header.TagSize - this.m_ID3v2ExtendedHeader.SizeIncludingSizeBytes) - num1;
             long num4 = stream.Position;
             while (num2 < num3)
             {
                 byte[] buffer1 = Utils.Read(stream, num1);
                 if ((((buffer1[0] < 0x30) || (buffer1[0] > 90)) || ((buffer1[1] < 0x30) || (buffer1[1] > 90))) || (((buffer1[2] < 0x30) || (buffer1[2] > 90)) || ((buffer1[3] < 0x30) || (buffer1[3] > 90))))
                 {
                     if ((buffer1[0] != 0) && (buffer1[0] != 0xff))
                     {
                     }
                     break;
                 }
                 int num5 = Utils.ReadInt32(stream);
                 if (num5 > 0xff)
                 {
                     if ((num5 & 0x80) == 0x80)
                     {
                         flag1 = false;
                         break;
                     }
                     if ((num5 & 0x8000) == 0x8000)
                     {
                         flag1 = false;
                         break;
                     }
                     if ((num5 & 0x800000) == 0x800000)
                     {
                         flag1 = false;
                         break;
                     }
                     if (((num2 + num5) + 10) == this.m_ID3v2Header.TagSize)
                     {
                         flag1 = false;
                         break;
                     }
                     stream.Seek((long) (-4), SeekOrigin.Current);
                     int num6 = Utils.ReadInt32SyncSafe(stream);
                     long num7 = stream.Position;
                     bool flag2 = true;
                     bool flag3 = true;
                     if (((num7 + num5) + 2) >= num3)
                     {
                         flag1 = true;
                         break;
                     }
                     stream.Seek((num7 + num5) + 2, SeekOrigin.Begin);
                     buffer1 = Utils.Read(stream, num1);
                     if ((((buffer1[0] < 0x30) || (buffer1[0] > 90)) || ((buffer1[1] < 0x30) || (buffer1[1] > 90))) || (((buffer1[2] < 0x30) || (buffer1[2] > 90)) || ((buffer1[3] < 0x30) || (buffer1[3] > 90))))
                     {
                         flag3 = false;
                     }
                     stream.Seek((num7 + num6) + 2, SeekOrigin.Begin);
                     buffer1 = Utils.Read(stream, num1);
                     if ((((buffer1[0] < 0x30) || (buffer1[0] > 90)) || ((buffer1[1] < 0x30) || (buffer1[1] > 90))) || (((buffer1[2] < 0x30) || (buffer1[2] > 90)) || ((buffer1[3] < 0x30) || (buffer1[3] > 90))))
                     {
                         flag2 = false;
                     }
                     if (flag3 != flag2)
                     {
                         flag1 = flag2;
                     }
                     break;
                 }
                 stream.Seek((long) (num5 + 2), SeekOrigin.Current);
                 num2 += num5 + 10;
             }
             stream.Position = num4;
             if (!flag1)
             {
                 info1.TagVersionOptions |= TagVersionOptions.UseNonSyncSafeFrameSizeID3v24;
             }
         }
         num3 = (this.m_ID3v2Header.TagSize - this.m_ID3v2ExtendedHeader.SizeIncludingSizeBytes) - num1;
         base.Read(stream, this.m_ID3v2Header.TagVersion, info1, num3, num1);
     }
 }
Beispiel #39
0
 public void Read(TagReadingInfo tagReadingInfo, ref Stream stream)
 {
     this.m_TagVersion = tagReadingInfo.TagVersion;
     bool flag1 = (tagReadingInfo.TagVersionOptions & TagVersionOptions.Unsynchronized) == TagVersionOptions.Unsynchronized;
     if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v23)
     {
         if (!flag1)
         {
             this.m_FrameSize = Utils.ReadInt32(stream);
         }
         else
         {
             this.m_FrameSize = Utils.ReadInt32Unsynchronized(stream);
         }
         this.m_FrameSizeExcludingAdditions = this.m_FrameSize;
         byte num1 = Utils.ReadByte(stream);
         byte num2 = Utils.ReadByte(stream);
         this.IsTagAlterPreservation = (num1 & 0x80) == 0x80;
         this.IsFileAlterPreservation = (num1 & 0x40) == 0x40;
         this.IsReadOnly = (num1 & 0x20) == 0x20;
         this.IsCompressed = (num2 & 0x80) == 0x80;
         bool flag2 = (num2 & 0x40) == 0x40;
         bool flag3 = (num2 & 0x20) == 0x20;
         if (this.IsCompressed)
         {
             this.DecompressedSize = Utils.ReadInt32(stream);
             this.m_FrameSizeExcludingAdditions -= 4;
         }
         else
         {
             this.DecompressedSize = 0;
         }
         if (flag2)
         {
             this.EncryptionMethod = new Nullable<byte>(Utils.ReadByte(stream));
             this.m_FrameSizeExcludingAdditions--;
         }
         else
         {
             this.EncryptionMethod = new Nullable<byte>();
         }
         if (flag3)
         {
             this.GroupingIdentity = new Nullable<byte>(Utils.ReadByte(stream));
             this.m_FrameSizeExcludingAdditions--;
         }
         else
         {
             this.GroupingIdentity = new Nullable<byte>();
         }
         if (flag1)
         {
             stream = Utils.ReadUnsynchronizedStream(stream, this.m_FrameSize);
         }
     }
     else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v22)
     {
         if (!flag1)
         {
             this.m_FrameSize = Utils.ReadInt24(stream);
         }
         else
         {
             this.m_FrameSize = Utils.ReadInt24Unsynchronized(stream);
         }
         if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.AddOneByteToSize) == TagVersionOptions.AddOneByteToSize)
         {
             this.m_FrameSize++;
         }
         this.m_FrameSizeExcludingAdditions = this.m_FrameSize;
         this.IsTagAlterPreservation = false;
         this.IsFileAlterPreservation = false;
         this.IsReadOnly = false;
         this.IsCompressed = false;
         this.DecompressedSize = 0;
         this.EncryptionMethod = new Nullable<byte>();
         this.GroupingIdentity = new Nullable<byte>();
         if (flag1)
         {
             stream = Utils.ReadUnsynchronizedStream(stream, this.m_FrameSize);
         }
     }
     else if (tagReadingInfo.TagVersion == ID3v2TagVersion.ID3v24)
     {
         if ((tagReadingInfo.TagVersionOptions & TagVersionOptions.UseNonSyncSafeFrameSizeID3v24) == TagVersionOptions.UseNonSyncSafeFrameSizeID3v24)
         {
             this.m_FrameSize = Utils.ReadInt32(stream);
         }
         else
         {
             this.m_FrameSize = Utils.ReadInt32SyncSafe(stream);
         }
         this.m_FrameSizeExcludingAdditions = this.m_FrameSize;
         Utils.ReadByte(stream);
         Utils.ReadByte(stream);
     }
     if (this.IsCompressed)
     {
         stream = Utils.DecompressFrame(stream, this.FrameSizeExcludingAdditions);
         this.IsCompressed = false;
         this.DecompressedSize = 0;
         this.m_FrameSizeExcludingAdditions = (int) stream.Length;
     }
 }