Skip to content

Commit d57ab2c

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 #10975 along with #17021.
1 parent 2e5e293 commit d57ab2c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

player/loadfile.c

Lines changed: 10 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,16 @@ 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+
if (mp_is_url(bstr0(disp_filename)))
916+
term_disp_width(title, 90, &cut_pos);
917+
if (cut_pos) {
918+
title.len = cut_pos - title.start;
919+
t->title = talloc_asprintf(t, "%.*s\u2026", BSTR_P(title));
920+
} else if (title.len) {
913921
t->title = bstrdup0(t, title);
922+
}
914923
}
915924
t->external_filename = mp_normalize_user_path(t, mpctx->global, filename);
916925
t->no_default = sh->type != filter;

0 commit comments

Comments
 (0)