summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-04 14:04:35 +0200
committerwm4 <wm4@nowhere>2013-09-04 16:15:08 +0200
commitefc5ac17bf0a563cc4200252e8d4718731dc9fde (patch)
tree86eeedc8abf1170b2c91abda2df632a0458e8eb6
parentdbff29c81d3127d69e97abcf7001f4b798898a81 (diff)
downloadmpv-efc5ac17bf0a563cc4200252e8d4718731dc9fde.tar.bz2
mpv-efc5ac17bf0a563cc4200252e8d4718731dc9fde.tar.xz
path: add a common mp_is_url() function
Remove the duplicated code.
-rw-r--r--mpvcore/mplayer.c9
-rw-r--r--mpvcore/path.c8
-rw-r--r--mpvcore/path.h2
-rw-r--r--mpvcore/playlist.c7
-rw-r--r--stream/stream.c7
5 files changed, 17 insertions, 16 deletions
diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c
index 12bf0a3aec..be820dd10e 100644
--- a/mpvcore/mplayer.c
+++ b/mpvcore/mplayer.c
@@ -682,6 +682,8 @@ static void load_per_protocol_config(m_config_t *conf, const char * const file)
m_profile_t *p;
/* does filename actually uses a protocol ? */
+ if (!mp_is_url(bstr0(file)))
+ return;
str = strstr(file, "://");
if (!str)
return;
@@ -784,11 +786,6 @@ static void load_per_file_config(m_config_t *conf, const char * const file,
}
}
-static bool might_be_an_url(bstr f)
-{
- return bstr_find0(f, "://") >= 0;
-}
-
#define MP_WATCH_LATER_CONF "watch_later"
static char *get_playback_resume_config_filename(const char *fname)
@@ -796,7 +793,7 @@ static char *get_playback_resume_config_filename(const char *fname)
char *res = NULL;
void *tmp = talloc_new(NULL);
const char *realpath = fname;
- if (!might_be_an_url(bstr0(fname))) {
+ if (!mp_is_url(bstr0(fname))) {
char *cwd = mp_getcwd(tmp);
if (!cwd)
goto exit;
diff --git a/mpvcore/path.c b/mpvcore/path.c
index 5d9b7841a4..5893284b5e 100644
--- a/mpvcore/path.c
+++ b/mpvcore/path.c
@@ -227,3 +227,11 @@ bool mp_path_isdir(const char *path)
struct stat st;
return mp_stat(path, &st) == 0 && S_ISDIR(st.st_mode);
}
+
+// Return false if it's considered a normal local filesystem path.
+bool mp_is_url(bstr path)
+{
+ // The URL check is a bit murky, but "/path" and "./path" are never URLs.
+ return path.len && path.start[0] != '/' && path.start[0] != '.' &&
+ bstr_find0(path, "://") >= 0;
+}
diff --git a/mpvcore/path.h b/mpvcore/path.h
index 9728dc7399..52656f8fc2 100644
--- a/mpvcore/path.h
+++ b/mpvcore/path.h
@@ -63,4 +63,6 @@ char *mp_getcwd(void *talloc_ctx);
bool mp_path_exists(const char *path);
bool mp_path_isdir(const char *path);
+bool mp_is_url(bstr path);
+
#endif /* MPLAYER_PATH_H */
diff --git a/mpvcore/playlist.c b/mpvcore/playlist.c
index 77e114b1a5..3396a5d78b 100644
--- a/mpvcore/playlist.c
+++ b/mpvcore/playlist.c
@@ -176,17 +176,12 @@ struct playlist_entry *playlist_get_next(struct playlist *pl, int direction)
return pl->current_was_replaced ? pl->current : pl->current->next;
}
-static bool might_be_an_url(bstr f)
-{
- return bstr_find0(f, "://") >= 0;
-}
-
void playlist_add_base_path(struct playlist *pl, bstr base_path)
{
if (base_path.len == 0 || bstrcmp0(base_path, ".") == 0)
return;
for (struct playlist_entry *e = pl->first; e; e = e->next) {
- if (!might_be_an_url(bstr0(e->filename))) {
+ if (!mp_is_url(bstr0(e->filename))) {
char *new_file = mp_path_join(e, base_path, bstr0(e->filename));
talloc_free(e->filename);
e->filename = new_file;
diff --git a/stream/stream.c b/stream/stream.c
index 8fde847743..bf84850d75 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -40,6 +40,7 @@
#include "mpvcore/mp_common.h"
#include "mpvcore/bstr.h"
#include "mpvcore/mp_msg.h"
+#include "mpvcore/path.h"
#include "osdep/timer.h"
#include "stream.h"
#include "demux/demux.h"
@@ -250,10 +251,8 @@ static const char *match_proto(const char *url, const char *proto)
if (l > 0) {
if (strncasecmp(url, proto, l) == 0 && strncmp("://", url + l, 3) == 0)
return url + l + 3;
- } else {
- // pure filenames (including "/path" and "./path")
- if (url[0] == '/' || url[0] == '.' || !strstr(url, "://"))
- return url;
+ } else if (!mp_is_url(bstr0(url))) {
+ return url; // pure filenames
}
return NULL;
}