Beispiel #1
0
        public override Playlist parse()
        {
            validateAvailable();

            ParseState      state           = new ParseState(mEncoding);
            TrackLineParser trackLineParser = new TrackLineParser();

            try
            {
                state.setMedia();

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

                    if (line.Length == 0 || isComment(line))
                    {
                        continue;
                    }
                    else
                    {
                        trackLineParser.parse(line, state);
                    }
                }

                Playlist playlist = new Playlist.Builder()
                                    .withMediaPlaylist(new MediaPlaylist.Builder()
                                                       .withTracks(state.getMedia().tracks)
                                                       .build())
                                    .build();

                PlaylistValidation validation = PlaylistValidation.from(playlist);

                if (validation.isValid())
                {
                    return(playlist);
                }
                else
                {
                    throw new PlaylistException(mScanner.getInput(), validation.getErrors());
                }
            }
            catch (ParseException exception)
            {
                exception.setInput(mScanner.getInput());
                throw exception;
            }
        }
Beispiel #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;
            }
        }