Skip to content

Commit 111f3f6

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 implement normalization.
1 parent 0c67ad2 commit 111f3f6

File tree

6 files changed

+21
-63
lines changed

6 files changed

+21
-63
lines changed

common/playlist.c

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

439439
for (int i = 0; i < pl->num_entries; ++i) {
440-
if (!pl->entries[i]->playlist_path)
441-
continue;
442-
char *path = pl->entries[i]->playlist_path;
443-
if (path[0] != '.')
444-
path = mp_path_join(NULL, pl->playlist_dir, mp_basename(pl->entries[i]->playlist_path));
445-
bool same = !strcmp(pl->entries[i]->filename, path);
446-
if (path != pl->entries[i]->playlist_path)
447-
talloc_free(path);
448-
if (same) {
440+
if (pl->entries[i]->playlist_path &&
441+
!strcmp(pl->entries[i]->filename, pl->entries[i]->playlist_path)) {
449442
pl->current = pl->entries[i];
450443
break;
451444
}

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: 12 additions & 29 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
}
@@ -310,18 +300,13 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
310300
{
311301
struct playlist_entry *cur = mpctx->playing;
312302
char *conffile = NULL;
313-
void *ctx = talloc_new(NULL);
314303

315304
if (!cur)
316305
goto exit;
317306

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

324-
conffile = mp_get_playback_resume_config_filename(mpctx, path);
309+
conffile = mp_get_playback_resume_config_filename(mpctx, cur->filename);
325310
if (!conffile)
326311
goto exit;
327312

@@ -337,7 +322,7 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
337322
goto exit;
338323
}
339324

340-
write_filename(mpctx, file, path);
325+
write_filename(mpctx, file, cur->filename);
341326

342327
bool write_start = true;
343328
double pos = get_playback_time(mpctx);
@@ -374,34 +359,32 @@ void mp_write_watch_later_conf(struct MPContext *mpctx)
374359
}
375360
fclose(file);
376361

377-
if (mpctx->opts->position_check_mtime && !mp_is_url(bstr0(path)) &&
378-
!copy_mtime(path, conffile))
362+
if (mpctx->opts->position_check_mtime && !mp_is_url(bstr0(cur->filename)) &&
363+
!copy_mtime(cur->filename, conffile))
379364
{
380365
MP_WARN(mpctx, "Can't copy mtime from %s to %s\n", cur->filename,
381366
conffile);
382367
}
383368

384-
write_redirects_for_parent_dirs(mpctx, path);
369+
write_redirects_for_parent_dirs(mpctx, cur->filename);
385370

386371
// Also write redirect entries for a playlist that mpv expanded if the
387372
// current entry is a URL, this is mostly useful for playing multiple
388373
// archives of images, e.g. with mpv 1.zip 2.zip and quit-watch-later
389374
// on 2.zip, write redirect entries for 2.zip, not just for the archive://
390375
// 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);
376+
if (cur->playlist_path && mp_is_url(bstr0(cur->filename))) {
377+
write_redirect(mpctx, cur->playlist_path);
378+
write_redirects_for_parent_dirs(mpctx, cur->playlist_path);
395379
}
396380

397381
exit:
398382
talloc_free(conffile);
399-
talloc_free(ctx);
400383
}
401384

402385
void mp_delete_watch_later_conf(struct MPContext *mpctx, const char *file)
403386
{
404-
char *path = mp_normalize_path(NULL, file ? file : mpctx->filename);
387+
char *path = file ? mp_normalize_path(NULL, file) : mpctx->filename;
405388
if (!path)
406389
goto exit;
407390

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)