Skip to content

Commit 6eaf358

Browse files
guidocellakasper93
authored andcommitted
command: add support for printing sub-lines
show-text ${sub-lines} can be used to print subtitle lines around the current one and have them hide automatically.
1 parent 59c91de commit 6eaf358

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

player/command.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,34 @@ static int mp_property_sub_lines(void *ctx, struct m_property *prop,
35393539
talloc_free(lines);
35403540
return M_PROPERTY_OK;
35413541
}
3542+
case M_PROPERTY_PRINT: {
3543+
struct sub_lines *lines = sub_get_lines(sub);
3544+
if (!lines)
3545+
return M_PROPERTY_UNAVAILABLE;
3546+
3547+
char *res = talloc_strdup(NULL, "");
3548+
double time_pos = get_playback_time(mpctx);
3549+
int pos = 0;
3550+
3551+
for (int i = 0; i < lines->num_entries; i++) {
3552+
struct sub_line *line = &lines->entries[i];
3553+
const char *reset = "";
3554+
3555+
if (line->start <= time_pos && line->end > time_pos) {
3556+
res = append_selected_style(mpctx, res);
3557+
reset = get_style_reset(mpctx);
3558+
}
3559+
3560+
res = talloc_asprintf_append(res, "%s%s\n", line->text, reset);
3561+
3562+
if (line->start <= time_pos && i)
3563+
pos += count_lines(lines->entries[i - 1].text);
3564+
}
3565+
3566+
*(char **)arg = cut_osd_list(mpctx, "Subtitle lines", res, pos);
3567+
talloc_free(lines);
3568+
return M_PROPERTY_OK;
3569+
}
35423570
}
35433571
return M_PROPERTY_NOT_IMPLEMENTED;
35443572
}

0 commit comments

Comments
 (0)