From a4eb8f75c0644ce5cf7c0bcea6b3efd2a886027d Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 16 Feb 2020 02:03:36 +0100 Subject: sub: add an option to filter subtitles by regex Works as ad-filter. I had some more plans, for example replacing matching text with different text, but for now it's dropping matches only. There's a big warning in the manpage that I might change semantics. For example, I might turn it into a primitive sed. In a sane world, you'd probably write a simple script that processes downloaded subtitles before giving them to mpv, and avoid all this complexity. But we don't live in a sane world, and the sooner you learn this, the happier you will be. (But I also want to run this on muxed subtitles.) This is pretty straightforward. We use POSIX regexes, which are readily available without additional pain or dependencies. This also means it's (apparently) not available on win32 (MinGW). The regex list is because I hate big monolithic regexes, and this makes it slightly better. Very superficially tested. --- options/options.c | 6 ++++++ options/options.h | 3 +++ 2 files changed, 9 insertions(+) (limited to 'options') diff --git a/options/options.c b/options/options.c index 73cd7ff76c..3dc85162fd 100644 --- a/options/options.c +++ b/options/options.c @@ -201,9 +201,15 @@ const struct m_sub_options mp_sub_filter_opts = { .opts = (const struct m_option[]){ OPT_FLAG("sub-filter-sdh", sub_filter_SDH, 0), OPT_FLAG("sub-filter-sdh-harder", sub_filter_SDH_harder, 0), + OPT_FLAG("sub-filter-regex-enable", rf_enable, 0), + OPT_STRINGLIST("sub-filter-regex", rf_items, 0), + OPT_FLAG("sub-filter-regex-warn", rf_warn, 0), {0} }, .size = sizeof(OPT_BASE_STRUCT), + .defaults = &(OPT_BASE_STRUCT){ + .rf_enable = 1, + }, .change_flags = UPDATE_SUB_FILT, }; diff --git a/options/options.h b/options/options.h index 8fbec3161c..cfb6f44813 100644 --- a/options/options.h +++ b/options/options.h @@ -103,6 +103,9 @@ struct mp_subtitle_opts { struct mp_sub_filter_opts { int sub_filter_SDH; int sub_filter_SDH_harder; + int rf_enable; + char **rf_items; + int rf_warn; }; struct mp_osd_render_opts { -- cgit v1.2.3