diff options
Diffstat (limited to 'demux/demux_libarchive.c')
-rw-r--r-- | demux/demux_libarchive.c | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/demux/demux_libarchive.c b/demux/demux_libarchive.c index 41b05368ca..a85e40ff89 100644 --- a/demux/demux_libarchive.c +++ b/demux/demux_libarchive.c @@ -20,14 +20,20 @@ #include "common/common.h" #include "common/playlist.h" +#include "options/m_config.h" #include "stream/stream.h" +#include "misc/natural_sort.h" #include "demux.h" #include "stream/stream_libarchive.h" +struct demux_libarchive_opts { + bool rar_list_all_volumes; +}; + static int cmp_filename(const void *a, const void *b) { - return strcmp(*(char **)a, *(char **)b); + return mp_natural_sort_cmp(*(char **)a, *(char **)b); } static int open_file(struct demuxer *demuxer, enum demux_check check) @@ -42,27 +48,33 @@ static int open_file(struct demuxer *demuxer, enum demux_check check) probe_size *= 100; } - bstr probe = stream_peek(demuxer->stream, probe_size); - if (probe.len == 0) + void *probe = ta_alloc_size(NULL, probe_size); + if (!probe) return -1; - struct stream *probe_stream = open_memory_stream(probe.start, probe.len); - struct mp_archive *mpa = mp_archive_new(mp_null_log, probe_stream, flags); + int probe_got = stream_read_peek(demuxer->stream, probe, probe_size); + struct stream *probe_stream = + stream_memory_open(demuxer->global, probe, probe_got); + struct mp_archive *mpa = mp_archive_new(mp_null_log, probe_stream, flags, 0); bool ok = !!mpa; free_stream(probe_stream); mp_archive_free(mpa); + ta_free(probe); if (!ok) return -1; - mpa = mp_archive_new(demuxer->log, demuxer->stream, flags); + struct demux_libarchive_opts *opts = + mp_get_config_group(demuxer, demuxer->global, demuxer->desc->options); + + if (!opts->rar_list_all_volumes) + flags |= MP_ARCHIVE_FLAG_NO_VOLUMES; + + mpa = mp_archive_new(demuxer->log, demuxer->stream, flags, 0); if (!mpa) return -1; struct playlist *pl = talloc_zero(demuxer, struct playlist); demuxer->playlist = pl; - // make it load archive:// - pl->disable_safety = true; - char *prefix = mp_url_escape(mpa, demuxer->stream->url, "~|"); char **files = NULL; @@ -70,7 +82,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check) while (mp_archive_next_entry(mpa)) { // stream_libarchive.c does the real work - char *f = talloc_asprintf(mpa, "archive://%s|%s", prefix, + char *f = talloc_asprintf(mpa, "archive://%s|/%s", prefix, mpa->entry_filename); MP_TARRAY_APPEND(mpa, files, num_files, f); } @@ -79,18 +91,30 @@ static int open_file(struct demuxer *demuxer, enum demux_check check) qsort(files, num_files, sizeof(files[0]), cmp_filename); for (int n = 0; n < num_files; n++) - playlist_add_file(pl, files[n]); + playlist_append_file(pl, files[n]); + + playlist_set_stream_flags(pl, demuxer->stream_origin); demuxer->filetype = "archive"; demuxer->fully_read = true; mp_archive_free(mpa); + demux_close_stream(demuxer); return 0; } +#define OPT_BASE_STRUCT struct demux_libarchive_opts + const struct demuxer_desc demuxer_desc_libarchive = { .name = "libarchive", .desc = "libarchive wrapper", .open = open_file, + .options = &(const struct m_sub_options){ + .opts = (const struct m_option[]) { + {"rar-list-all-volumes", OPT_BOOL(rar_list_all_volumes)}, + {0} + }, + .size = sizeof(OPT_BASE_STRUCT), + }, }; |