Beispiel #1
0
 private static byte[] CreateId3v2Frame(string key, string value)
 {
     if (string.IsNullOrEmpty(key))
     {
         throw new ArgumentNullException("key");
     }
     if (string.IsNullOrEmpty(value))
     {
         throw new ArgumentNullException("value");
     }
     if (key.Length != 4)
     {
         throw new ArgumentOutOfRangeException("key", "key " + key + " must be 4 characters long");
     }
     byte[] array = new byte[]
     {
         255,
         254
     };
     byte[] array2 = new byte[3];
     byte[] array3 = new byte[2];
     byte[] array4;
     if (key == "COMM")
     {
         array4 = ByteArrayExtensions.Concat(new byte[][]
         {
             new byte[]
             {
                 1
             },
             array2,
             array3,
             array,
             Encoding.Unicode.GetBytes(value)
         });
     }
     else
     {
         array4 = ByteArrayExtensions.Concat(new byte[][]
         {
             new byte[]
             {
                 1
             },
             array,
             Encoding.Unicode.GetBytes(value)
         });
     }
     return(ByteArrayExtensions.Concat(new byte[][]
     {
         Encoding.UTF8.GetBytes(key),
         Id3v2Tag.FrameSizeToBytes(array4.Length),
         new byte[2],
         array4
     }));
 }
Beispiel #2
0
        /// <summary>
        /// Creates an ID3v2 frame for the given key-value pair.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        static byte[] CreateId3v2Frame(string key, string value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }

            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("value");
            }

            if (key.Length != 4)
            {
                throw new ArgumentOutOfRangeException("key", "key " + key + " must be 4 characters long");
            }

            const byte UnicodeEncoding = 01;                     // encode text in Unicode

            byte[] UnicodeOrder     = new byte[] { 0xff, 0xfe }; // Unicode byte order mark
            byte[] language         = new byte[] { 0, 0, 0 };    // language is empty (only used in COMM -> comment)
            byte[] shortDescription = new byte[] { 0, 0 };       // short description is empty (only used in COMM -> comment)

            byte[] body;
            if (key == "COMM") // comment
            {
                body = ByteArrayExtensions.Concat(
                    new byte[] { UnicodeEncoding },
                    language,
                    shortDescription,
                    UnicodeOrder,
                    Encoding.Unicode.GetBytes(value));
            }
            else
            {
                body = ByteArrayExtensions.Concat(
                    new byte[] { UnicodeEncoding },
                    UnicodeOrder,
                    Encoding.Unicode.GetBytes(value));
            }

            return(ByteArrayExtensions.Concat(
                       // needs review - have converted to UTF8 as Win 8 has no Encoding.ASCII,
                       // need to check what the rules are for ID3v2 tag identifiers
                       Encoding.UTF8.GetBytes(key),
                       FrameSizeToBytes(body.Length),
                       new byte[] { 0, 0 }, // flags
                       body));
        }
Beispiel #3
0
        /// <summary>
        /// Creates the Id3v2 tag header and returns is as a byte array.
        /// </summary>
        /// <param name="frames">The Id3v2 frames that will be included in the file. This is used to calculate the ID3v2 tag size.</param>
        /// <returns></returns>
        static byte[] CreateId3v2TagHeader(IEnumerable <byte[]> frames)
        {
            int size = 0;

            foreach (byte[] frame in frames)
            {
                size += frame.Length;
            }

            byte[] tagHeader = ByteArrayExtensions.Concat(
                Encoding.UTF8.GetBytes("ID3"),
                new byte[] { 3, 0 }, // version
                new byte[] { 0 },    // flags
                GetId3TagHeaderSize(size));
            return(tagHeader);
        }
Beispiel #4
0
        private static byte[] CreateId3v2TagHeader(IEnumerable <byte[]> frames)
        {
            int num = 0;

            foreach (byte[] current in frames)
            {
                num += current.Length;
            }
            byte[][] expr_32 = new byte[4][];
            expr_32[0] = Encoding.UTF8.GetBytes("ID3");
            int arg_50_1 = 1;

            byte[] expr_4C = new byte[2];
            expr_4C[0]        = 3;
            expr_32[arg_50_1] = expr_4C;
            expr_32[2]        = new byte[1];
            expr_32[3]        = Id3v2Tag.GetId3TagHeaderSize(num);
            return(ByteArrayExtensions.Concat(expr_32));
        }
Beispiel #5
0
        private static byte[] CreateId3v2TagHeader(IEnumerable <byte[]> frames)
        {
            int num = 0;

            foreach (byte[] array in frames)
            {
                num += array.Length;
            }
            byte[][] array2 = new byte[4][];
            array2[0] = Encoding.UTF8.GetBytes("ID3");
            byte[][] array3 = array2;
            int      num2   = 1;

            byte[] array4 = new byte[2];
            array4[0]    = 3;
            array3[num2] = array4;
            byte[][] array5 = array2;
            int      num3   = 2;

            byte[] array6 = new byte[1];
            array5[num3] = array6;
            array2[3]    = Id3v2Tag.GetId3TagHeaderSize(num);
            return(ByteArrayExtensions.Concat(array2));
        }
Beispiel #6
0
        private static byte[] CreateId3v2Frame(string key, string value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key");
            }
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("value");
            }
            if (key.Length != 4)
            {
                throw new ArgumentOutOfRangeException("key", "key " + key + " must be 4 characters long");
            }
            byte[] array = new byte[]
            {
                byte.MaxValue,
                254
            };
            byte[] array2 = new byte[3];
            byte[] array3 = array2;
            byte[] array4 = new byte[2];
            byte[] array5 = array4;
            byte[] array6;
            if (key == "COMM")
            {
                array6 = ByteArrayExtensions.Concat(new byte[][]
                {
                    new byte[]
                    {
                        1
                    },
                    array3,
                    array5,
                    array,
                    Encoding.Unicode.GetBytes(value)
                });
            }
            else
            {
                array6 = ByteArrayExtensions.Concat(new byte[][]
                {
                    new byte[]
                    {
                        1
                    },
                    array,
                    Encoding.Unicode.GetBytes(value)
                });
            }
            byte[][] array7 = new byte[4][];
            array7[0] = Encoding.UTF8.GetBytes(key);
            array7[1] = Id3v2Tag.FrameSizeToBytes(array6.Length);
            byte[][] array8 = array7;
            int      num    = 2;

            byte[] array9 = new byte[2];
            array8[num] = array9;
            array7[3]   = array6;
            return(ByteArrayExtensions.Concat(array7));
        }