Example #1
0
        private async Task LoadAsync(PlaylistTokenizer tokenizer)
        {
            Clear();

            // Read header
            var token = await tokenizer.ReadAsync().ConfigureAwait(false);

            if (token == null || token.Type != PlaylistTokenType.Header)
            {
                throw new PlaylistDocumentLoadException();
            }

            var context = new LoadContext();

            while (!tokenizer.EndOfStream)
            {
                token = await tokenizer.ReadAsync().ConfigureAwait(false);

                if (token == null)
                {
                    break;
                }
                context.Token = token;

                switch (token.Type)
                {
                case PlaylistTokenType.Comment:
                    continue;

                case PlaylistTokenType.Header:
                    throw new PlaylistDocumentLoadException("Unexpected HEADER.");

                case PlaylistTokenType.Tag:
                    ParseTagToken(context);
                    break;

                case PlaylistTokenType.Uri:
                    ParseUriToken(context);
                    break;

                default:
                    throw new NotImplementedException($"Playlist token type of '{token.Type}' is not implemented.");
                }
            }
        }
Example #2
0
 /// <summary>
 /// Loads the playlist from a stream.
 /// </summary>
 /// <exception cref="PlaylistDocumentLoadException" />
 public Task LoadAsync(StreamReader reader)
 {
     using var tokenizer = new PlaylistTokenizer(reader);
     return(LoadAsync(tokenizer));
 }