From c6369933f1d9cd204b09be95ef7d4ed1351610e2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 14 May 2020 22:14:49 +0200 Subject: command: add property to return text subtitles in ASS See manpage additions. This was requested, sort of. Although what has been requested might be something completely different. So this is speculative. This also changes sub_get_text() to return an allocated copy, because the buffer shit was too damn messy. --- sub/sd_ass.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'sub/sd_ass.c') diff --git a/sub/sd_ass.c b/sub/sd_ass.c index d51f892dd4..46f16908b0 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -627,7 +627,7 @@ static bool is_whitespace_only(char *s, int len) return true; } -static char *get_text(struct sd *sd, double pts) +static char *get_text_buf(struct sd *sd, double pts, enum sd_text_type type) { struct sd_ass_priv *ctx = sd->priv; ASS_Track *track = ctx->ass_track; @@ -643,7 +643,13 @@ static char *get_text(struct sd *sd, double pts) if (ipts >= event->Start && ipts < event->Start + event->Duration) { if (event->Text) { int start = b.len; - ass_to_plaintext(&b, event->Text); + if (type == SD_TEXT_TYPE_PLAIN) { + ass_to_plaintext(&b, event->Text); + } else { + char *t = event->Text; + while (*t) + append(&b, *t++); + } if (is_whitespace_only(&b.start[start], b.len - start)) { b.len = start; } else { @@ -661,6 +667,11 @@ static char *get_text(struct sd *sd, double pts) return ctx->last_text; } +static char *get_text(struct sd *sd, double pts, enum sd_text_type type) +{ + return talloc_strdup(NULL, get_text_buf(sd, pts, type)); +} + static struct sd_times get_times(struct sd *sd, double pts) { struct sd_ass_priv *ctx = sd->priv; @@ -697,7 +708,7 @@ static void fill_plaintext(struct sd *sd, double pts) ass_flush_events(track); - char *text = get_text(sd, pts); + char *text = get_text_buf(sd, pts, SD_TEXT_TYPE_PLAIN); if (!text) return; -- cgit v1.2.3