Esempio n. 1
0
        /// <summary>
        ///     Constructs and initializes a new instance of
        ///     <see
        ///         cref="Item" />
        ///     with a specified key and raw data.
        /// </summary>
        /// <param name="key">
        ///     A <see cref="string" /> object containing the key to use
        ///     for the current instance.
        /// </param>
        /// <param name="value">
        ///     A <see cref="StringCollection" /> object containing the
        ///     values to store in the new instance.
        /// </param>
        /// <remarks>
        ///     This constructor automatically marks the new instance as
        ///     <see cref="ItemType.Binary" />.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="key" /> or <paramref name="value" /> is
        ///     <see langword="null" />.
        /// </exception>
        /// <seealso cref="Item(string,string[])" />
        public Item(string key, ByteVector value)
        {
            Key  = key;
            Type = ItemType.Binary;

            data = value as ReadOnlyByteVector ?? new ReadOnlyByteVector(value);
        }
Esempio n. 2
0
        private void Button5_Click(object sender, EventArgs e)
        {
            var tf = TagLib.File.Create(@"e:\tmp\dadata.mp3");

            var id3 = tf.GetTag(TagTypes.Id3v2) as TagLib.Id3v2.Tag;

            ReadOnlyByteVector USLT = "USLT";

            //UnsynchronisedLyricsFrame uslt;
            //foreach (var frame in id3.GetFrames(USLT))
            //{
            //    uslt = frame as UnsynchronisedLyricsFrame;
            //}

            //tf.Tag.Lyrics = "ascii?";

            //List<Frame> frames = new List<Frame>(id3.GetFrames(USLT));

            id3.RemoveFrames(USLT);

            UnsynchronisedLyricsFrame frame;

            frame = UnsynchronisedLyricsFrame.Get(id3, string.Empty, "eng", true);

            frame.Text = "今度こその新しい歌詞";

            tf.Save();
        }
Esempio n. 3
0
 public Item(string key, ByteVector value)
 {
     this.key  = key;
     this.type = ItemType.Binary;
     data      = value as ReadOnlyByteVector;
     if (data == null)
     {
         data = new ReadOnlyByteVector(value);
     }
 }
Esempio n. 4
0
        /// <summary>
        ///     Populates the current instance by reading in a raw APEv2
        ///     item.
        /// </summary>
        /// <param name="data">
        ///     A <see cref="ByteVector" /> object containing the item to
        ///     read.
        /// </param>
        /// <param name="offset">
        ///     A <see cref="int" /> value specifying the offset in
        ///     <paramref name="data" /> at which the item data begins.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="data" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     <paramref name="offset" /> is less than zero.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///     A complete item could not be read.
        /// </exception>
        protected void Parse(ByteVector data, int offset)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            // 11 bytes is the minimum size for an APE item
            if (data.Count < offset + 11)
            {
                throw new CorruptFileException(
                          "Not enough data for APE Item");
            }

            var value_length = data.Mid(offset, 4)
                               .ToUInt(false);

            var flags = data.Mid(offset + 4, 4)
                        .ToUInt(false);

            ReadOnly = (flags & 1) == 1;
            Type     = (ItemType)((flags >> 1) & 3);

            var pos = data.Find(ByteVector.TextDelimiter(
                                    StringType.UTF8), offset + 8);

            Key = data.ToString(StringType.UTF8,
                                offset + 8, pos - offset - 8);

            if (value_length > data.Count - pos - 1)
            {
                throw new CorruptFileException(
                          "Invalid data length.");
            }

            Size = pos + 1 + (int)value_length - offset;

            if (Type == ItemType.Binary)
            {
                this.data = new ReadOnlyByteVector(
                    data.Mid(pos + 1, (int)value_length));
            }
            else
            {
                text = data.Mid(pos + 1,
                                (int)value_length)
                       .ToStrings(
                    StringType.UTF8, 0);
            }
        }
Esempio n. 5
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="Item" /> with a specified key and raw data.
        /// </summary>
        /// <param name="key">
        ///    A <see cref="string" /> object containing the key to use
        ///    for the current instance.
        /// </param>
        /// <param name="value">
        ///    A <see cref="StringCollection" /> object containing the
        ///    values to store in the new instance.
        /// </param>
        /// <remarks>
        ///    This constructor automatically marks the new instance as
        ///    <see cref="ItemType.Binary" />.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="key" /> or <paramref name="value" /> is
        ///    <see langword="null" />.
        /// </exception>
        /// <seealso cref="Item(string,string[])" />
        public Item(string key, ByteVector value)
        {
            _key  = key;
            _type = ItemType.Binary;

            _data = value as ReadOnlyByteVector;
            if (_data == null)
            {
                _data = new ReadOnlyByteVector(value);
            }
        }
Esempio n. 6
0
        public FrameHeader(ByteVector data, byte version)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            flags      = 0;
            frame_size = 0;
            if (version < 2 || version > 4)
            {
                throw new CorruptFileException("Unsupported tag version.");
            }
            if (data.Count < (version == 2?3:4))
            {
                throw new CorruptFileException("Data must contain at least a frame ID.");
            }
            switch (version)
            {
            case 2:
                frame_id = ConvertId(data.Mid(0, 3), version, false);
                if (data.Count < 6)
                {
                    return;
                }
                frame_size = data.Mid(3, 3).ToUInt();
                return;

            case 3:
                frame_id = ConvertId(data.Mid(0, 4), version, false);
                if (data.Count < 10)
                {
                    return;
                }
                frame_size = data.Mid(4, 4).ToUInt();
                flags      = (FrameFlags)(((data[8] << 7) & 0x7000) | ((data[9] >> 4) & 0x000C) | ((data[9] << 1) & 0x0040));
                return;

            case 4:
                frame_id = new ReadOnlyByteVector(data.Mid(0, 4));
                if (data.Count < 10)
                {
                    return;
                }
                frame_size = SynchData.ToUInt(data.Mid(4, 4));
                flags      = (FrameFlags)data.Mid(8, 2).ToUShort();
                return;

            default:
                throw new CorruptFileException("Unsupported tag version.");
            }
        }
Esempio n. 7
0
 private Item(Item item)
 {
     _type = item._type;
     _key  = item._key;
     if (item._data != null)
     {
         _data = new ReadOnlyByteVector(item._data);
     }
     if (item._text != null)
     {
         _text = (string[])item._text.Clone();
     }
     _readOnly   = item._readOnly;
     _sizeOnDisk = item._sizeOnDisk;
 }
Esempio n. 8
0
 private Item(Item item)
 {
     type = item.type;
     key  = item.key;
     if (item.data != null)
     {
         data = new ReadOnlyByteVector(item.data);
     }
     if (item.text != null)
     {
         text = (string[])item.text.Clone();
     }
     read_only    = item.read_only;
     size_on_disk = item.size_on_disk;
 }
Esempio n. 9
0
 private Item(Item item)
 {
     Type = item.Type;
     Key  = item.Key;
     if (item.data != null)
     {
         data = new ReadOnlyByteVector(item.data);
     }
     if (item.text != null)
     {
         text = (string[])item.text.Clone();
     }
     ReadOnly = item.ReadOnly;
     Size     = item.Size;
 }
Esempio n. 10
0
 internal static ReadOnlyByteVector FixId(ByteVector id)
 {
     if (id.Count == 4)
     {
         ReadOnlyByteVector roid = id as ReadOnlyByteVector;
         if (roid != null)
         {
             return(roid);
         }
         return(new ReadOnlyByteVector(id));
     }
     if (id.Count == 3)
     {
         return(new ReadOnlyByteVector(0xa9, id[0], id[1], id[2]));
     }
     return(null);
 }
Esempio n. 11
0
 private static ReadOnlyByteVector ConvertId(ByteVector id, byte version, bool toVersion)
 {
     if (version >= 4)
     {
         ReadOnlyByteVector outid = id as ReadOnlyByteVector;
         return(outid != null?outid:new ReadOnlyByteVector(id));
     }
     if (id == null || version < 2)
     {
         return(null);
     }
     if (!toVersion && (id == FrameType.EQUA || id == FrameType.RVAD || id == FrameType.TRDA || id == FrameType.TSIZ))
     {
         return(null);
     }
     if (version == 2)
     {
         for (int i = 0; i < version2_frames.GetLength(0); i++)
         {
             if (!version2_frames[i, toVersion?1:0].Equals(id))
             {
                 continue;
             }
             return(version2_frames[i, toVersion?0:1]);
         }
     }
     if (version == 3)
     {
         for (int i = 0; i < version3_frames.GetLength(0); i++)
         {
             if (!version3_frames[i, toVersion?1:0].Equals(id))
             {
                 continue;
             }
             return(version3_frames[i, toVersion?0:1]);
         }
     }
     if ((id.Count != 4 && version > 2) || (id.Count != 3 && version == 2))
     {
         return(null);
     }
     return(id is ReadOnlyByteVector?id as ReadOnlyByteVector:new ReadOnlyByteVector(id));
 }
Esempio n. 12
0
 private Item(Item item)
 {
     _type = item._type;
     _key = item._key;
     if (item._data != null)
         _data = new ReadOnlyByteVector (item._data);
     if (item._text != null)
         _text = (string[]) item._text.Clone ();
     _readOnly = item._readOnly;
     _sizeOnDisk = item._sizeOnDisk;
 }
Esempio n. 13
0
		/// <summary>
		///    Populates the current instance by reading in a raw APEv2
		///    item.
		/// </summary>
		/// <param name="data">
		///    A <see cref="ByteVector" /> object containing the item to
		///    read.
		/// </param>
		/// <param name="offset">
		///    A <see cref="int" /> value specifying the offset in
		///    <paramref name="data" /> at which the item data begins.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="data" /> is <see langword="null" />.
		/// </exception>
		/// <exception cref="ArgumentOutOfRangeException">
		///    <paramref name="offset" /> is less than zero.
		/// </exception>
		/// <exception cref="CorruptFileException">
		///    A complete item could not be read.
		/// </exception>
		protected void Parse (ByteVector data, int offset)
		{
			if (data == null)
				throw new ArgumentNullException ("data");
			
			if (offset < 0)
				throw new ArgumentOutOfRangeException ("offset");
			
			
			// 11 bytes is the minimum size for an APE item
			if(data.Count < offset + 11)
				throw new CorruptFileException (
					"Not enough data for APE Item");
			
			uint value_length = data.Mid (offset, 4).ToUInt (false);
			uint flags = data.Mid (offset + 4, 4).ToUInt (false);
			
			ReadOnly = (flags & 1) == 1;
			Type = (ItemType) ((flags >> 1) & 3);
			
			int pos = data.Find (ByteVector.TextDelimiter (
				StringType.UTF8), offset + 8);
			
			key = data.ToString (StringType.UTF8,
				offset + 8, pos - offset - 8);
			
			if (value_length > data.Count - pos - 1)
				throw new CorruptFileException (
					"Invalid data length.");
			
			size_on_disk = pos + 1 + (int) value_length - offset;
			
			if (Type == ItemType.Binary)
				this.data = new ReadOnlyByteVector (
					data.Mid (pos + 1, (int) value_length));
			else
				this.text = data.Mid (pos + 1,
					(int) value_length).ToStrings (
						StringType.UTF8, 0);
		}
Esempio n. 14
0
		private Item (Item item)
		{
			type = item.type;
			key = item.key;
			if (item.data != null)
				data = new ReadOnlyByteVector (item.data);
			if (item.text != null)
				text = (string[]) item.text.Clone ();
			read_only = item.read_only;
			size_on_disk = item.size_on_disk;
		}
Esempio n. 15
0
		/// <summary>
		///    Constructs and initializes a new instance of <see
		///    cref="Item" /> with a specified key and raw data.
		/// </summary>
		/// <param name="key">
		///    A <see cref="string" /> object containing the key to use
		///    for the current instance.
		/// </param>
		/// <param name="value">
		///    A <see cref="StringCollection" /> object containing the
		///    values to store in the new instance.
		/// </param>
		/// <remarks>
		///    This constructor automatically marks the new instance as
		///    <see cref="ItemType.Binary" />.
		/// </remarks>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="key" /> or <paramref name="value" /> is
		///    <see langword="null" />.
		/// </exception>
		/// <seealso cref="Item(string,string[])" />
		public Item (string key, ByteVector value)
		{
			this.key = key;
			this.type = ItemType.Binary;
			
			data = value as ReadOnlyByteVector;
			if (data == null)
				data = new ReadOnlyByteVector (value);
		}
Esempio n. 16
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="FrameHeader" /> by reading it from raw header data
        ///    of a specified version.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the raw
        ///    data to build the new instance from.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> value containing the ID3v2 version
        ///    with which the data in <paramref name="data" /> was
        ///    encoded.
        /// </param>
        /// <remarks>
        ///    If the data size is smaller than the size of a full
        ///    header, the data is just treated as a frame identifier 
        ///    and the remaining values are zeroed.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="data" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    <paramref name="data" /> is smaller than the size of a
        ///    frame identifier or <paramref name="version" /> is less
        ///    than 2 or more than 4.
        /// </exception>
        public FrameHeader(ByteVector data, byte version)
        {
            if (data == null)
                throw new ArgumentNullException ("data");

            flags = 0;
            frame_size = 0;

            if (version < 2 || version > 4)
                throw new CorruptFileException (
                    "Unsupported tag version.");

            if (data.Count < (version == 2 ? 3 : 4))
                throw new CorruptFileException (
                    "Data must contain at least a frame ID.");

            switch (version)
            {
            case 2:
                // Set the frame ID -- the first three bytes
                frame_id = ConvertId (data.Mid (0, 3), version,
                    false);

                // If the full header information was not passed
                // in, do not continue to the steps to parse the
                // frame size and flags.
                if (data.Count < 6)
                    return;

                frame_size = data.Mid (3, 3).ToUInt ();
                return;

            case 3:
                // Set the frame ID -- the first four bytes
                frame_id = ConvertId (data.Mid (0, 4), version,
                    false);

                // If the full header information was not passed
                // in, do not continue to the steps to parse the
                // frame size and flags.
                if (data.Count < 10)
                    return;

                // Store the flags internally as version 2.4.
                frame_size = data.Mid (4, 4).ToUInt ();
                flags = (FrameFlags) (
                    ((data [8] << 7) & 0x7000) |
                    ((data [9] >> 4) & 0x000C) |
                    ((data [9] << 1) & 0x0040));

                return;

            case 4:
                // Set the frame ID -- the first four bytes
                frame_id = new ReadOnlyByteVector (
                    data.Mid (0, 4));

                // If the full header information was not passed
                // in, do not continue to the steps to parse the
                // frame size and flags.
                if (data.Count < 10)
                    return;

                frame_size = SynchData.ToUInt (data.Mid (4, 4));
                flags = (FrameFlags) data.Mid (8, 2).ToUShort ();

                return;

            default:
                throw new CorruptFileException (
                    "Unsupported tag version.");
            }
        }
Esempio n. 17
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="FrameHeader" /> by reading it from raw header data
        ///    of a specified version.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the raw
        ///    data to build the new instance from.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> value containing the ID3v2 version
        ///    with which the data in <paramref name="data" /> was
        ///    encoded.
        /// </param>
        /// <remarks>
        ///    If the data size is smaller than the size of a full
        ///    header, the data is just treated as a frame identifier
        ///    and the remaining values are zeroed.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="data" /> is <see langword="null" />.
        /// </exception>
        /// <exception cref="CorruptFileException">
        ///    <paramref name="data" /> is smaller than the size of a
        ///    frame identifier or <paramref name="version" /> is less
        ///    than 2 or more than 4.
        /// </exception>
        public FrameHeader(ByteVector data, byte version)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            flags      = 0;
            frame_size = 0;

            if (version < 2 || version > 4)
            {
                throw new CorruptFileException(
                          "Unsupported tag version.");
            }

            if (data.Count < (version == 2 ? 3 : 4))
            {
                throw new CorruptFileException(
                          "Data must contain at least a frame ID.");
            }

            switch (version)
            {
            case 2:
                // Set the frame ID -- the first three bytes
                frame_id = ConvertId(data.Mid(0, 3), version,
                                     false);

                // If the full header information was not passed
                // in, do not continue to the steps to parse the
                // frame size and flags.
                if (data.Count < 6)
                {
                    return;
                }

                frame_size = data.Mid(3, 3).ToUInt();
                return;

            case 3:
                // Set the frame ID -- the first four bytes
                frame_id = ConvertId(data.Mid(0, 4), version,
                                     false);

                // If the full header information was not passed
                // in, do not continue to the steps to parse the
                // frame size and flags.
                if (data.Count < 10)
                {
                    return;
                }

                // Store the flags internally as version 2.4.
                frame_size = data.Mid(4, 4).ToUInt();
                flags      = (FrameFlags)(
                    ((data [8] << 7) & 0x7000) |
                    ((data [9] >> 4) & 0x000C) |
                    ((data [9] << 1) & 0x0040));

                return;

            case 4:
                // Set the frame ID -- the first four bytes
                frame_id = new ReadOnlyByteVector(
                    data.Mid(0, 4));

                // If the full header information was not passed
                // in, do not continue to the steps to parse the
                // frame size and flags.
                if (data.Count < 10)
                {
                    return;
                }

                frame_size = SynchData.ToUInt(data.Mid(4, 4));
                flags      = (FrameFlags)data.Mid(8, 2).ToUShort();

                return;

            default:
                throw new CorruptFileException(
                          "Unsupported tag version.");
            }
        }
Esempio n. 18
0
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="Item" /> with a specified key and raw data.
        /// </summary>
        /// <param name="key">
        ///    A <see cref="string" /> object containing the key to use
        ///    for the current instance.
        /// </param>
        /// <param name="value">
        ///    A <see cref="StringCollection" /> object containing the
        ///    values to store in the new instance.
        /// </param>
        /// <remarks>
        ///    This constructor automatically marks the new instance as
        ///    <see cref="ItemType.Binary" />.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="key" /> or <paramref name="value" /> is
        ///    <see langword="null" />.
        /// </exception>
        /// <seealso cref="Item(string,string[])" />
        public Item(string key, ByteVector value)
        {
            _key = key;
            _type = ItemType.Binary;

            _data = value as ReadOnlyByteVector;
            if (_data == null)
                _data = new ReadOnlyByteVector (value);
        }