Skip to content

Commit 6662363

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. This is also faster since every playlist entry no longer has to be normalized on each file change to check for watch later config files.
1 parent 6f9aac5 commit 6662363

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
@@ -448,15 +448,8 @@ void playlist_set_current(struct playlist *pl)
448448
return;
449449

450450
for (int i = 0; i < pl->num_entries; ++i) {
451-
if (!pl->entries[i]->playlist_path)
452-
continue;
453-
char *path = pl->entries[i]->playlist_path;
454-
if (path[0] != '.')
455-
path = mp_path_join(NULL, pl->playlist_dir, mp_basename(pl->entries[i]->playlist_path));
456-
bool same = !strcmp(pl->entries[i]->filename, path);
457-
if (path != pl->entries[i]->playlist_path)
458-
talloc_free(path);
459-
if (same) {
451+
if (pl->entries[i]->playlist_path &&
452+
!strcmp(pl->entries[i]->filename, pl->entries[i]->playlist_path)) {
460453
pl->current = pl->entries[i];
461454
break;
462455
}

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
@@ -419,21 +419,10 @@ static bool test_path(struct pl_parser *p, char *path, int autocreate)
419419
if (autocreate & AUTO_ANY)
420420
return true;
421421

422-
bstr bpath = bstr0(path);
423-
bstr bstream_path = bstr0(p->real_stream->path);
424-
425-
// When opening a file from cwd, 'path' starts with "./" while stream->path
426-
// matches what the user passed as arg. So it may or not not contain ./.
427-
// Strip it from both to make the comparison work.
428-
if (!mp_path_is_absolute(bstream_path)) {
429-
bstr_eatstart0(&bpath, "./");
430-
bstr_eatstart0(&bstream_path, "./");
431-
}
432-
433-
if (!bstrcmp(bpath, bstream_path))
422+
if (!strcmp(path, p->real_stream->path))
434423
return true;
435424

436-
bstr ext = bstr_get_ext(bpath);
425+
bstr ext = bstr_get_ext(bstr0(path));
437426
if (autocreate & AUTO_VIDEO && str_in_list(ext, p->mp_opts->video_exts))
438427
return true;
439428
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)