/// <summary>
        ///    Populates the values in the current instance by parsing
        ///    its field data in a specified version.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the
        ///    extracted field data.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> indicating the ID3v2 version the
        ///    field data is encoded in.
        /// </param>
        protected override void ParseFields(ByteVector data,
                                            byte version)
        {
            if (data.Count < 4)
            {
                throw new CorruptFileException(
                          "Not enough bytes in field.");
            }

            encoding = (StringType)data [0];
            language = data.ToString(StringType.Latin1, 1, 3);

            string [] split = data.ToStrings(encoding, 4, 2);

            if (split.Length == 1)
            {
                // Bad lyrics frame. Assume that it lacks a
                // description.
                description = String.Empty;
                text        = split [0];
            }
            else
            {
                description = split [0];
                text        = split [1];
            }
        }
예제 #2
0
        /// <summary>
        ///    Populates the values in the current instance by parsing
        ///    its field data in a specified version.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the
        ///    extracted field data.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> indicating the ID3v2 version the
        ///    field data is encoded in.
        /// </param>
        protected override void ParseFields(ByteVector data,
                                            byte version)
        {
            if (data.Count < 4)
            {
                throw new CorruptFileException(
                          "Not enough bytes in field.");
            }

            encoding = (StringType)data [0];
            language = data.ToString(StringType.Latin1, 1, 3);

            // Instead of splitting into two string, in the format
            // [{desc}\0{value}], try splitting into three strings
            // in case of a misformatted [{desc}\0{value}\0].
            string [] split = data.ToStrings(encoding, 4, 3);

            if (split.Length == 1)
            {
                // Bad comment frame. Assume that it lacks a
                // description.
                description = String.Empty;
                text        = split [0];
            }
            else
            {
                description = split [0];
                text        = split [1];
            }
        }
예제 #3
0
        /// <summary>
        ///    Performs the actual parsing of the raw data.
        /// </summary>
        /// <remarks>
        ///    Because of the high parsing cost and relatively low usage
        ///    of the class, <see cref="ParseFields" /> only stores the
        ///    field data so it can be parsed on demand. Whenever a
        ///    property or method is called which requires the data,
        ///    this method is called, and only on the first call does it
        ///    actually parse the data.
        /// </remarks>
        protected void ParseRawData()
        {
            if (raw_data == null)
            {
                return;
            }

            ByteVector data = raw_data;

            raw_data = null;

            // read the string data type (the first byte of the
            // field data)
            encoding = (StringType)data[0];
            List <string> field_list = new List <string>();

            ByteVector delim = ByteVector.TextDelimiter(encoding);

            if (FrameId != FrameType.WXXX)
            {
                field_list.AddRange(data.ToStrings(encoding, 0));
            }
            else if (data.Count > 1 && !data.Mid(0,
                                                 delim.Count).Equals(delim))
            {
                string value = data.ToString(StringType.Latin1, 1,
                                             data.Count - 1);

                // Do a fast removal of end bytes.
                if (value.Length > 1 &&
                    value[value.Length - 1] == 0)
                {
                    for (int i = value.Length - 1; i >= 0; i--)
                    {
                        if (value[i] != 0)
                        {
                            value = value.Substring(0, i + 1);
                            break;
                        }
                    }
                }

                field_list.Add(value);
            }

            // Bad tags may have one or more nul characters at the
            // end of a string, resulting in empty strings at the
            // end of the FieldList. Strip them off.
            while (field_list.Count != 0 &&
                   string.IsNullOrEmpty(field_list[
                                            field_list.Count - 1]))
            {
                field_list.RemoveAt(field_list.Count - 1);
            }

            text_fields = field_list.ToArray();
        }
		public void CommentsFrameError ()
		{
			// http://bugzilla.gnome.org/show_bug.cgi?id=582735
			// Comments data found in the wild
			var vector = new ByteVector (
				1, 255, 254, 73, 0, 68, 0, 51, 0, 71, 0, 58, 0, 32, 0, 50, 0, 55, 0, 0, 0);

			var encoding = (StringType)vector[0];
			//var language = vector.ToString (StringType.Latin1, 1, 3);
			var split = vector.ToStrings (encoding, 4, 3);
			Assert.AreEqual (2, split.Length);
		}
예제 #5
0
        public void CommentsFrameError()
        {
            // http://bugzilla.gnome.org/show_bug.cgi?id=582735
            // Comments data found in the wild
            ByteVector vector = new ByteVector (
                1, 255, 254, 73, 0, 68, 0, 51, 0, 71, 0, 58, 0, 32, 0, 50, 0, 55, 0, 0, 0);

            var encoding = (StringType) vector [0];
            var language = vector.ToString (StringType.Latin1, 1, 3);
            var split = vector.ToStrings (encoding, 4, 3);
            Assert.AreEqual (2, split.Length);
        }
예제 #6
0
        protected void ParseRawData()
        {
            if (raw_data == null)
            {
                return;
            }
            ByteVector data = raw_data;

            raw_data = null;
            List <string> field_list = new List <string>();
            ByteVector    delim      = ByteVector.TextDelimiter(encoding);

            if (FrameId != FrameType.WXXX)
            {
                field_list.AddRange(data.ToStrings(StringType.Latin1, 0));
            }
            else if (data.Count > 1 && !data.Mid(0, delim.Count).Equals(delim))
            {
                string value = data.ToString(StringType.Latin1, 1, data.Count - 1);
                if (value.Length > 1 && value[value.Length - 1] == 0)
                {
                    for (int i = value.Length - 1; i >= 0; i--)
                    {
                        if (value[i] != 0)
                        {
                            value = value.Substring(0, i + 1);
                            break;
                        }
                    }
                }
                field_list.Add(value);
            }
            while (field_list.Count != 0 && string.IsNullOrEmpty(field_list[field_list.Count - 1]))
            {
                field_list.RemoveAt(field_list.Count - 1);
            }
            text_fields = field_list.ToArray();
        }
		/// <summary>
		///    Populates the values in the current instance by parsing
		///    its field data in a specified version.
		/// </summary>
		/// <param name="data">
		///    A <see cref="ByteVector" /> object containing the
		///    extracted field data.
		/// </param>
		/// <param name="version">
		///    A <see cref="byte" /> indicating the ID3v2 version the
		///    field data is encoded in.
		/// </param>
		protected override void ParseFields (ByteVector data,
		                                     byte version)
		{
			if (data.Count < 4)
				throw new CorruptFileException (
					"Not enough bytes in field.");
			
			encoding = (StringType) data [0];
			language = data.ToString (StringType.Latin1, 1, 3);
			
			string [] split = data.ToStrings (encoding, 4, 2);
			
			if (split.Length == 1) {
				// Bad lyrics frame. Assume that it lacks a
				// description.
				description = String.Empty;
				text = split [0];
			} else {
				description = split [0];
				text = split [1];
			}
		}
예제 #8
0
		/// <summary>
		///    Populates the values in the current instance by parsing
		///    its field data in a specified version.
		/// </summary>
		/// <param name="data">
		///    A <see cref="ByteVector" /> object containing the
		///    extracted field data.
		/// </param>
		/// <param name="version">
		///    A <see cref="byte" /> indicating the ID3v2 version the
		///    field data is encoded in.
		/// </param>
		protected override void ParseFields (ByteVector data,
		                                     byte version)
		{
			if (data.Count < 4)
				throw new CorruptFileException (
					"Not enough bytes in field.");
			
			encoding = (StringType) data [0];
			language = data.ToString (StringType.Latin1, 1, 3);
			
			// Instead of splitting into two string, in the format
			// [{desc}\0{value}], try splitting into three strings
			// in case of a misformatted [{desc}\0{value}\0].
			string [] split = data.ToStrings (encoding, 4, 3);
			
			if (split.Length == 0) {
				// No data in the frame.
				description = String.Empty;
				text        = String.Empty;
			} else if (split.Length == 1) {
				// Bad comment frame. Assume that it lacks a
				// description.
				description = String.Empty;
				text        = split [0];
			} else {
				description = split [0];
				text        = split [1];
			}
		}
        protected void ParseRawData()
        {
            if (raw_data == null)
            {
                return;
            }

            ByteVector data = raw_data;

            raw_data = null;

            // read the string data type (the first byte of the
            // field data)
            encoding = (StringType)data [0];
            List <string> field_list = new List <string> ();

            ByteVector delim = ByteVector.TextDelimiter(encoding);

            if (raw_version > 3 || FrameId == FrameType.TXXX)
            {
                field_list.AddRange(data.ToStrings(encoding, 1));
            }
            else if (data.Count > 1 && !data.Mid(1,
                                                 delim.Count).Equals(delim))
            {
                string value = data.ToString(encoding, 1,
                                             data.Count - 1);

                // Do a fast removal of end bytes.
                if (value.Length > 1 &&
                    value [value.Length - 1] == 0)
                {
                    for (int i = value.Length - 1; i >= 0; i--)
                    {
                        if (value [i] != 0)
                        {
                            value = value.Substring(0, i + 1);
                            break;
                        }
                    }
                }

                if (FrameId == FrameType.TCOM ||
                    FrameId == FrameType.TEXT ||
                    FrameId == FrameType.TOLY ||
                    FrameId == FrameType.TOPE ||
                    FrameId == FrameType.TPE1 ||
                    FrameId == FrameType.TPE2 ||
                    FrameId == FrameType.TPE3 ||
                    FrameId == FrameType.TPE4)
                {
                    field_list.AddRange(value.Split('/'));
                }
                else if (FrameId == FrameType.TCON)
                {
                    while (value.Length > 1 && value [0] == '(')
                    {
                        int closing = value.IndexOf(')');
                        if (closing < 0)
                        {
                            break;
                        }

                        field_list.Add(
                            value.Substring(1,
                                            closing - 1));

                        value = value.Substring(
                            closing + 1);
                    }

                    if (value.Length > 0)
                    {
                        field_list.AddRange(value.Split(new char [] { '/' }));
                    }
                }
                else
                {
                    field_list.Add(value);
                }
            }

            // Bad tags may have one or more nul characters at the
            // end of a string, resulting in empty strings at the
            // end of the FieldList. Strip them off.
            while (field_list.Count != 0 &&
                   string.IsNullOrEmpty(field_list [
                                            field_list.Count - 1]))
            {
                field_list.RemoveAt(field_list.Count - 1);
            }

            text_fields = field_list.ToArray();
        }
 protected override void ParseFields(ByteVector data, byte version)
 {
     if (data.Count < 4)
     {
         throw new CorruptFileException("Not enough bytes in field.");
     }
     this.encoding = (StringType) data[0];
     this.language = data.ToString(StringType.Latin1, 1, 3);
     string[] strArray = data.ToStrings(this.encoding, 4, 2);
     if (strArray.Length == 1)
     {
         this.description = string.Empty;
         this.text = strArray[0];
     }
     else
     {
         this.description = strArray[0];
         this.text = strArray[1];
     }
 }
예제 #11
0
        protected void ParseRawData()
        {
            if (raw_data == null)
            {
                return;
            }
            ByteVector data = raw_data;

            raw_data = null;
            encoding = (StringType)data[0];
            List <string> field_list = new List <string>();
            ByteVector    delim      = ByteVector.TextDelimiter(encoding);

            if (raw_version > 3 || FrameId == FrameType.TXXX)
            {
                field_list.AddRange(data.ToStrings(encoding, 1));
            }
            else if (data.Count > 1 && !data.Mid(1, delim.Count).Equals(delim))
            {
                string value      = data.ToString(encoding, 1, data.Count - 1);
                int    null_index = value.IndexOf('\x00');
                if (null_index >= 0)
                {
                    value = value.Substring(0, null_index);
                }
                if (FrameId == FrameType.TCOM || FrameId == FrameType.TEXT || FrameId == FrameType.TOLY || FrameId == FrameType.TOPE || FrameId == FrameType.TPE1 || FrameId == FrameType.TPE2 || FrameId == FrameType.TPE3 || FrameId == FrameType.TPE4)
                {
                    field_list.AddRange(value.Split('/'));
                }
                else if (FrameId == FrameType.TCON)
                {
                    while (value.Length > 1 && value[0] == '(')
                    {
                        int closing = value.IndexOf(')');
                        if (closing < 0)
                        {
                            break;
                        }
                        string number = value.Substring(1, closing - 1);
                        field_list.Add(number);
                        value = value.Substring(closing + 1).TrimStart('/', ' ');
                        string text = Genres.IndexToAudio(number);
                        if (text != null && value.StartsWith(text))
                        {
                            value = value.Substring(text.Length).TrimStart('/', ' ');
                        }
                    }
                    if (value.Length > 0)
                    {
                        field_list.AddRange(value.Split(new char[] { '/' }));
                    }
                }
                else
                {
                    field_list.Add(value);
                }
            }
            while (field_list.Count != 0 && string.IsNullOrEmpty(field_list[field_list.Count - 1]))
            {
                field_list.RemoveAt(field_list.Count - 1);
            }
            text_fields = field_list.ToArray();
        }