History

demux_playlist: use --directory-filter-types for --autocreate-playlist

Kacper Michajłow committed 2 years ago

Commit 4e50da31 parent ff1f8ba3 files · +22 −20Browse files

Unified · Split

3 files
  1. DOCS/man/options.rst +2 −3
  2. demux/demux.c +1 −1
  3. demux/demux_playlist.c +19 −16
DOCS/man/options.rst+2−3
@@ -4147,14 +4147,13 @@ Demuxer · 4146 unmodified lines
4147 4147
4148 This is a string list option. See `List Options`_ for details.4148 This is a string list option. See `List Options`_ for details.
4149 4149
4150``--autocreate-playlist=<no|any|filter|same>``4150``--autocreate-playlist=<no|filter|same>``
4151 When opening a local file, act as if the parent directory is opened and4151 When opening a local file, act as if the parent directory is opened and
4152 create a playlist automatically.4152 create a playlist automatically.
4153 4153
4154 :no: Load a single file (default).4154 :no: Load a single file (default).
4155 :any: Create a playlist from the parent directory with any file type.
4156 :filter: Create a playlist from the parent directory with files matching4155 :filter: Create a playlist from the parent directory with files matching
4157 extensions from any list ``*-exts``.4156 ``--directory-filter-types``.
4158 :same: Create a playlist from the parent directory with files matching the4157 :same: Create a playlist from the parent directory with files matching the
4159 same category as the currently loaded file. One of the4158 same category as the currently loaded file. One of the
4160 ``*-exts`` is selected based on the input file4159 ``*-exts`` is selected based on the input file
demux/demux.c+1−1
@@ -120,7 +120,7 @@ const struct m_sub_options demux_conf = { · 119 unmodified lines
120 M_RANGE(0, DBL_MAX)},120 M_RANGE(0, DBL_MAX)},
121 {"metadata-codepage", OPT_STRING(meta_cp)},121 {"metadata-codepage", OPT_STRING(meta_cp)},
122 {"autocreate-playlist", OPT_CHOICE(autocreate_playlist,122 {"autocreate-playlist", OPT_CHOICE(autocreate_playlist,
123 {"no", 0}, {"any", 1}, {"filter", 2}, {"same", 3})},123 {"no", 0}, {"filter", 1}, {"same", 2})},
124 {0}124 {0}
125 },125 },
126 .size = sizeof(struct demux_opts),126 .size = sizeof(struct demux_opts),
demux/demux_playlist.c+19−16
@@ -495,22 +495,33 @@ static bool scan_dir(struct pl_parser *p, char *path, · 494 unmodified lines
495 return true;495 return true;
496}496}
497 497
498static enum autocreate_mode get_directory_filter(struct pl_parser *p)
499{
500 enum autocreate_mode autocreate = AUTO_NONE;
501 if (!p->opts->directory_filter || !p->opts->directory_filter[0])
502 autocreate = AUTO_ANY;
503 if (str_in_list(bstr0("video"), p->opts->directory_filter))
504 autocreate |= AUTO_VIDEO;
505 if (str_in_list(bstr0("audio"), p->opts->directory_filter))
506 autocreate |= AUTO_AUDIO;
507 if (str_in_list(bstr0("image"), p->opts->directory_filter))
508 autocreate |= AUTO_IMAGE;
509 return autocreate;
510}
511
498static int parse_dir(struct pl_parser *p)512static int parse_dir(struct pl_parser *p)
499{513{
500 int ret = -1;514 int ret = -1;
501 struct stream *stream = p->real_stream;515 struct stream *stream = p->real_stream;
502 int autocreate = AUTO_NONE;516 enum autocreate_mode autocreate = AUTO_NONE;
503 p->pl->playlist_dir = NULL;517 p->pl->playlist_dir = NULL;
504 if (p->autocreate_playlist && p->real_stream->is_local_file && !p->real_stream->is_directory) {518 if (p->autocreate_playlist && p->real_stream->is_local_file && !p->real_stream->is_directory) {
505 bstr ext = bstr_get_ext(bstr0(p->real_stream->url));519 bstr ext = bstr_get_ext(bstr0(p->real_stream->url));
506 switch (p->autocreate_playlist) {520 switch (p->autocreate_playlist) {
507 case 1: // any521 case 1: // filter
508 autocreate = AUTO_ANY;522 autocreate = get_directory_filter(p);
509 break;
510 case 2: // filter
511 autocreate = AUTO_VIDEO | AUTO_AUDIO | AUTO_IMAGE;
512 break;523 break;
513 case 3: // same524 case 2: // same
514 if (str_in_list(ext, p->mp_opts->video_exts)) {525 if (str_in_list(ext, p->mp_opts->video_exts)) {
515 autocreate = AUTO_VIDEO;526 autocreate = AUTO_VIDEO;
516 } else if (str_in_list(ext, p->mp_opts->audio_exts)) {527 } else if (str_in_list(ext, p->mp_opts->audio_exts)) {
@@ -530,15 +541,7 @@ static int parse_dir(struct pl_parser *p) · 13 unmodified lines
530 p->pl->playlist_dir = bstrdup0(p->pl, dir);541 p->pl->playlist_dir = bstrdup0(p->pl, dir);
531 }542 }
532 } else {543 } else {
533 autocreate = AUTO_NONE;544 autocreate = get_directory_filter(p);
534 if (!p->opts->directory_filter || !p->opts->directory_filter[0])
535 autocreate = AUTO_ANY;
536 if (str_in_list(bstr0("video"), p->opts->directory_filter))
537 autocreate |= AUTO_VIDEO;
538 if (str_in_list(bstr0("audio"), p->opts->directory_filter))
539 autocreate |= AUTO_AUDIO;
540 if (str_in_list(bstr0("image"), p->opts->directory_filter))
541 autocreate |= AUTO_IMAGE;
542 }545 }
543 if (!stream->is_directory)546 if (!stream->is_directory)
544 goto done;547 goto done;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t