Skip to content

Commit 0c9ec2a

Browse files
committed
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.
1 parent 172c59a commit 0c9ec2a

File tree

6 files changed

+29
-68
lines changed

6 files changed

+29
-68
lines changed

common/playlist.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,8 @@ void playlist_set_current(struct playlist *pl)
433433
return;
434434

435435
for (int i = 0; i < pl->num_entries; ++i) {
436-
if (!pl->entries[i]->playlist_path)
437-
continue;
438-
char *path = pl->entries[i]->playlist_path;
439-
if (path[0] != '.')
440-
path = mp_path_join(NULL, pl->playlist_dir, mp_basename(pl->entries[i]->playlist_path));
441-
bool same = !strcmp(pl->entries[i]->filename, path);
442-
if (path != pl->entries[i]->playlist_path)
443-
talloc_free(path);
444-
if (same) {
436+
if (pl->entries[i]->playlist_path &&
437+
!strcmp(pl->entries[i]->filename, pl->entries[i]->playlist_path)) {
445438
pl->current = pl->entries[i];
446439
break;
447440
}

demux/demux_libarchive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
7676
struct playlist *pl = talloc_zero(demuxer, struct playlist);
7777
demuxer->playlist = pl;
7878

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

8181
char **files = NULL;
8282
int num_files = 0;

demux/demux_playlist.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -426,21 +426,10 @@ static bool test_path(struct pl_parser *p, char *path, int autocreate)
426426
if (autocreate & AUTO_ANY)
427427
return true;
428428

429-
bstr bpath = bstr0(path);
430-
bstr bstream_path = bstr0(p->real_stream->path);
431-
432-
// When opening a file from cwd, 'path' starts with "./" while stream->path
433-
// matches what the user passed as arg. So it may or not not contain ./.
434-
// Strip it from both to make the comparison work.
435-
if (!mp_path_is_absolute(bstream_path)) {
436-
bstr_eatstart0(&bpath, "./");
437-
bstr_eatstart0(&bstream_path, "./");
438-
}
439-
440-
if (!bstrcmp(bpath, bstream_path))
429+
if (!strcmp(path, p->real_stream->path))
441430
return true;
442431

443-
bstr ext = bstr_get_ext(bpath);
432+
bstr ext = bstr_get_ext(bstr0(path));
444433
if (autocreate & AUTO_VIDEO && str_in_list(ext, p->mp_opts->video_exts))
445434
return true;
446435
if (autocreate & AUTO_AUDIO && str_in_list(ext, p->mp_opts->audio_exts))

player/command.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,7 @@ static int mp_property_path(void *ctx, struct m_property *prop,
510510
MPContext *mpctx = ctx;
511511
if (!mpctx->filename)
512512
return M_PROPERTY_UNAVAILABLE;
513-
char *path = mp_normalize_path(NULL, mpctx->filename);
514-
int r = m_property_strdup_ro(action, arg, path);
515-
talloc_free(path);
516-
return r;
513+
return m_property_strdup_ro(action, arg, mpctx->filename);
517514
}
518515

519516
static int mp_property_filename(void *ctx, struct m_property *prop,
@@ -559,12 +556,8 @@ static int mp_property_stream_open_filename(void *ctx, struct m_property *prop,
559556
return M_PROPERTY_OK;
560557
}
561558
case M_PROPERTY_GET_TYPE:
562-
case M_PROPERTY_GET: {
563-
char *path = mp_normalize_path(NULL, mpctx->stream_open_filename);
564-
int r = m_property_strdup_ro(action, arg, path);
565-
talloc_free(path);
566-
return r;
567-
}
559+
case M_PROPERTY_GET:
560+
return m_property_strdup_ro(action, arg, mpctx->stream_open_filename);
568561
}
569562
return M_PROPERTY_NOT_IMPLEMENTED;
570563
}

player/configfiles.c

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,13 @@ char *mp_get_playback_resume_dir(struct MPContext *mpctx)
209209
}
210210

211211
static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
212-
const char *fname)
212+
const char *path)
213213
{
214214
struct MPOpts *opts = mpctx->opts;
215215
char *res = NULL;
216216
void *tmp = talloc_new(NULL);
217-
const char *path = NULL;
218-
if (mp_is_url(bstr0(fname))) {
219-
path = fname;
220-
} else if (opts->ignore_path_in_watch_later_config) {
221-
path = mp_basename(fname);
222-
} else {
223-
path = mp_normalize_path(tmp, fname);
224-
if (!path)
225-
goto exit;
226-
}
217+
if (opts->ignore_path_in_watch_later_config && !mp_is_url(bstr0(path)))
218+
path = mp_basename(path);
227219
uint8_t md5[16];
228220
av_md5_sum(md5, path, strlen(path));
229221
char *conf = talloc_strdup(tmp, "");
@@ -234,8 +226,6 @@ static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
234226
if (wl_dir && wl_dir[0])
235227
res = mp_path_join(NULL, wl_dir, conf);
236228
talloc_free(wl_dir);
237-
238-
exit:
239229
talloc_free(tmp);
240230
return res;
241231
}
@@ -296,32 +286,29 @@ static void write_redirects_for_parent_dirs(struct MPContext *mpctx, char *path)
296286
// "/a/b/c.mkv" is the current entry, also create resume files for /a/b and
297287
// /a, so that "mpv --directory-mode=lazy /a" resumes playback from
298288
// /a/b/c.mkv even when b isn't the first directory in /a.
289+
char* path_copy = talloc_strdup(NULL, path);
299290
bstr dir = mp_dirname(path);
300291
// There is no need to write a redirect entry for "/".
301-
while (dir.len > 1 && dir.len < strlen(path)) {
302-
path[dir.len] = '\0';
303-
mp_path_strip_trailing_separator(path);
304-
write_redirect(mpctx, path);
305-
dir = mp_dirname(path);
292+
while (dir.len > 1 && dir.len < strlen(path_copy)) {
293+
path_copy[dir.len] = '\0';
294+
mp_path_strip_trailing_separator(path_copy);
295+
write_redirect(mpctx, path_copy);
296+
dir = mp_dirname(path_copy);
306297
}
298+
talloc_free(path_copy);
307299
}
308300

309301
void mp_write_watch_later_conf(struct MPContext *mpctx)
310302
{
311303
struct playlist_entry *cur = mpctx->playing;
312304
char *conffile = NULL;
313-
void *ctx = talloc_new(NULL);
314305

315306
if (!cur)
316307
goto exit;
317308

318-
char *path = mp_normalize_path(ctx, cur->filename);
319-
if (!path)
320-
goto exit;
321-
322309
struct demuxer *demux = mpctx->demuxer;
323310

324-
conffile = mp_get_playback_resume_config_filename(mpctx, path);
311+
conffile = mp_get_playback_resume_config_filename(mpctx, cur->filename);
325312
if (!conffile)
326313
goto exit;
327314

@@ -337,7 +324,7 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
337324
goto exit;
338325
}
339326

340-
write_filename(mpctx, file, path);
327+
write_filename(mpctx, file, cur->filename);
341328

342329
bool write_start = true;
343330
double pos = get_playback_time(mpctx);
@@ -374,34 +361,33 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
374361
}
375362
fclose(file);
376363

377-
if (mpctx->opts->position_check_mtime && !mp_is_url(bstr0(path)) &&
378-
!copy_mtime(path, conffile))
364+
if (mpctx->opts->position_check_mtime && !mp_is_url(bstr0(cur->filename)) &&
365+
!copy_mtime(cur->filename, conffile))
379366
{
380367
MP_WARN(mpctx, "Can't copy mtime from %s to %s\n", cur->filename,
381368
conffile);
382369
}
383370

384-
write_redirects_for_parent_dirs(mpctx, path);
371+
write_redirects_for_parent_dirs(mpctx, cur->filename);
385372

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

397383
exit:
398384
talloc_free(conffile);
399-
talloc_free(ctx);
400385
}
401386

402387
void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file)
403388
{
404-
char *path = mp_normalize_path(NULL, file ? file : mpctx->filename);
389+
char *path = file ? mp_normalize_path(NULL, file)
390+
: talloc_strdup(NULL, mpctx->filename);
405391
if (!path)
406392
goto exit;
407393

player/loadfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ static void append_to_watch_history(struct MPContext *mpctx)
15781578
list->keys[1] = "path";
15791579
list->values[1] = (struct mpv_node) {
15801580
.format = MPV_FORMAT_STRING,
1581-
.u.string = mp_normalize_path(ctx, mpctx->filename),
1581+
.u.string = mpctx->filename,
15821582
};
15831583
if (title) {
15841584
list->keys[2] = "title";

0 commit comments

Comments
 (0)