Skip to content

Commit 8447aae

Browse files
committed
loadfile: clip long track titles
When a track title is taken from its filename and is very long, clip it to not make track information too verbose. term_disp_width() is convenient even for ASS output because it avoids cutting in the middle of UTF-8 characters. Fixes mpv-player#10975 along with mpv-player#17021.
1 parent 2e5e293 commit 8447aae

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

player/loadfile.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "mpv_talloc.h"
2727

28+
#include "misc/codepoint_width.h"
2829
#include "misc/thread_pool.h"
2930
#include "misc/thread_tools.h"
3031
#include "osdep/io.h"
@@ -909,8 +910,17 @@ int mp_add_external_file(struct MPContext *mpctx, char *filename,
909910
bstr title = bstr0(mp_basename(disp_filename));
910911
bstr_eatstart(&title, parent);
911912
bstr_eatstart(&title, bstr0("."));
912-
if (title.len)
913+
914+
const unsigned char *cut_pos = NULL;
915+
term_disp_width(title, 90, &cut_pos);
916+
if (cut_pos) {
917+
title.len = cut_pos - title.start;
918+
char *title2 = bstrto0(t, title);
919+
t->title = talloc_asprintf(t, "%s…", title2);
920+
talloc_free(title2);
921+
} else if (title.len) {
913922
t->title = bstrdup0(t, title);
923+
}
914924
}
915925
t->external_filename = mp_normalize_user_path(t, mpctx->global, filename);
916926
t->no_default = sh->type != filter;

0 commit comments

Comments
 (0)