Ejemplo n.º 1
0
        /// <summary>
        /// Add Frame information to where it must store
        /// </summary>
        /// <param name="Data">FileStream contain Frame</param>
        /// <param name="FrameID">FrameID of frame</param>
        /// <param name="Length">Maximum available length to read</param>
        /// <param name="Flags">Flags of frame</param>
        private bool AddFrame(FileStreamEx Data, string FrameID, int Length, FrameFlags Flags)
        {
            // NOTE: All FrameIDs must be capital letters
            if (!FramesInfo.IsValidFrameID(FrameID))
            {
                AddError(new ID3Error("nonValid Frame found and dropped", FrameID));
                return false;
            }

            int IsText = FramesInfo.IsTextFrame(FrameID, _ver.Minor);
            if (IsText == 1)
            {
                TextFrame TempTextFrame = new TextFrame(FrameID, Flags, Data, Length);
                if (TempTextFrame.IsReadableFrame)
                {
                    _TextFrames.Add(TempTextFrame);
                    return true;
                }
                return false;
            }

            if (IsText == 2)
            {
                UserTextFrame TempUserTextFrame = new UserTextFrame(FrameID, Flags, Data, Length);
                if (TempUserTextFrame.IsReadableFrame)
                {
                    _UserTextFrames.Add(TempUserTextFrame);
                    return true;
                }
                return false;
            }

            switch (FrameID)
            {
                case "UFID":
                case "PRIV":
                    PrivateFrame TempPrivateFrame = new PrivateFrame(FrameID, Flags, Data, Length);
                    if (TempPrivateFrame.IsReadableFrame)
                    {
                        _PrivateFrames.Add(TempPrivateFrame); return true;
                    }
                    else
                        AddError(new ID3Error(TempPrivateFrame.ErrorMessage, FrameID));
                    break;
                case "USLT":
                case "COMM":
                    TextWithLanguageFrame TempTextWithLangFrame = new TextWithLanguageFrame(FrameID, Flags, Data, Length);
                    if (TempTextWithLangFrame.IsReadableFrame)
                    { _TextWithLangFrames.Add(TempTextWithLangFrame); return true; }
                    else
                        AddError(new ID3Error(TempTextWithLangFrame.ErrorMessage, FrameID));
                    break;
                case "SYLT":
                    SynchronisedText TempSynchronisedText = new SynchronisedText(FrameID, Flags, Data, Length);
                    if (TempSynchronisedText.IsReadableFrame)
                    { _SynchronisedTextFrames.Add(TempSynchronisedText); return true; }
                    else
                        AddError(new ID3Error(TempSynchronisedText.ErrorMessage, FrameID));
                    break;
                case "GEOB":
                    GeneralFileFrame TempGeneralFileFrame = new GeneralFileFrame(FrameID, Flags, Data, Length);
                    if (TempGeneralFileFrame.IsReadableFrame)
                    { _EncapsulatedObjectFrames.Add(TempGeneralFileFrame); return true; }
                    else
                        AddError(new ID3Error(TempGeneralFileFrame.ErrorMessage, FrameID));
                    break;
                case "POPM":
                    PopularimeterFrame TempPopularimeterFrame = new PopularimeterFrame(FrameID, Flags, Data, Length);
                    if (TempPopularimeterFrame.IsReadableFrame)
                    { _PopularimeterFrames.Add(TempPopularimeterFrame); return true; }
                    else
                        AddError(new ID3Error(TempPopularimeterFrame.ErrorMessage, FrameID));
                    break;
                case "AENC":
                    AudioEncryptionFrame TempAudioEncryptionFrame = new AudioEncryptionFrame(FrameID, Flags, Data, Length);
                    if (TempAudioEncryptionFrame.IsReadableFrame)
                    { _AudioEncryptionFrames.Add(TempAudioEncryptionFrame); return true; }
                    else
                        AddError(new ID3Error(TempAudioEncryptionFrame.ErrorMessage, FrameID));
                    break;
                case "USER":
                    TermOfUseFrame TempTermOfUseFrame = new TermOfUseFrame(FrameID, Flags, Data, Length);
                    if (TempTermOfUseFrame.IsReadableFrame)
                    { _TermOfUseFrames.Add(TempTermOfUseFrame); return true; }
                    else
                        AddError(new ID3Error(TempTermOfUseFrame.ErrorMessage, FrameID));
                    break;
                case "ENCR":
                case "GRID":
                    DataWithSymbolFrame TempDataWithSymbolFrame = new DataWithSymbolFrame(FrameID, Flags, Data, Length);
                    if (TempDataWithSymbolFrame.IsReadableFrame)
                    { _DataWithSymbolFrames.Add(TempDataWithSymbolFrame); return true; }
                    else
                        AddError(new ID3Error(TempDataWithSymbolFrame.ErrorMessage, FrameID));
                    break;
                case "LINK":
                    LinkFrame LF = new LinkFrame(FrameID, Flags, Data, Length);
                    if (LF.IsReadableFrame)
                    {
                        _LinkFrames.Add(LF);
                        if (_LoadLinkedFrames)
                        { LoadFrameFromFile(LF.FrameIdentifier, LF.URL); return true; }
                    }
                    else
                        AddError(new ID3Error(LF.ErrorMessage, FrameID));
                    break;
                case "APIC":
                    AttachedPictureFrame TempAttachedPictureFrame = new AttachedPictureFrame(FrameID, Flags, Data, Length);
                    if (TempAttachedPictureFrame.IsReadableFrame)
                    { _AttachedPictureFrames.Add(TempAttachedPictureFrame); return true; }
                    else
                        AddError(new ID3Error(TempAttachedPictureFrame.ErrorMessage, FrameID));
                    break;
                case "MCDI":
                    BinaryFrame MCDI = new BinaryFrame(FrameID, Flags, Data, Length);
                    if (MCDI.IsReadableFrame)
                    { _MCDIFrame = MCDI; return true; }
                    else
                        AddError(new ID3Error(MCDI.ErrorMessage, FrameID));
                    break;
                case "SYTC":
                    SynchronisedTempoFrame SYTC = new SynchronisedTempoFrame(FrameID, Flags, Data, Length);
                    if (SYTC.IsReadableFrame)
                    { _SYTCFrame = SYTC; return true; }
                    else
                        AddError(new ID3Error(SYTC.ErrorMessage, FrameID));
                    break;
                case "PCNT":
                    PlayCounterFrame PCNT = new PlayCounterFrame(FrameID, Flags, Data, Length);
                    if (PCNT.IsReadableFrame)
                    { _PCNTFrame = PCNT; return true; }
                    else
                        AddError(new ID3Error(PCNT.ErrorMessage, FrameID));
                    break;
                case "RBUF":
                    RecomendedBufferSizeFrame RBUF = new RecomendedBufferSizeFrame(FrameID, Flags, Data, Length);
                    if (RBUF.IsReadableFrame)
                    { _RBUFFrame = RBUF; return true; }
                    else
                        AddError(new ID3Error(RBUF.ErrorMessage, FrameID));
                    break;
                case "OWNE":
                    OwnershipFrame OWNE = new OwnershipFrame(FrameID, Flags, Data, Length);
                    if (OWNE.IsReadableFrame)
                    { _OWNEFrame = OWNE; return true; }
                    else
                        AddError(new ID3Error(OWNE.ErrorMessage, FrameID));
                    break;
                case "COMR":
                    CommercialFrame COMR = new CommercialFrame(FrameID, Flags, Data, Length);
                    if (COMR.IsReadableFrame)
                    { _COMRFrame = COMR; return true; }
                    else
                        AddError(new ID3Error(COMR.ErrorMessage, FrameID));
                    break;
                case "RVRB":
                    ReverbFrame RVRB = new ReverbFrame(FrameID, Flags, Data, Length);
                    if (RVRB.IsReadableFrame)
                    { _RVRBFrame = RVRB; return true; }
                    else
                        AddError(new ID3Error(RVRB.ErrorMessage, FrameID));
                    break;
                case "EQUA":
                    Equalisation EQUA = new Equalisation(FrameID, Flags, Data, Length);
                    if (EQUA.IsReadableFrame)
                    { _EQUAFrame = EQUA; return true; }
                    else
                        AddError(new ID3Error(EQUA.ErrorMessage, FrameID));
                    break;
                case "RVAD":
                    RelativeVolumeFrame RVAD = new RelativeVolumeFrame(FrameID, Flags, Data, Length);
                    if (RVAD.IsReadableFrame)
                    { _RVADFrame = RVAD; return true; }
                    else
                        AddError(new ID3Error(RVAD.ErrorMessage, FrameID));
                    break;
                case "ETCO":
                    EventTimingCodeFrame ETCO = new EventTimingCodeFrame(FrameID, Flags, Data, Length);
                    if (ETCO.IsReadableFrame)
                    { _ETCOFrame = ETCO; return true; }
                    else
                        AddError(new ID3Error(ETCO.ErrorMessage, FrameID));
                    break;
                case "POSS":
                    PositionSynchronisedFrame POSS = new PositionSynchronisedFrame(FrameID, Flags, Data, Length);
                    if (POSS.IsReadableFrame)
                    { _POSSFrame = POSS; return true; }
                    else
                        AddError(new ID3Error(POSS.ErrorMessage, FrameID));
                    break;
                default:
                    BinaryFrame Temp = new BinaryFrame(FrameID, Flags, Data, Length);
                    if (Temp.IsReadableFrame)
                    { _UnknownFrames.Add(Temp); return true; }
                    else
                        AddError(new ID3Error(Temp.ErrorMessage, FrameID));
                    break;
                // TODO: Mpeg Location
            }

            return false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set text of specific TextFrame
        /// </summary>
        /// <param name="FrameID">FrameID</param>
        /// <param name="Text">Text to set</param>
        /// <param name="TextEncoding">Enxoding of text</param>
        /// <param name="ver">minor version of ID3v2</param>
        public void SetTextFrame(string FrameID, string Text)
        {
            if (!FramesInfo.IsValidFrameID(FrameID))
                return;

            for (int i = 0; i < _TextFrames.Count - 1; i++)
            {
                if (_TextFrames.Items[i].FrameID == FrameID)
                {
                    _TextFrames.RemoveAt(i);
                    break;
                }
            }

            if (Text != "")
            {
                FrameFlags flag = new FrameFlags();
                TextEncodings encoding;
                if (Frame.IsAscii(Text))
                {
                    encoding = TextEncodings.Ascii;
                }
                else
                {
                    encoding = _DefaultUnicodeEncoding;
                }

                int ver=_ver.Minor;
                TextFrame frame= new TextFrame(FrameID, flag,Text, encoding,ver);
                _TextFrames.Add(frame);
            }
        }