Skip to content

Commit 65af2e7

Browse files
committed
demux_playlist: add base paths when adding playlist entries
Currently entries in playlist files like m3u are first added to the playlist, and then if they were relative paths the playlist file's dirname is prepended to them. Change it to directly add entries with the correct path. This will be needed to normalize playlist entries as soon as they are added, else normalization would prepend the working directory to entries with relative paths. demux_cue, demux_edl and demux_mkv_timeline don't need to be modified to work with the next commit.
1 parent 3ae5521 commit 65af2e7

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

common/playlist.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,6 @@ struct playlist_entry *playlist_get_first_in_same_playlist(
304304
return entry;
305305
}
306306

307-
void playlist_add_base_path(struct playlist *pl, bstr base_path)
308-
{
309-
if (base_path.len == 0 || bstrcmp0(base_path, ".") == 0)
310-
return;
311-
for (int n = 0; n < pl->num_entries; n++) {
312-
struct playlist_entry *e = pl->entries[n];
313-
if (!mp_is_url(bstr0(e->filename))) {
314-
char *new_file = mp_path_join_bstr(e, base_path, bstr0(e->filename));
315-
talloc_free(e->filename);
316-
e->filename = new_file;
317-
}
318-
}
319-
}
320-
321307
void playlist_set_stream_flags(struct playlist *pl, int flags)
322308
{
323309
for (int n = 0; n < pl->num_entries; n++)

common/playlist.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ struct playlist_entry *playlist_get_first_in_next_playlist(struct playlist *pl,
107107
int direction);
108108
struct playlist_entry *playlist_get_first_in_same_playlist(struct playlist_entry *entry,
109109
char *current_playlist_path);
110-
void playlist_add_base_path(struct playlist *pl, bstr base_path);
111110
void playlist_set_stream_flags(struct playlist *pl, int flags);
112111
int64_t playlist_transfer_entries_to(struct playlist *pl, int dst_index,
113112
struct playlist *source_pl);

demux/demux_playlist.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ struct pl_parser {
101101
bool error;
102102
bool probing;
103103
bool force;
104-
bool add_base;
105104
bool line_allocated;
106105
int autocreate_playlist;
107106
enum demux_check check_level;
@@ -219,9 +218,19 @@ static void pl_free_line(struct pl_parser *p, bstr line)
219218

220219
static void pl_add(struct pl_parser *p, bstr entry)
221220
{
222-
char *s = bstrto0(NULL, entry);
223-
playlist_append_file(p->pl, s);
224-
talloc_free(s);
221+
char *filename;
222+
bstr proto = mp_split_proto(bstr0(p->s->url), NULL);
223+
// Don't add base path to self-expanding protocols
224+
if (!mp_is_url(entry) && bstrcasecmp0(proto, "memory") &&
225+
bstrcasecmp0(proto, "lavf") && bstrcasecmp0(proto, "hex") &&
226+
bstrcasecmp0(proto, "data") && bstrcasecmp0(proto, "fd")) {
227+
filename = mp_path_join_bstr(NULL, mp_dirname(p->s->url), entry);
228+
} else {
229+
filename = bstrto0(NULL, entry);
230+
}
231+
232+
playlist_append_file(p->pl, filename);
233+
talloc_free(filename);
225234
}
226235

227236
static bool pl_eof(struct pl_parser *p)
@@ -279,12 +288,10 @@ static int parse_m3u(struct pl_parser *p)
279288
} else if (bstr_startswith0(line_dup, "#EXT-X-")) {
280289
p->format = "hls";
281290
} else if (line_dup.len > 0 && !bstr_startswith0(line_dup, "#")) {
282-
char *fn = bstrto0(NULL, line_dup);
283-
struct playlist_entry *e = playlist_entry_new(fn);
284-
talloc_free(fn);
291+
pl_add(p, line);
292+
struct playlist_entry *e = playlist_get_last(p->pl);
285293
e->title = talloc_steal(e, title);
286294
title = NULL;
287-
playlist_insert_at(p->pl, e, NULL);
288295
}
289296
pl_free_line(p, line);
290297
line = pl_get_line(p);
@@ -595,7 +602,6 @@ static int parse_dir(struct pl_parser *p)
595602

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

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

601607
done:
@@ -662,7 +668,6 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
662668
p->log = demuxer->log;
663669
p->pl = talloc_zero(p, struct playlist);
664670
p->real_stream = demuxer->stream;
665-
p->add_base = true;
666671

667672
struct demux_opts *opts = mp_get_config_group(p, p->global, &demux_conf);
668673
p->codepage = opts->meta_cp;
@@ -696,16 +701,6 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
696701
p->s = demuxer->stream;
697702
p->utf16 = stream_skip_bom(p->s);
698703
bool ok = fmt->parse(p) >= 0 && !p->error;
699-
if (p->add_base) {
700-
bstr proto = mp_split_proto(bstr0(demuxer->filename), NULL);
701-
// Don't add base path to self-expanding protocols
702-
if (bstrcasecmp0(proto, "memory") && bstrcasecmp0(proto, "lavf") &&
703-
bstrcasecmp0(proto, "hex") && bstrcasecmp0(proto, "data") &&
704-
bstrcasecmp0(proto, "fd"))
705-
{
706-
playlist_add_base_path(p->pl, mp_dirname(demuxer->filename));
707-
}
708-
}
709704
playlist_set_stream_flags(p->pl, demuxer->stream_origin);
710705
demuxer->playlist = talloc_steal(demuxer, p->pl);
711706
demuxer->filetype = p->format ? p->format : fmt->name;

0 commit comments

Comments
 (0)