Unified · Split
| @@ -434,3 +434,24 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel, · 433 unmodified lines | ||
| 434 | 434 | talloc_free(log); |
| 435 | 435 | return ret; |
| 436 | 436 | } |
| 437 | + | |
| 438 | +void playlist_set_current(struct playlist *pl) | |
| 439 | +{ | |
| 440 | + if (!pl->playlist_dir) | |
| 441 | + return; | |
| 442 | + | |
| 443 | + for (int i = 0; i < pl->num_entries; ++i) { | |
| 444 | + if (!pl->entries[i]->playlist_path) | |
| 445 | + continue; | |
| 446 | + char *path = pl->entries[i]->playlist_path; | |
| 447 | + if (path[0] != '.') | |
| 448 | + path = mp_path_join(NULL, pl->playlist_dir, pl->entries[i]->playlist_path); | |
| 449 | + bool same = !strcmp(pl->entries[i]->filename, path); | |
| 450 | + if (path != pl->entries[i]->playlist_path) | |
| 451 | + talloc_free(path); | |
| 452 | + if (same) { | |
| 453 | + pl->current = pl->entries[i]; | |
| 454 | + break; | |
| 455 | + } | |
| 456 | + } | |
| 457 | +} | |
| @@ -125,4 +125,6 @@ struct playlist *playlist_parse_file(const char *file, struct mp_cancel *cancel, · 124 unmodified lines | ||
| 125 | 125 | |
| 126 | 126 | void playlist_entry_unref(struct playlist_entry *e); |
| 127 | 127 | |
| 128 | +void playlist_set_current(struct playlist *pl); | |
| 129 | + | |
| 128 | 130 | #endif |
| @@ -1042,20 +1042,8 @@ void prepare_playlist(struct MPContext *mpctx, struct playlist *pl) · 1041 unmodified lines | ||
| 1042 | 1042 | if (opts->playlist_pos >= 0) |
| 1043 | 1043 | pl->current = playlist_entry_from_index(pl, opts->playlist_pos); |
| 1044 | 1044 | |
| 1045 | − for (int i = 0; i < pl->num_entries && pl->playlist_dir; ++i) { | |
| 1046 | − if (!pl->entries[i]->playlist_path) | |
| 1047 | − continue; | |
| 1048 | − char *path = pl->entries[i]->playlist_path; | |
| 1049 | − if (path[0] != '.') | |
| 1050 | − path = mp_path_join(NULL, pl->playlist_dir, pl->entries[i]->playlist_path); | |
| 1051 | − bool same = !strcmp(pl->entries[i]->filename, path); | |
| 1052 | − if (path != pl->entries[i]->playlist_path) | |
| 1053 | − talloc_free(path); | |
| 1054 | − if (same) { | |
| 1055 | − pl->current = pl->entries[i]; | |
| 1056 | − break; | |
| 1057 | − } | |
| 1058 | − } | |
| 1045 | + if (pl->playlist_dir) | |
| 1046 | + playlist_set_current(pl); | |
| 1059 | 1047 | |
| 1060 | 1048 | if (opts->shuffle) |
| 1061 | 1049 | playlist_shuffle(pl); |