Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions common/playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ struct playlist_entry *playlist_entry_new(const char *filename)
{
struct playlist_entry *e = talloc_zero(NULL, struct playlist_entry);
char *local_filename = mp_file_url_to_filename(e, bstr0(filename));
e->filename = local_filename ? local_filename : talloc_strdup(e, filename);
e->filename = mp_normalize_path(e, local_filename ? local_filename : filename);
if (e->filename) {
talloc_free(local_filename);
} else {
e->filename = local_filename ? local_filename : talloc_strdup(e, filename);
}
e->stream_flags = STREAM_ORIGIN_DIRECT;
e->original_index = -1;
return e;
Expand Down Expand Up @@ -304,20 +309,6 @@ struct playlist_entry *playlist_get_first_in_same_playlist(
return entry;
}

void playlist_add_base_path(struct playlist *pl, bstr base_path)
{
if (base_path.len == 0 || bstrcmp0(base_path, ".") == 0)
return;
for (int n = 0; n < pl->num_entries; n++) {
struct playlist_entry *e = pl->entries[n];
if (!mp_is_url(bstr0(e->filename))) {
char *new_file = mp_path_join_bstr(e, base_path, bstr0(e->filename));
talloc_free(e->filename);
e->filename = new_file;
}
}
}

void playlist_set_stream_flags(struct playlist *pl, int flags)
{
for (int n = 0; n < pl->num_entries; n++)
Expand Down Expand Up @@ -446,15 +437,8 @@ void playlist_set_current(struct playlist *pl)
return;

for (int i = 0; i < pl->num_entries; ++i) {
if (!pl->entries[i]->playlist_path)
continue;
char *path = pl->entries[i]->playlist_path;
if (path[0] != '.')
path = mp_path_join(NULL, pl->playlist_dir, mp_basename(pl->entries[i]->playlist_path));
bool same = !strcmp(pl->entries[i]->filename, path);
if (path != pl->entries[i]->playlist_path)
talloc_free(path);
if (same) {
if (pl->entries[i]->playlist_path &&
!strcmp(pl->entries[i]->filename, pl->entries[i]->playlist_path)) {
pl->current = pl->entries[i];
break;
}
Expand Down
1 change: 0 additions & 1 deletion common/playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ struct playlist_entry *playlist_get_first_in_next_playlist(struct playlist *pl,
int direction);
struct playlist_entry *playlist_get_first_in_same_playlist(struct playlist_entry *entry,
char *current_playlist_path);
void playlist_add_base_path(struct playlist *pl, bstr base_path);
void playlist_set_stream_flags(struct playlist *pl, int flags);
int64_t playlist_transfer_entries_to(struct playlist *pl, int dst_index,
struct playlist *source_pl);
Expand Down
2 changes: 1 addition & 1 deletion demux/demux_libarchive.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
struct playlist *pl = talloc_zero(demuxer, struct playlist);
demuxer->playlist = pl;

char *prefix = mp_url_escape(NULL, mp_normalize_path(mpa, demuxer->stream->url), "~|%");
char *prefix = mp_url_escape(NULL, demuxer->stream->url, "~|%");

char **files = NULL;
int num_files = 0;
Expand Down
50 changes: 17 additions & 33 deletions demux/demux_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ struct pl_parser {
bool error;
bool probing;
bool force;
bool add_base;
bool line_allocated;
int autocreate_playlist;
enum demux_check check_level;
Expand Down Expand Up @@ -219,9 +218,19 @@ static void pl_free_line(struct pl_parser *p, bstr line)

static void pl_add(struct pl_parser *p, bstr entry)
{
char *s = bstrto0(NULL, entry);
playlist_append_file(p->pl, s);
talloc_free(s);
char *path;
bstr proto = mp_split_proto(bstr0(p->s->url), NULL);
// Don't add base path to self-expanding protocols
if (!mp_is_url(entry) && bstrcasecmp0(proto, "memory") &&
bstrcasecmp0(proto, "lavf") && bstrcasecmp0(proto, "hex") &&
bstrcasecmp0(proto, "data") && bstrcasecmp0(proto, "fd")) {
path = mp_path_join_bstr(NULL, mp_dirname(p->s->url), entry);
} else {
path = bstrto0(NULL, entry);
}

playlist_append_file(p->pl, path);
talloc_free(path);
}

static bool pl_eof(struct pl_parser *p)
Expand Down Expand Up @@ -279,12 +288,10 @@ static int parse_m3u(struct pl_parser *p)
} else if (bstr_startswith0(line_dup, "#EXT-X-")) {
p->format = "hls";
} else if (line_dup.len > 0 && !bstr_startswith0(line_dup, "#")) {
char *fn = bstrto0(NULL, line_dup);
struct playlist_entry *e = playlist_entry_new(fn);
talloc_free(fn);
pl_add(p, line);
struct playlist_entry *e = playlist_get_last(p->pl);
e->title = talloc_steal(e, title);
title = NULL;
playlist_insert_at(p->pl, e, NULL);
}
pl_free_line(p, line);
line = pl_get_line(p);
Expand Down Expand Up @@ -419,21 +426,10 @@ static bool test_path(struct pl_parser *p, char *path, int autocreate)
if (autocreate & AUTO_ANY)
return true;

bstr bpath = bstr0(path);
bstr bstream_path = bstr0(p->real_stream->path);

// When opening a file from cwd, 'path' starts with "./" while stream->path
// matches what the user passed as arg. So it may or not not contain ./.
// Strip it from both to make the comparison work.
if (!mp_path_is_absolute(bstream_path)) {
bstr_eatstart0(&bpath, "./");
bstr_eatstart0(&bstream_path, "./");
}

if (!bstrcmp(bpath, bstream_path))
if (!strcmp(path, p->real_stream->path))
return true;

bstr ext = bstr_get_ext(bpath);
bstr ext = bstr_get_ext(bstr0(path));
if (autocreate & AUTO_VIDEO && str_in_list(ext, p->mp_opts->video_exts))
return true;
if (autocreate & AUTO_AUDIO && str_in_list(ext, p->mp_opts->audio_exts))
Expand Down Expand Up @@ -595,7 +591,6 @@ static int parse_dir(struct pl_parser *p)

scan_dir(p, path, dir_stack, 0, autocreate);

p->add_base = false;
ret = p->pl->num_entries > 0 ? 0 : -1;

done:
Expand Down Expand Up @@ -662,7 +657,6 @@ 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;

struct demux_opts *opts = mp_get_config_group(p, p->global, &demux_conf);
p->codepage = opts->meta_cp;
Expand Down Expand Up @@ -696,16 +690,6 @@ 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 (p->add_base) {
bstr proto = mp_split_proto(bstr0(demuxer->filename), NULL);
// Don't add base path to self-expanding protocols
if (bstrcasecmp0(proto, "memory") && bstrcasecmp0(proto, "lavf") &&
bstrcasecmp0(proto, "hex") && bstrcasecmp0(proto, "data") &&
bstrcasecmp0(proto, "fd"))
{
playlist_add_base_path(p->pl, mp_dirname(demuxer->filename));
}
}
playlist_set_stream_flags(p->pl, demuxer->stream_origin);
demuxer->playlist = talloc_steal(demuxer, p->pl);
demuxer->filetype = p->format ? p->format : fmt->name;
Expand Down
13 changes: 3 additions & 10 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,7 @@ static int mp_property_path(void *ctx, struct m_property *prop,
MPContext *mpctx = ctx;
if (!mpctx->filename)
return M_PROPERTY_UNAVAILABLE;
char *path = mp_normalize_path(NULL, mpctx->filename);
int r = m_property_strdup_ro(action, arg, path);
talloc_free(path);
return r;
return m_property_strdup_ro(action, arg, mpctx->filename);
}

static int mp_property_filename(void *ctx, struct m_property *prop,
Expand Down Expand Up @@ -559,12 +556,8 @@ static int mp_property_stream_open_filename(void *ctx, struct m_property *prop,
return M_PROPERTY_OK;
}
case M_PROPERTY_GET_TYPE:
case M_PROPERTY_GET: {
char *path = mp_normalize_path(NULL, mpctx->stream_open_filename);
int r = m_property_strdup_ro(action, arg, path);
talloc_free(path);
return r;
}
case M_PROPERTY_GET:
return m_property_strdup_ro(action, arg, mpctx->stream_open_filename);
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
Expand Down
54 changes: 20 additions & 34 deletions player/configfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,13 @@ char *mp_get_playback_resume_dir(struct MPContext *mpctx)
}

static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
const char *fname)
const char *path)
{
struct MPOpts *opts = mpctx->opts;
char *res = NULL;
void *tmp = talloc_new(NULL);
const char *path = NULL;
if (mp_is_url(bstr0(fname))) {
path = fname;
} else if (opts->ignore_path_in_watch_later_config) {
path = mp_basename(fname);
} else {
path = mp_normalize_path(tmp, fname);
if (!path)
goto exit;
}
if (opts->ignore_path_in_watch_later_config && !mp_is_url(bstr0(path)))
path = mp_basename(path);
uint8_t md5[16];
av_md5_sum(md5, path, strlen(path));
char *conf = talloc_strdup(tmp, "");
Expand All @@ -234,8 +226,6 @@ static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
if (wl_dir && wl_dir[0])
res = mp_path_join(NULL, wl_dir, conf);
talloc_free(wl_dir);

exit:
talloc_free(tmp);
return res;
}
Expand Down Expand Up @@ -296,32 +286,29 @@ static void write_redirects_for_parent_dirs(struct MPContext *mpctx, char *path)
// "/a/b/c.mkv" is the current entry, also create resume files for /a/b and
// /a, so that "mpv --directory-mode=lazy /a" resumes playback from
// /a/b/c.mkv even when b isn't the first directory in /a.
char* path_copy = talloc_strdup(NULL, path);
bstr dir = mp_dirname(path);
// There is no need to write a redirect entry for "/".
while (dir.len > 1 && dir.len < strlen(path)) {
path[dir.len] = '\0';
mp_path_strip_trailing_separator(path);
write_redirect(mpctx, path);
dir = mp_dirname(path);
while (dir.len > 1 && dir.len < strlen(path_copy)) {
path_copy[dir.len] = '\0';
mp_path_strip_trailing_separator(path_copy);
write_redirect(mpctx, path_copy);
dir = mp_dirname(path_copy);
}
talloc_free(path_copy);
}

void mp_write_watch_later_conf(struct MPContext *mpctx)
{
struct playlist_entry *cur = mpctx->playing;
char *conffile = NULL;
void *ctx = talloc_new(NULL);

if (!cur)
goto exit;

char *path = mp_normalize_path(ctx, cur->filename);
if (!path)
goto exit;

struct demuxer *demux = mpctx->demuxer;

conffile = mp_get_playback_resume_config_filename(mpctx, path);
conffile = mp_get_playback_resume_config_filename(mpctx, cur->filename);
if (!conffile)
goto exit;

Expand All @@ -337,7 +324,7 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
goto exit;
}

write_filename(mpctx, file, path);
write_filename(mpctx, file, cur->filename);

bool write_start = true;
double pos = get_playback_time(mpctx);
Expand Down Expand Up @@ -374,34 +361,33 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
}
fclose(file);

if (mpctx->opts->position_check_mtime && !mp_is_url(bstr0(path)) &&
!copy_mtime(path, conffile))
if (mpctx->opts->position_check_mtime && !mp_is_url(bstr0(cur->filename)) &&
!copy_mtime(cur->filename, conffile))
{
MP_WARN(mpctx, "Can't copy mtime from %s to %s\n", cur->filename,
conffile);
}

write_redirects_for_parent_dirs(mpctx, path);
write_redirects_for_parent_dirs(mpctx, cur->filename);

// Also write redirect entries for a playlist that mpv expanded if the
// current entry is a URL, this is mostly useful for playing multiple
// archives of images, e.g. with mpv 1.zip 2.zip and quit-watch-later
// on 2.zip, write redirect entries for 2.zip, not just for the archive://
// URL.
if (cur->playlist_path && mp_is_url(bstr0(path))) {
char *playlist_path = mp_normalize_path(ctx, cur->playlist_path);
write_redirect(mpctx, playlist_path);
write_redirects_for_parent_dirs(mpctx, playlist_path);
if (cur->playlist_path && mp_is_url(bstr0(cur->filename))) {
write_redirect(mpctx, cur->playlist_path);
write_redirects_for_parent_dirs(mpctx, cur->playlist_path);
}

exit:
talloc_free(conffile);
talloc_free(ctx);
}

void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file)
{
char *path = mp_normalize_path(NULL, file ? file : mpctx->filename);
char *path = file ? mp_normalize_path(NULL, file)
: talloc_strdup(NULL, mpctx->filename);
if (!path)
goto exit;

Expand Down
2 changes: 1 addition & 1 deletion player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ static void append_to_watch_history(struct MPContext *mpctx)
list->keys[1] = "path";
list->values[1] = (struct mpv_node) {
.format = MPV_FORMAT_STRING,
.u.string = mp_normalize_path(ctx, mpctx->filename),
.u.string = mpctx->filename,
};
if (title) {
list->keys[2] = "title";
Expand Down
5 changes: 1 addition & 4 deletions player/lua/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,13 @@ mp.add_key_binding(nil, "select-playlist", function ()
local playlist = {}
local default_item
local show = mp.get_property_native("osd-playlist-entry")
local trailing_slash_pattern = mp.get_property("platform") == "windows"
and "[/\\]+$" or "/+$"

for i, entry in ipairs(mp.get_property_native("playlist")) do
playlist[i] = entry.title
if not playlist[i] or show ~= "title" then
playlist[i] = entry.filename
if not playlist[i]:find("://") then
playlist[i] = select(2, utils.split_path(
playlist[i]:gsub(trailing_slash_pattern, "")))
playlist[i] = select(2, utils.split_path(playlist[i]))
end
end
if entry.title and show == "both" then
Expand Down
Loading