summaryrefslogtreecommitdiffstats
path: root/demux/demux_playlist.c
diff options
context:
space:
mode:
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-04-25 18:28:17 +0900
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-04-25 18:28:17 +0900
commit5f1d6b6e5ae515abfb77c78c44d21ee21beb0fc3 (patch)
tree6b757d37d296709dfd5955ef9d4d41426cd47da6 /demux/demux_playlist.c
parentd64ff3aa51b49451348383a6ff6de7697a52dc62 (diff)
parent983d24e3b9ce9c9c7755279138c14170e85fbf37 (diff)
downloadmpv-5f1d6b6e5ae515abfb77c78c44d21ee21beb0fc3.tar.bz2
mpv-5f1d6b6e5ae515abfb77c78c44d21ee21beb0fc3.tar.xz
Merge branch 'master' into release/0.9
* master: (87 commits) manpage: move --autosync description player: add --window-scale option player: flush decoder even if cover art is decoded player: don't show A/V desync message in non-sense situations w32_common: add more rounded-down frame rates w32_common: use the current monitor's refresh rate dxva2: fix broken build with gcc 5.1 terminal: printf() is not signal-safe man: fix PDF build DOCS/mplayer-changes: Eleborate on joystick input osc: add nil check for element.eventresponder mp_image: remove some unused interlacing flags vf_vapoursynth: update _FieldBased semantics options: remove unneeded hack from command line parser manpage: document ff-index sub-property demux_mkv: limit timestamp fixing to 1ms max demux_mkv: attempt to fix rounded timestamps demux_mkv: move global options to the demuxer demux_mkv: better seeking after video end lua: add utils.format_json() function ...
Diffstat (limited to 'demux/demux_playlist.c')
-rw-r--r--demux/demux_playlist.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c
index 381b50f269..6f73bea5ba 100644
--- a/demux/demux_playlist.c
+++ b/demux/demux_playlist.c
@@ -15,7 +15,10 @@
* with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdlib.h>
+#include <string.h>
#include <strings.h>
+#include <dirent.h>
#include "common/common.h"
#include "options/options.h"
@@ -23,6 +26,7 @@
#include "common/playlist.h"
#include "options/path.h"
#include "stream/stream.h"
+#include "osdep/io.h"
#include "demux.h"
#define PROBE_SIZE (8 * 1024)
@@ -47,6 +51,7 @@ struct pl_parser {
bool error;
bool probing;
bool force;
+ bool add_base;
enum demux_check check_level;
struct stream *real_stream;
};
@@ -204,6 +209,51 @@ static int parse_txt(struct pl_parser *p)
return 0;
}
+static int cmp_filename(const void *a, const void *b)
+{
+ return strcmp(*(char **)a, *(char **)b);
+}
+
+static int parse_dir(struct pl_parser *p)
+{
+ if (p->real_stream->type != STREAMTYPE_DIR)
+ return -1;
+ if (p->probing)
+ return 0;
+
+ char *path = mp_file_get_path(p, bstr0(p->real_stream->url));
+ if (strlen(path) >= 8192)
+ return -1; // things like mount bind loops
+
+ DIR *dp = opendir(path);
+ if (!dp) {
+ MP_ERR(p, "Could not read directory.\n");
+ return -1;
+ }
+
+ char **files = NULL;
+ int num_files = 0;
+
+ struct dirent *ep;
+ while ((ep = readdir(dp))) {
+ if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
+ continue;
+ MP_TARRAY_APPEND(p, files, num_files, talloc_strdup(p, ep->d_name));
+ }
+
+ if (files)
+ qsort(files, num_files, sizeof(files[0]), cmp_filename);
+
+ for (int n = 0; n < num_files; n++)
+ playlist_add_file(p->pl, mp_path_join(p, bstr0(path), bstr0(files[n])));
+
+ closedir(dp);
+
+ p->add_base = false;
+
+ return num_files > 0 ? 0 : -1;
+}
+
#define MIME_TYPES(...) \
.mime_types = (const char*const[]){__VA_ARGS__, NULL}
@@ -214,6 +264,7 @@ struct pl_format {
};
static const struct pl_format formats[] = {
+ {"directory", parse_dir},
{"m3u", parse_m3u,
MIME_TYPES("audio/mpegurl", "audio/x-mpegurl", "application/x-mpegurl")},
{"ini", parse_ref_init},
@@ -248,6 +299,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
p->log = demuxer->log;
p->pl = talloc_zero(p, struct playlist);
p->real_stream = demuxer->stream;
+ p->add_base = true;
bstr probe_buf = stream_peek(demuxer->stream, PROBE_SIZE);
p->s = open_memory_stream(probe_buf.start, probe_buf.len);
@@ -269,7 +321,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
p->s = demuxer->stream;
p->utf16 = stream_skip_bom(p->s);
bool ok = fmt->parse(p) >= 0 && !p->error;
- if (ok)
+ if (p->add_base)
playlist_add_base_path(p->pl, mp_dirname(demuxer->filename));
demuxer->playlist = talloc_steal(demuxer, p->pl);
demuxer->filetype = fmt->name;