player/command: add sub-text/ass-full sub-property

This is like sub-text/ass, but it returns a full ASS line, making it suitable for some more advanced scripting use-cases.
This commit is contained in:
rcombs
2024-04-17 01:29:51 -07:00
committed by Kacper Michajłow
parent 437fff9f21
commit 99f1b2b7b4
5 changed files with 31 additions and 2 deletions

View File

@@ -0,0 +1 @@
add `sub-text/ass-full` sub-property

View File

@@ -2833,8 +2833,11 @@ Property list
with line breaks. Contains only the "Text" part of the events. with line breaks. Contains only the "Text" part of the events.
This property is not enough to render ASS subtitles correctly, because ASS This property is not enough to render ASS subtitles correctly, because ASS
header and per-event metadata are not returned. You likely need to do header and per-event metadata are not returned. Use ``/ass-full`` for that.
further filtering on the returned string to make it useful.
``sub-text/ass-full``
Like ``sub-text-ass``, but return the full event with all fields, formatted as
lines in a .ass text file. Use with ``sub-ass-extradata`` for style information.
``sub-text-ass`` (deprecated) ``sub-text-ass`` (deprecated)
Deprecated alias for ``sub-text/ass``. Deprecated alias for ``sub-text/ass``.

View File

@@ -3026,6 +3026,8 @@ static int mp_property_sub_text(void *ctx, struct m_property *prop,
if (!strcmp(ka->key, "ass")) if (!strcmp(ka->key, "ass"))
type = SD_TEXT_TYPE_ASS; type = SD_TEXT_TYPE_ASS;
else if (!strcmp(ka->key, "ass-full"))
type = SD_TEXT_TYPE_ASS_FULL;
else else
return M_PROPERTY_UNKNOWN; return M_PROPERTY_UNKNOWN;

View File

@@ -24,6 +24,7 @@ enum sd_ctrl {
enum sd_text_type { enum sd_text_type {
SD_TEXT_TYPE_PLAIN, SD_TEXT_TYPE_PLAIN,
SD_TEXT_TYPE_ASS, SD_TEXT_TYPE_ASS,
SD_TEXT_TYPE_ASS_FULL,
}; };
struct sd_times { struct sd_times {

View File

@@ -795,6 +795,28 @@ static bstr get_text_buf(struct sd *sd, double pts, enum sd_text_type type)
int start = b->len; int start = b->len;
if (type == SD_TEXT_TYPE_PLAIN) { if (type == SD_TEXT_TYPE_PLAIN) {
ass_to_plaintext(b, event->Text); ass_to_plaintext(b, event->Text);
} else if (type == SD_TEXT_TYPE_ASS_FULL) {
long long s = event->Start;
long long e = s + event->Duration;
ASS_Style *style = (event->Style < 0 || event->Style >= track->n_styles) ? NULL : &track->styles[event->Style];
int sh = (s / 60 / 60 / 1000);
int sm = (s / 60 / 1000) % 60;
int ss = (s / 1000) % 60;
int sc = (s / 10) % 100;
int eh = (e / 60 / 60 / 1000);
int em = (e / 60 / 1000) % 60;
int es = (e / 1000) % 60;
int ec = (e / 10) % 100;
bstr_xappend_asprintf(NULL, b, "Dialogue: %d,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s,%s,%04d,%04d,%04d,%s,%s",
event->Layer,
sh, sm, ss, sc,
eh, em, es, ec,
(style && style->Name) ? style->Name : "", event->Name,
event->MarginL, event->MarginR, event->MarginV,
event->Effect, event->Text);
} else { } else {
bstr_xappend(NULL, b, bstr0(event->Text)); bstr_xappend(NULL, b, bstr0(event->Text));
} }