mirror of
https://github.com/mpv-player/mpv
synced 2025-02-16 12:17:12 +00:00
playlist: do not add playlist base path to URLs
The entries of a playlist file usually refer either to local files (in the same directory as the playlist), or absolute paths like URLs. In the first case, you want to add the base path of the playlist file to the files, so that mplayer can find the files. In the second case, the URLs should not be changed. Unfortunately, mp_path_join() recognizes URLs as relative paths, and changes them. E.g. it tried to play /path/to/playlist/http://entry. Add some code to deal with this properly. The added code uses the same approach as m_option_type_custom_url in m_option.c, but because it's so short and trivial, it's perhaps better not to rely on the option parser code. It's also unclear whether mp_path_join() should contain this logic, but maybe it's better to keep the logic of that function clean.
This commit is contained in:
parent
b27bc9e3c9
commit
796599bcc2
13
playlist.c
13
playlist.c
@ -162,14 +162,21 @@ struct playlist_entry *playlist_get_next(struct playlist *pl, int direction)
|
||||
return pl->current_was_replaced ? pl->current : pl->current->next;
|
||||
}
|
||||
|
||||
static bool might_be_an_url(bstr f)
|
||||
{
|
||||
return bstr_find0(f, "://") >= 0;
|
||||
}
|
||||
|
||||
void playlist_add_base_path(struct playlist *pl, bstr base_path)
|
||||
{
|
||||
if (base_path.len == 0 || bstrcmp0(base_path, ".") == 0)
|
||||
return;
|
||||
for (struct playlist_entry *e = pl->first; e; e = e->next) {
|
||||
char *new_file = mp_path_join(e, base_path, bstr0(e->filename));
|
||||
talloc_free(e->filename);
|
||||
e->filename = new_file;
|
||||
if (!might_be_an_url(bstr0(e->filename))) {
|
||||
char *new_file = mp_path_join(e, base_path, bstr0(e->filename));
|
||||
talloc_free(e->filename);
|
||||
e->filename = new_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user