summaryrefslogtreecommitdiffstats
path: root/mpvcore/playlist_parser.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-08-25 20:40:21 +0200
committerwm4 <wm4@nowhere>2013-08-26 10:09:45 +0200
commit8be9c49fcd8b23463199036eda5fc290ded6d078 (patch)
tree285f8a1cdcd89c8da9f8a50631a1af5176a783b1 /mpvcore/playlist_parser.c
parentddc973344685b8fee1d7b00e23ba93692d56d7c9 (diff)
downloadmpv-8be9c49fcd8b23463199036eda5fc290ded6d078.tar.bz2
mpv-8be9c49fcd8b23463199036eda5fc290ded6d078.tar.xz
core: add a playlist demuxer
Modeled after the old playlist_parser.c, but actually new code, and it works a bit differently. Demuxers (and sometimes streams) are the component that should be used to open files and to determine the file format. This was already done for subtitles, but playlists still use a separate code path.
Diffstat (limited to 'mpvcore/playlist_parser.c')
-rw-r--r--mpvcore/playlist_parser.c69
1 files changed, 17 insertions, 52 deletions
diff --git a/mpvcore/playlist_parser.c b/mpvcore/playlist_parser.c
index 4573e133ae..920a004c50 100644
--- a/mpvcore/playlist_parser.c
+++ b/mpvcore/playlist_parser.c
@@ -16,6 +16,11 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+/*
+ * Warning: this is outdated, crappy code. It is used only for --playlist.
+ * New or cleaned up code should be added to demux_playlist.c instead.
+ */
+
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
@@ -406,43 +411,6 @@ static bool parse_ref_ini(play_tree_parser_t* p) {
return true;
}
-static bool parse_m3u(play_tree_parser_t* p) {
- char* line;
-
- mp_msg(MSGT_PLAYTREE,MSGL_V,"Trying extended m3u playlist...\n");
- if (!(line = play_tree_parser_get_line(p)))
- return NULL;
- strstrip(line);
- if(strcasecmp(line,"#EXTM3U"))
- return NULL;
- mp_msg(MSGT_PLAYTREE,MSGL_V,"Detected extended m3u playlist format\n");
- play_tree_parser_stop_keeping(p);
-
- while((line = play_tree_parser_get_line(p)) != NULL) {
- strstrip(line);
- if(line[0] == '\0')
- continue;
- /* EXTM3U files contain such lines:
- * #EXTINF:<seconds>, <title>
- * followed by a line with the filename
- * for now we have no place to put that
- * so we just skip that extra-info ::atmos
- */
- if(line[0] == '#') {
-#if 0 /* code functional */
- if(strncasecmp(line,"#EXTINF:",8) == 0) {
- mp_msg(MSGT_PLAYTREE,MSGL_INFO,"[M3U] Duration: %dsec Title: %s\n",
- strtol(line+8,&line,10), line+2);
- }
-#endif
- continue;
- }
- playlist_add_file(p->pl, line);
- }
-
- return true;
-}
-
static bool parse_smil(play_tree_parser_t* p) {
int entrymode=0;
char* line,source[512],*pos,*s_start,*s_end,*src_line;
@@ -697,9 +665,11 @@ err_out:
return success;
}
-struct playlist *playlist_parse_file(const char *file)
+static struct playlist *do_parse(struct stream* stream, bool forced);
+
+struct playlist *playlist_parse_file(const char *file, struct MPOpts *opts)
{
- stream_t *stream = stream_open(file, NULL);
+ stream_t *stream = stream_open(file, opts);
if(!stream) {
mp_msg(MSGT_PLAYTREE,MSGL_ERR,
"Error while opening playlist file %s: %s\n",
@@ -710,7 +680,7 @@ struct playlist *playlist_parse_file(const char *file)
mp_msg(MSGT_PLAYTREE, MSGL_V,
"Parsing playlist file %s...\n", file);
- struct playlist *ret = playlist_parse(stream);
+ struct playlist *ret = do_parse(stream, true);
free_stream(stream);
playlist_add_base_path(ret, mp_dirname(file));
@@ -723,7 +693,6 @@ typedef bool (*parser_fn)(play_tree_parser_t *);
static const parser_fn pl_parsers[] = {
parse_asx,
parse_pls,
- parse_m3u,
parse_ref_ini,
parse_smil,
parse_nsc,
@@ -740,7 +709,13 @@ static struct playlist *do_parse(struct stream* stream, bool forced)
};
bool success = false;
- if (play_tree_parser_get_line(&p) != NULL) {
+ struct demuxer *pl_demux = demux_open(stream, "playlist", NULL, stream->opts);
+ if (pl_demux && pl_demux->playlist) {
+ playlist_transfer_entries(p.pl, pl_demux->playlist);
+ success = true;
+ }
+ free_demuxer(pl_demux);
+ 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)
@@ -765,13 +740,3 @@ static struct playlist *do_parse(struct stream* stream, bool forced)
return p.pl;
}
-
-struct playlist *playlist_parse(struct stream* stream)
-{
- return do_parse(stream, true);
-}
-
-struct playlist *playlist_probe_and_parse(struct stream* stream)
-{
- return do_parse(stream, false);
-}