diff options
author | wm4 <wm4@nowhere> | 2014-01-19 20:54:00 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2014-01-19 21:15:55 +0100 |
commit | 7c34e0226fb81693e644b613d18b530c15b06505 (patch) | |
tree | 84fb5118cfa2eb8e6f48bd801fe972ff4fe2adf1 /demux | |
parent | ef006dcae6b07a8abb7fed847fd4a9e647109584 (diff) | |
download | mpv-7c34e0226fb81693e644b613d18b530c15b06505.tar.bz2 mpv-7c34e0226fb81693e644b613d18b530c15b06505.tar.xz |
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.
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux_playlist.c | 25 |
1 files changed, 23 insertions, 2 deletions
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) { |