summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--player/loadfile.c8
-rw-r--r--stream/stream.h3
-rw-r--r--stream/stream_file.c36
3 files changed, 34 insertions, 13 deletions
diff --git a/player/loadfile.c b/player/loadfile.c
index 2189bc4130..e7a45e014d 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1029,6 +1029,7 @@ static void load_per_file_options(m_config_t *conf,
static void play_current_file(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
+ void *tmp = talloc_new(NULL);
double playback_start = -1e100;
mpctx->initialized_flags |= INITIALIZED_PLAYBACK;
@@ -1047,6 +1048,10 @@ static void play_current_file(struct MPContext *mpctx)
if (!mpctx->filename)
goto terminate_playback;
+ char *local_filename = mp_file_url_to_filename(tmp, bstr0(mpctx->filename));
+ if (local_filename)
+ mpctx->filename = local_filename;
+
#if HAVE_ENCODING
encode_lavc_discontinuity(mpctx->encode_lavc_ctx);
#endif
@@ -1096,6 +1101,7 @@ static void play_current_file(struct MPContext *mpctx)
char *stream_filename = mpctx->filename;
mpctx->resolve_result = resolve_url(stream_filename, mpctx->global);
if (mpctx->resolve_result) {
+ talloc_steal(tmp, mpctx->resolve_result);
print_resolve_contents(mpctx->log, mpctx->resolve_result);
if (mpctx->resolve_result->playlist) {
transfer_playlist(mpctx, mpctx->resolve_result->playlist);
@@ -1370,8 +1376,8 @@ terminate_playback: // don't jump here after ao/vo/getch initialization!
getch2_enable();
mpctx->filename = NULL;
- talloc_free(mpctx->resolve_result);
mpctx->resolve_result = NULL;
+ talloc_free(tmp);
// Played/paused for longer than 3 seconds -> ok
bool playback_short = mpctx->stop_play == AT_END_OF_FILE &&
diff --git a/stream/stream.h b/stream/stream.h
index 9cb227bfa8..e64baf07c6 100644
--- a/stream/stream.h
+++ b/stream/stream.h
@@ -281,4 +281,7 @@ typedef struct {
void mp_url_unescape_inplace(char *buf);
char *mp_url_escape(void *talloc_ctx, const char *s, const char *ok);
+// stream_file.c
+char *mp_file_url_to_filename(void *talloc_ctx, bstr url);
+
#endif /* MPLAYER_STREAM_H */
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;
}