Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demux: add --autocreate-playlist #14555

Merged
merged 8 commits into from
Aug 10, 2024
Merged
4 changes: 4 additions & 0 deletions DOCS/interface-changes/autocreate-playlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add `--autocreate-playlist`
add `--video-exts`
add `--audio-exts`
add `--image-exts`
2 changes: 2 additions & 0 deletions DOCS/interface-changes/directory-filter-types.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add `--directory-filter-types`
By default, opening a directory will create a playlist with only the media types "video, audio, image". To restore the previous behavior, use `--directory-filter-types-clr`.
41 changes: 36 additions & 5 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2258,10 +2258,12 @@ Audio
:all: Load all audio files in the current and ``--audio-file-paths``
directories.

``--audio-file-auto-exts=ext1,ext2,...``
Audio file extentions to try and match when using ``audio-file-auto``.
``--audio-exts=ext1,ext2,...``
Audio file extentions to try to match when using ``--audio-file-auto``,
``--autocreate-playlist`` or ``--directory-filter-types``.

This is a string list option. See `List Options`_ for details.
Use ``--help=audio-exts`` to see default extensions.

``--audio-file-paths=<path1:path2:...>``
Equivalent to ``--sub-file-paths`` option, but for auto-loaded audio files.
Expand Down Expand Up @@ -4120,6 +4122,26 @@ Demuxer
all. The default is ``auto``, which behaves like ``recursive`` with
``--shuffle``, and like ``lazy`` otherwise.

``--directory-filter-types=<video,audio,image>``
Media file types to filter when opening directory. If the list is empty,
all files are added to the playlist. (Default: ``video,audio,image``)
kasper93 marked this conversation as resolved.
Show resolved Hide resolved

This is a string list option. See `List Options`_ for details.

``--autocreate-playlist=<no|filter|same>``
When opening a local file, act as if the parent directory is opened and
create a playlist automatically.

:no: Load a single file (default).
:filter: Create a playlist from the parent directory with files matching
``--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
and only files with matching extensions are added to the playlist.
If the input file itself is not matched to any extension list,
the playlist is not autogenerated.

Input
-----

Expand Down Expand Up @@ -7488,20 +7510,29 @@ Miscellaneous
See ``--audio-display`` how to control display of cover art (this can be
used to disable cover art that is part of the file).

``--cover-art-auto-exts=ext1,ext2,...``
Cover art extentions to try and match when using ``cover-art-auto``.
``--image-exts=ext1,ext2,...``
Image file extentions to try to match when using ``--cover-art-auto``,
``--autocreate-playlist`` or ``--directory-filter-types``.

This is a string list option. See `List Options`_ for details.
Use ``--help=image-exts`` to see default extensions.

``--cover-art-whitelist=filename1,filename2,...``
Filenames to load as cover art, sorted by descending priority. They are
combined with the extensions in ``--cover-art-auto-exts``. This has no
combined with the extensions in ``--image-exts``. This has no
effect if ``cover-art-auto`` is ``no``.

Default: ``AlbumArt,Album,cover,front,AlbumArtSmall,Folder,.folder,thumb``

This is a string list option. See `List Options`_ for details.

``--video-exts=ext1,ext2,...``
Video file extentions to try to match when using ``--autocreate-playlist`` or
``--directory-filter-types``.

This is a string list option. See `List Options`_ for details.
Use ``--help=video-exts`` to see default extensions.

kasper93 marked this conversation as resolved.
Show resolved Hide resolved
``--autoload-files=<yes|no>``
Automatically load/select external files (default: yes).

Expand Down
21 changes: 21 additions & 0 deletions common/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,24 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel,
talloc_free(log);
return ret;
}

void playlist_set_current(struct playlist *pl)
{
if (!pl->playlist_dir)
return;

for (int i = 0; i < pl->num_entries; ++i) {
if (!pl->entries[i]->playlist_path)
continue;
char *path = pl->entries[i]->playlist_path;
if (path[0] != '.')
path = mp_path_join(NULL, pl->playlist_dir, pl->entries[i]->playlist_path);
bool same = !strcmp(pl->entries[i]->filename, path);
if (path != pl->entries[i]->playlist_path)
talloc_free(path);
if (same) {
pl->current = pl->entries[i];
break;
}
}
}
3 changes: 3 additions & 0 deletions common/playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct playlist {
bool current_was_replaced;
bool playlist_completed;
bool playlist_started;
char *playlist_dir;

uint64_t id_alloc;
};
Expand Down Expand Up @@ -124,4 +125,6 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel,

void playlist_entry_unref(struct playlist_entry *e);

void playlist_set_current(struct playlist *pl);

#endif
4 changes: 4 additions & 0 deletions demux/demux.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ extern const demuxer_desc_t demuxer_desc_mf;
extern const demuxer_desc_t demuxer_desc_matroska;
extern const demuxer_desc_t demuxer_desc_lavf;
extern const demuxer_desc_t demuxer_desc_playlist;
extern const demuxer_desc_t demuxer_desc_directory;
extern const demuxer_desc_t demuxer_desc_disc;
extern const demuxer_desc_t demuxer_desc_rar;
extern const demuxer_desc_t demuxer_desc_libarchive;
extern const demuxer_desc_t demuxer_desc_null;
extern const demuxer_desc_t demuxer_desc_timeline;

static const demuxer_desc_t *const demuxer_list[] = {
&demuxer_desc_directory,
&demuxer_desc_disc,
&demuxer_desc_edl,
&demuxer_desc_cue,
Expand Down Expand Up @@ -117,6 +119,8 @@ const struct m_sub_options demux_conf = {
{"demuxer-backward-playback-step", OPT_DOUBLE(back_seek_size),
M_RANGE(0, DBL_MAX)},
{"metadata-codepage", OPT_STRING(meta_cp)},
{"autocreate-playlist", OPT_CHOICE(autocreate_playlist,
{"no", 0}, {"filter", 1}, {"same", 2})},
{0}
},
.size = sizeof(struct demux_opts),
Expand Down
2 changes: 2 additions & 0 deletions demux/demux.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct demux_opts {
double back_seek_size;
char *meta_cp;
bool force_retry_eof;
int autocreate_playlist;
};

#define SEEK_FACTOR (1 << 1) // argument is in range [0,1]
Expand Down Expand Up @@ -211,6 +212,7 @@ struct demuxer_params {
bool stream_record; // if true, enable stream recording if option is set
int stream_flags;
struct stream *external_stream; // if set, use this, don't open or close streams
bool allow_playlist_create;
// result
bool demuxer_failed;
};
Expand Down
Loading
Loading