Beispiel #1
0
        public id3v2FrameHeader(byte[] header)
        {
            if (header.Length == 10)
            {
                try
                {
                    byte[] t_id   = new byte[4];
                    byte[] t_size = new byte[4];

                    for (int i = 0; i < 4; i++)
                    {
                        t_id[i]   = header[i];
                        t_size[i] = header[i + 4];
                    }
                    if (t_size[0] == 0)
                    {
                        FrameSize = Id3Read.BytesToInt(t_size);

                        if (FrameSize != 0 && FrameSize < 1000000)
                        {
                            FrameID = Id3Read.ASCIIByteArrayToStr(t_id);
                            //Flags
                            FrameAlterPreservation = (header[8] & 64) == 64 ? true : false;
                            FileAlterPreservation  = (header[8] & 32) == 32 ? true : false;
                            ReadOnly             = (header[8] & 16) == 16 ? true : false;
                            GroupIdentity        = (header[9] & 64) == 64 ? true : false;
                            Compressed           = (header[9] & 8) == 8 ? true : false;
                            Encrypted            = (header[9] & 4) == 4 ? true : false;
                            Unsynchronised       = (header[9] & 2) == 2 ? true : false;
                            DataLengthIdentifier = (header[9] & 1) == 1 ? true : false;
                            FrameOk = true;
                        }
                        else
                        {
                            FrameOk = false;
                        }
                    }
                    else
                    {
                        FrameOk = false;
                    }
                }
                catch (Exception e)
                {
                    FrameOk = false;
                }
            }
            else
            {
                FrameOk = false;
            }
        }
Beispiel #2
0
        public id3v2Frame(BinaryReader br)
        {
            FrameHeader = new id3v2FrameHeader(br.ReadBytes(10));
            if (FrameHeader.FrameOk)
            {
                FrameID = FrameHeader.FrameID;
                try
                {
                    //byte enc = br.ReadByte();
                    //if (enc == 0 || 1 == 1)
                    //{
                    byte encoding = br.ReadByte();
                    switch (encoding)
                    {
                    case 0:

                        data      = br.ReadBytes(FrameHeader.FrameSize - 1);
                        FrameData = Id3Read.ASCIIByteArrayToStr(data).TrimEnd(paddingchars).TrimStart(paddingchars);
                        break;

                    case 1:

                        data      = br.ReadBytes(FrameHeader.FrameSize - 1);
                        FrameData = Id3Read.UNICODEByteArrayToStr(data).TrimEnd(paddingchars).TrimStart(paddingchars);
                        break;

                    default:
                        data      = br.ReadBytes(FrameHeader.FrameSize - 1);
                        FrameData = Id3Read.ASCIIByteArrayToStr(data).TrimEnd(paddingchars).TrimStart(paddingchars);
                        break;
                    }
                    FrameOk = true;

                    /*
                     * int c = 0;
                     * byte[] temp_data = new byte[data.Length];
                     * for (int i = 0; i < data.Length; i++)
                     * {
                     *  if (!(data[i] == 0 && i == 0) && !(data[i]== 0 && i == data.Length-1))
                     *  {
                     *      temp_data[c] = data[i];
                     *      c++;
                     *
                     *  }
                     * }
                     *
                     * if (c == data.Length)
                     * {
                     *  FrameData = Id3Read.ByteArrayToStr(data);
                     *  FrameOk = true;
                     * }
                     * else
                     * {
                     *
                     *  byte[] temp2_data = new byte[c];
                     *  for (int i = 0; i < c; i++)
                     *  {
                     *      temp2_data[i] = temp_data[i];
                     *  }
                     *
                     *  FrameData = Id3Read.ByteArrayToStr(temp2_data);
                     *  FrameOk = true;
                     * }
                     * */
                    //}
                }
                catch (Exception e)
                {
                    FrameOk = false;
                }
            }
        }
Beispiel #3
0
        public void read(FileStream fs)
        {
            try
            {
                if (fs.Length < 128)
                {
                    return;
                }
                //Check for ID3v1 tag...
                byte[] temp = new byte[30];
                fs.Position = fs.Length - 128;
                BinaryReader br           = new BinaryReader(fs);
                char[]       paddingchars = { ' ', '0', '\0' };

                if (Id3Read.ASCIIByteArrayToStr(br.ReadBytes(3)) == "TAG")
                {
                    //Read Title
                    temp  = br.ReadBytes(30);
                    Title = Id3Read.ASCIIByteArrayToStr(temp).TrimEnd(paddingchars);

                    //Read Artist
                    temp   = br.ReadBytes(30);
                    Artist = Id3Read.ASCIIByteArrayToStr(temp).TrimEnd(paddingchars);

                    //Read Album
                    temp  = br.ReadBytes(30);
                    Album = Id3Read.ASCIIByteArrayToStr(temp).TrimEnd(paddingchars);

                    //Read Year
                    temp = br.ReadBytes(4);
                    Year = Id3Read.ASCIIByteArrayToStr(temp).TrimEnd(paddingchars);

                    //Read Comment
                    temp    = br.ReadBytes(30);
                    Comment = Id3Read.ASCIIByteArrayToStr(temp).TrimEnd(paddingchars);

                    //Read Track (Id3v1.1)
                    //temp = br.ReadBytes(2);
                    if (temp[28] == 0)
                    {
                        Track = temp[29].ToString();
                    }

                    //Read Genre
                    temp[0] = br.ReadByte();
                    if (temp[0] < 81)
                    {
                        try
                        {
                            Genre = Id3Read.GenreConv[temp[0]];
                        }
                        catch (Exception e)
                        {
                            throw (e);
                        }
                    }
                }
            }
            catch
            {
            }
        }