From 7c34e0226fb81693e644b613d18b530c15b06505 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 19 Jan 2014 20:54:00 +0100 Subject: demux_playlist: move parser for plaintext playlists This was implemented in playlist_parser.c. To make it use the improved implementation of stream_read_line(), move it to demux_playlist.c. --- common/playlist_parser.c | 20 -------------------- demux/demux_playlist.c | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/common/playlist_parser.c b/common/playlist_parser.c index d871854dbb..0c466a135b 100644 --- a/common/playlist_parser.c +++ b/common/playlist_parser.c @@ -364,23 +364,6 @@ static bool parse_smil(play_tree_parser_t* p) { return true; } -static bool parse_textplain(play_tree_parser_t* p) { - char* line; - - MP_VERBOSE(p, "Trying plaintext playlist...\n"); - play_tree_parser_stop_keeping(p); - - while((line = play_tree_parser_get_line(p)) != NULL) { - strstrip(line); - if(line[0] == '\0' || line[0] == '#' || (line[0] == '/' && line[1] == '/')) - continue; - - playlist_add_file(p->pl,line); - } - - return true; -} - /** * \brief decode the base64 used in nsc files * \param in input string, 0-terminated @@ -524,7 +507,6 @@ static const parser_fn pl_parsers[] = { parse_asx, parse_smil, parse_nsc, - parse_textplain }; @@ -548,8 +530,6 @@ static struct playlist *do_parse(struct stream* stream, bool forced, if (!success && play_tree_parser_get_line(&p) != NULL) { for (int n = 0; n < sizeof(pl_parsers) / sizeof(pl_parsers[0]); n++) { play_tree_parser_reset(&p); - if (pl_parsers[n] == parse_textplain && !forced) - break; if (pl_parsers[n](&p)) { success = true; break; diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c index b7a752468b..2f4fb130ef 100644 --- a/demux/demux_playlist.c +++ b/demux/demux_playlist.c @@ -26,12 +26,14 @@ #define PROBE_SIZE (8 * 1024) struct pl_parser { + struct mp_log *log; struct stream *s; char buffer[8 * 1024]; int utf16; struct playlist *pl; bool error; bool probing; + bool force; }; static char *pl_get_line0(struct pl_parser *p) @@ -134,6 +136,22 @@ static int parse_pls(struct pl_parser *p) return 0; } +static int parse_txt(struct pl_parser *p) +{ + if (!p->force) + return -1; + if (p->probing) + return 0; + MP_WARN(p, "Reading plaintext playlist.\n"); + while (!pl_eof(p)) { + bstr line = bstr_strip(pl_get_line(p)); + if (line.len == 0) + continue; + pl_add(p, line); + } + return 0; +} + struct pl_format { const char *name; int (*parse)(struct pl_parser *p); @@ -144,9 +162,10 @@ static const struct pl_format formats[] = { {"ini", parse_ref_init}, {"mov", parse_mov_rtsptext}, {"pls", parse_pls}, + {"txt", parse_txt}, }; -static const struct pl_format *probe_pl(struct pl_parser *p, bool force) +static const struct pl_format *probe_pl(struct pl_parser *p) { int64_t start = stream_tell(p->s); for (int n = 0; n < MP_ARRAY_SIZE(formats); n++) { @@ -163,13 +182,15 @@ static int open_file(struct demuxer *demuxer, enum demux_check check) bool force = check < DEMUX_CHECK_UNSAFE || check == DEMUX_CHECK_REQUEST; struct pl_parser *p = talloc_zero(NULL, struct pl_parser); + p->log = demuxer->log; p->pl = talloc_zero(p, struct playlist); bstr probe_buf = stream_peek(demuxer->stream, PROBE_SIZE); p->s = open_memory_stream(probe_buf.start, probe_buf.len); p->utf16 = stream_skip_bom(p->s); + p->force = force; p->probing = true; - const struct pl_format *fmt = probe_pl(p, force); + const struct pl_format *fmt = probe_pl(p); free_stream(p->s); playlist_clear(p->pl); if (!fmt) { -- cgit v1.2.3