summaryrefslogtreecommitdiffstats
path: root/stream/stream_file.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-08 21:46:42 +0100
committerwm4 <wm4@nowhere>2014-01-08 21:46:42 +0100
commit1d2a11133737802baa555dcbff9482bd5c8120ad (patch)
treec8c512a911c936435d1201277033793dc48876ff /stream/stream_file.c
parent59c6fa220158794791b5e1674c4aa1e1a439c2c8 (diff)
downloadmpv-1d2a11133737802baa555dcbff9482bd5c8120ad.tar.bz2
mpv-1d2a11133737802baa555dcbff9482bd5c8120ad.tar.xz
player: strip 'file://' from filenames on playback start
This fixes two things: 1. Dropping files on the VO window will auto-load subtitles (since most drag & drop code prefixes the filenames with 'file://', and the subtitle auto-load code considers 'file://' non-local) 2. Fix behavior of the %x screenshot filename template (similar problem) One could force all that code to special-case 'file://' URLs, but just replacing the filename on playback start is simpler.
Diffstat (limited to 'stream/stream_file.c')
-rw-r--r--stream/stream_file.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/stream/stream_file.c b/stream/stream_file.c
index 9b27b7bc82..3591227f75 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -32,6 +32,7 @@
#include "common/msg.h"
#include "stream.h"
#include "options/m_option.h"
+#include "options/path.h"
struct priv {
int fd;
@@ -91,10 +92,25 @@ static void s_close(stream_t *s)
close(p->fd);
}
+// If url is a file:// URL, return the local filename, otherwise return NULL.
+char *mp_file_url_to_filename(void *talloc_ctx, bstr url)
+{
+ bstr proto = mp_split_proto(url, &url);
+ if (bstrcasecmp0(proto, "file") != 0)
+ return NULL;
+ char *filename = bstrto0(talloc_ctx, url);
+ mp_url_unescape_inplace(filename);
+#if HAVE_DOS_PATHS
+ // extract '/' from '/x:/path'
+ if (filename[0] == '/' && filename[1] && filename[2] == ':')
+ memmove(filename, filename + 1, strlen(filename)); // including \0
+#endif
+ return filename;
+}
+
static int open_f(stream_t *stream, int mode)
{
int fd;
- char *filename = stream->path;
struct priv *priv = talloc_ptrtype(stream, priv);
*priv = (struct priv) {
.fd = -1
@@ -111,15 +127,12 @@ static int open_f(stream_t *stream, int mode)
return STREAM_UNSUPPORTED;
}
- // "file://" prefix -> decode URL-style escapes
- if (strlen(stream->url) > strlen(stream->path))
- mp_url_unescape_inplace(stream->path);
-
-#if HAVE_DOS_PATHS
- // extract '/' from '/x:/path'
- if (filename[0] == '/' && filename[1] && filename[2] == ':')
- filename++;
-#endif
+ char *filename = mp_file_url_to_filename(stream, bstr0(stream->url));
+ if (filename) {
+ stream->path = filename;
+ } else {
+ filename = stream->path;
+ }
if (!strcmp(filename, "-")) {
if (mode == STREAM_READ) {
@@ -151,8 +164,7 @@ static int open_f(stream_t *stream, int mode)
#ifndef __MINGW32__
struct stat st;
if (fstat(fd, &st) == 0 && S_ISDIR(st.st_mode)) {
- MP_ERR(stream, "File is a directory: '%s'\n",
- filename);
+ MP_ERR(stream, "File is a directory: '%s'\n", filename);
close(fd);
return STREAM_ERROR;
}