summaryrefslogtreecommitdiffstats
path: root/mpvcore
diff options
context:
space:
mode:
Diffstat (limited to 'mpvcore')
-rw-r--r--mpvcore/asxparser.c13
-rw-r--r--mpvcore/command.c2
-rw-r--r--mpvcore/mplayer.c45
-rw-r--r--mpvcore/options.c2
-rw-r--r--mpvcore/options.h1
-rw-r--r--mpvcore/parser-mpcmd.c3
-rw-r--r--mpvcore/playlist_parser.c69
-rw-r--r--mpvcore/playlist_parser.h9
-rw-r--r--mpvcore/timeline/tl_cue.c2
9 files changed, 59 insertions, 87 deletions
diff --git a/mpvcore/asxparser.c b/mpvcore/asxparser.c
index 804e796f85..16646b9347 100644
--- a/mpvcore/asxparser.c
+++ b/mpvcore/asxparser.c
@@ -449,7 +449,6 @@ asx_parse_ref(ASX_Parser_t* parser, char** attribs) {
static void asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs) {
char *href;
- stream_t* stream;
if(parser->deep > 0)
return;
@@ -459,16 +458,8 @@ static void asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs
asx_warning_attrib_required(parser,"ENTRYREF" ,"HREF" );
return;
}
- stream=stream_open(href, NULL);
- if(!stream) {
- mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Can't open playlist %s\n",href);
- free(href);
- return;
- }
-
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Not recursively loading playlist %s\n",href);
-
- free_stream(stream);
+ mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Recursive playlist %s\n", href);
+ playlist_add_file(parser->pl, href);
free(href);
//mp_msg(MSGT_PLAYTREE,MSGL_INFO,"Need to implement entryref\n");
}
diff --git a/mpvcore/command.c b/mpvcore/command.c
index a9a96e6ebb..db4b2a7a9c 100644
--- a/mpvcore/command.c
+++ b/mpvcore/command.c
@@ -2319,7 +2319,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
case MP_CMD_LOADLIST: {
char *filename = cmd->args[0].v.s;
bool append = cmd->args[1].v.i;
- struct playlist *pl = playlist_parse_file(filename);
+ struct playlist *pl = playlist_parse_file(filename, opts);
if (pl) {
if (!append)
playlist_clear(mpctx->playlist);
diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c
index 2d5265d41b..43a7b5d9b0 100644
--- a/mpvcore/mplayer.c
+++ b/mpvcore/mplayer.c
@@ -4133,6 +4133,19 @@ static void stream_dump(struct MPContext *mpctx)
}
}
+// Replace the current playlist entry with playlist contents. Moves the entries
+// from the given playlist pl, so the entries don't actually need to be copied.
+static void transfer_playlist(struct MPContext *mpctx, struct playlist *pl)
+{
+ if (mpctx->demuxer->playlist->first) {
+ playlist_transfer_entries(mpctx->playlist, mpctx->demuxer->playlist);
+ if (mpctx->playlist->current)
+ playlist_remove(mpctx->playlist, mpctx->playlist->current);
+ } else {
+ MP_WARN(mpctx, "Empty playlist!\n");
+ }
+}
+
// Start playing the current playlist entry.
// Handle initialization and deinitialization.
static void play_current_file(struct MPContext *mpctx)
@@ -4213,11 +4226,7 @@ static void play_current_file(struct MPContext *mpctx)
mpctx->resolve_result = resolve_url(stream_filename, opts);
if (mpctx->resolve_result) {
if (mpctx->resolve_result->playlist) {
- // Replace entry with playlist contents
- playlist_transfer_entries(mpctx->playlist,
- mpctx->resolve_result->playlist);
- if (mpctx->playlist->current)
- playlist_remove(mpctx->playlist, mpctx->playlist->current);
+ transfer_playlist(mpctx, mpctx->resolve_result->playlist);
goto terminate_playback;
}
stream_filename = mpctx->resolve_result->url;
@@ -4258,12 +4267,29 @@ goto_reopen_demuxer: ;
mpctx->demuxer = demux_open(mpctx->stream, opts->demuxer_name, NULL, opts);
mpctx->master_demuxer = mpctx->demuxer;
-
if (!mpctx->demuxer) {
mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "Failed to recognize file format.\n");
goto terminate_playback;
}
+ MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources, mpctx->demuxer);
+
+ mpctx->initialized_flags |= INITIALIZED_DEMUXER;
+
+ if (mpctx->demuxer->playlist) {
+ if (mpctx->demuxer->stream->safe_origin || opts->load_unsafe_playlists) {
+ transfer_playlist(mpctx, mpctx->demuxer->playlist);
+ } else {
+ MP_ERR(mpctx, "\nThis looks like a playlist, but playlist support "
+ "will not be used automatically.\nThe main problem with "
+ "playlist safety is that playlist entries can be arbitrary,\n"
+ "and an attacker could make mpv poke around in your local "
+ "filesystem or network.\nUse --playlist=file or the "
+ "--load-unsafe-playlists option to load them anyway.\n");
+ }
+ goto terminate_playback;
+ }
+
if (mpctx->demuxer->matroska_data.ordered_chapters)
build_ordered_chapter_timeline(mpctx);
@@ -4275,11 +4301,6 @@ goto_reopen_demuxer: ;
print_timeline(mpctx);
- if (!mpctx->num_sources) {
- MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources,
- mpctx->demuxer);
- }
-
if (mpctx->timeline) {
// With Matroska, the "master" file usually dictates track layout etc.
// On the contrary, the EDL and CUE demuxers are empty wrappers, as
@@ -4298,8 +4319,6 @@ goto_reopen_demuxer: ;
if (mpctx->timeline)
timeline_set_part(mpctx, mpctx->timeline_part, true);
- mpctx->initialized_flags |= INITIALIZED_DEMUXER;
-
add_subtitle_fonts_from_sources(mpctx);
open_subtitles_from_options(mpctx);
diff --git a/mpvcore/options.c b/mpvcore/options.c
index 733b104a46..e508262378 100644
--- a/mpvcore/options.c
+++ b/mpvcore/options.c
@@ -669,6 +669,8 @@ const m_option_t mp_opts[] = {
OPT_DOUBLE("chapter-seek-threshold", chapter_seek_threshold, 0),
+ OPT_FLAG("load-unsafe-playlists", load_unsafe_playlists, 0),
+
// a-v sync stuff:
OPT_FLAG("correct-pts", correct_pts, 0),
OPT_CHOICE("pts-association-mode", user_pts_assoc_mode, 0,
diff --git a/mpvcore/options.h b/mpvcore/options.h
index 1ff50688ce..033d3c89c6 100644
--- a/mpvcore/options.h
+++ b/mpvcore/options.h
@@ -87,6 +87,7 @@ typedef struct MPOpts {
int ordered_chapters;
int chapter_merge_threshold;
double chapter_seek_threshold;
+ int load_unsafe_playlists;
int quiet;
int load_config;
int use_filedir_conf;
diff --git a/mpvcore/parser-mpcmd.c b/mpvcore/parser-mpcmd.c
index 55615d950e..e85085b808 100644
--- a/mpvcore/parser-mpcmd.c
+++ b/mpvcore/parser-mpcmd.c
@@ -114,6 +114,7 @@ static bool split_opt(struct parse_state *p)
int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
int argc, char **argv)
{
+ struct MPOpts *opts = config->optstruct;
int ret = M_OPT_UNKNOWN;
int mode = 0;
struct playlist_entry *local_start = NULL;
@@ -187,7 +188,7 @@ int m_config_parse_mp_command_line(m_config_t *config, struct playlist *files,
if (bstrcmp0(p.arg, "playlist") == 0) {
// append the playlist to the local args
char *param0 = bstrdup0(NULL, p.param);
- struct playlist *pl = playlist_parse_file(param0);
+ struct playlist *pl = playlist_parse_file(param0, opts);
talloc_free(param0);
if (!pl) {
mp_tmsg(MSGT_CFGPARSER, MSGL_FATAL,
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);
-}
diff --git a/mpvcore/playlist_parser.h b/mpvcore/playlist_parser.h
index 3ceb95c460..a541aa2cb4 100644
--- a/mpvcore/playlist_parser.h
+++ b/mpvcore/playlist_parser.h
@@ -21,14 +21,9 @@
#include <stdbool.h>
-struct stream;
+struct MPOpts;
struct playlist;
-// Parse the given stream as playlist. Append entries to pl. Return whether
-// there was an error when parsing.
-// deep = Parser depth. Some formats allow including other files,
-struct playlist *playlist_parse(struct stream* stream);
-struct playlist *playlist_probe_and_parse(struct stream* stream);
-struct playlist *playlist_parse_file(const char *file);
+struct playlist *playlist_parse_file(const char *file, struct MPOpts *opts);
#endif
diff --git a/mpvcore/timeline/tl_cue.c b/mpvcore/timeline/tl_cue.c
index f7e13ec681..634a6de5f4 100644
--- a/mpvcore/timeline/tl_cue.c
+++ b/mpvcore/timeline/tl_cue.c
@@ -356,8 +356,6 @@ void build_cue_timeline(struct MPContext *mpctx)
}
}
- add_source(mpctx, mpctx->demuxer);
-
for (size_t i = 0; i < file_count; i++) {
if (!open_source(mpctx, files[i]))
goto out;