From 4e50da3ddc1aefb9946f53851b15b3c02f46fbec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 9 Aug 2024 17:06:04 +0200 Subject: [PATCH] demux_playlist: use --directory-filter-types for --autocreate-playlist --- DOCS/man/options.rst | 5 ++--- demux/demux.c | 2 +- demux/demux_playlist.c | 35 +++++++++++++++++++---------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index a42aa44c0c..892398501a 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -4147,14 +4147,13 @@ Demuxer This is a string list option. See `List Options`_ for details. -``--autocreate-playlist=`` +``--autocreate-playlist=`` When opening a local file, act as if the parent directory is opened and create a playlist automatically. :no: Load a single file (default). - :any: Create a playlist from the parent directory with any file type. :filter: Create a playlist from the parent directory with files matching - extensions from any list ``*-exts``. + ``--directory-filter-types``. :same: Create a playlist from the parent directory with files matching the same category as the currently loaded file. One of the ``*-exts`` is selected based on the input file diff --git a/demux/demux.c b/demux/demux.c index f74836a3c3..eb79c32ef0 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -120,7 +120,7 @@ const struct m_sub_options demux_conf = { M_RANGE(0, DBL_MAX)}, {"metadata-codepage", OPT_STRING(meta_cp)}, {"autocreate-playlist", OPT_CHOICE(autocreate_playlist, - {"no", 0}, {"any", 1}, {"filter", 2}, {"same", 3})}, + {"no", 0}, {"filter", 1}, {"same", 2})}, {0} }, .size = sizeof(struct demux_opts), diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c index a157c05deb..ba98560d42 100644 --- a/demux/demux_playlist.c +++ b/demux/demux_playlist.c @@ -495,22 +495,33 @@ static bool scan_dir(struct pl_parser *p, char *path, return true; } +static enum autocreate_mode get_directory_filter(struct pl_parser *p) +{ + enum autocreate_mode autocreate = AUTO_NONE; + if (!p->opts->directory_filter || !p->opts->directory_filter[0]) + autocreate = AUTO_ANY; + if (str_in_list(bstr0("video"), p->opts->directory_filter)) + autocreate |= AUTO_VIDEO; + if (str_in_list(bstr0("audio"), p->opts->directory_filter)) + autocreate |= AUTO_AUDIO; + if (str_in_list(bstr0("image"), p->opts->directory_filter)) + autocreate |= AUTO_IMAGE; + return autocreate; +} + static int parse_dir(struct pl_parser *p) { int ret = -1; struct stream *stream = p->real_stream; - int autocreate = AUTO_NONE; + enum autocreate_mode autocreate = AUTO_NONE; p->pl->playlist_dir = NULL; if (p->autocreate_playlist && p->real_stream->is_local_file && !p->real_stream->is_directory) { bstr ext = bstr_get_ext(bstr0(p->real_stream->url)); switch (p->autocreate_playlist) { - case 1: // any - autocreate = AUTO_ANY; + case 1: // filter + autocreate = get_directory_filter(p); break; - case 2: // filter - autocreate = AUTO_VIDEO | AUTO_AUDIO | AUTO_IMAGE; - break; - case 3: // same + case 2: // same if (str_in_list(ext, p->mp_opts->video_exts)) { autocreate = AUTO_VIDEO; } else if (str_in_list(ext, p->mp_opts->audio_exts)) { @@ -530,15 +541,7 @@ static int parse_dir(struct pl_parser *p) p->pl->playlist_dir = bstrdup0(p->pl, dir); } } else { - autocreate = AUTO_NONE; - if (!p->opts->directory_filter || !p->opts->directory_filter[0]) - autocreate = AUTO_ANY; - if (str_in_list(bstr0("video"), p->opts->directory_filter)) - autocreate |= AUTO_VIDEO; - if (str_in_list(bstr0("audio"), p->opts->directory_filter)) - autocreate |= AUTO_AUDIO; - if (str_in_list(bstr0("image"), p->opts->directory_filter)) - autocreate |= AUTO_IMAGE; + autocreate = get_directory_filter(p); } if (!stream->is_directory) goto done;