예제 #1
0
        public void parse(String line, ParseState state)
        {
            if (state.isMedia())
            {
                throw ParseException.create(ParseExceptionType.MASTER_IN_MEDIA, mTagParser.getTag());
            }

            state.setMaster();
            mLineParser.parse(line, state);
        }
예제 #2
0
        public override Playlist parse()
        {
            validateAvailable();

            ParseState state           = new ParseState(mEncoding);
            LineParser playlistParser  = new PlaylistLineParser();
            LineParser trackLineParser = new TrackLineParser();

            try
            {
                while (mScanner.hasNext())
                {
                    String line = mScanner.next();
                    checkWhitespace(line);

                    if (line.Length == 0 || isComment(line))
                    {
                        continue;
                    }
                    else
                    {
                        if (isExtTag(line))
                        {
                            String tagKey = getExtTagKey(line);
                            mExtTagParsers.TryGetValue(tagKey, out IExtTagParser tagParser);

                            if (tagParser == null)
                            {
                                //To support forward compatibility, when parsing Playlists, Clients
                                //MUST:
                                //o  ignore any unrecognized tags.
                                if (mParsingMode.allowUnknownTags)
                                {
                                    tagParser = ExtLineParser.EXT_UNKNOWN_HANDLER;
                                }
                                else
                                {
                                    throw ParseException.create(ParseExceptionType.UNSUPPORTED_EXT_TAG_DETECTED, tagKey, line);
                                }
                            }

                            tagParser.parse(line, state);

                            if (state.isMedia() && state.getMedia().endOfList)
                            {
                                break;
                            }
                        }
                        else if (state.isMaster())
                        {
                            playlistParser.parse(line, state);
                        }
                        else if (state.isMedia())
                        {
                            trackLineParser.parse(line, state);
                        }
                        else
                        {
                            throw ParseException.create(ParseExceptionType.UNKNOWN_PLAYLIST_TYPE, line);
                        }
                    }
                }

                Playlist           playlist   = state.buildPlaylist();
                PlaylistValidation validation = PlaylistValidation.from(playlist, mParsingMode);

                if (validation.isValid())
                {
                    return(playlist);
                }
                else
                {
                    throw new PlaylistException(mScanner.getInput(), validation.getErrors());
                }
            }
            catch (ParseException exception)
            {
                exception.setInput(mScanner.getInput());
                throw exception;
            }
        }