various: don't normalize playlist filenames again

Since the previous commit normalized playlist filenames when they are
stored, the code normalizing them can be simplified back to how it was
before implementing normalization.
This commit is contained in:
Guido Cella
2025-10-07 22:27:41 +02:00
committed by Dudemanguy
parent dfb4164097
commit fc86b96a8a
6 changed files with 29 additions and 68 deletions
+2 -9
View File
@@ -433,15 +433,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;
}
+1 -1
View File
@@ -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;
+2 -13
View File
@@ -428,21 +428,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))
+3 -10
View File
@@ -516,10 +516,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,
@@ -565,12 +562,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;
}
+20 -34
View File
@@ -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, "");
@@ -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;
}
@@ -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;
@@ -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);
@@ -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;
+1 -1
View File
@@ -1592,7 +1592,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";