From a09d8c9297bba2c4285a5c08b6002d755d55ce74 Mon Sep 17 00:00:00 2001 From: Martin Lindhe Date: Tue, 22 Oct 2024 01:02:17 +0200 Subject: [PATCH] subtitle.RemoveAds(): add verbose argument --- cleaner.go | 6 ++++-- cleaner_test.go | 2 +- cmd/subber/subber.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cleaner.go b/cleaner.go index 129d943..c192d78 100644 --- a/cleaner.go +++ b/cleaner.go @@ -102,7 +102,7 @@ var ( ) // RemoveAds removes advertisement from the subtitles -func (subtitle *Subtitle) RemoveAds(outputPrefix string) *Subtitle { +func (subtitle *Subtitle) RemoveAds(outputPrefix string, verbose bool) *Subtitle { info := color.New(color.FgGreen, color.BgBlack).SprintFunc() orange := color.New(color.FgBlack, color.BgHiYellow).SprintFunc() @@ -120,7 +120,9 @@ func (subtitle *Subtitle) RemoveAds(outputPrefix string) *Subtitle { for _, adLine := range advertisements { if !isAd && strings.Contains(block, adLine) { isAd = true - fmt.Printf("%s [ads] %d %s matched (%s)\n", info(outputPrefix), (orgSeq + 1), orange(sub.Text), adLine) + if verbose { + fmt.Printf("%s [ads] %d %s matched (%s)\n", info(outputPrefix), (orgSeq + 1), orange(sub.Text), adLine) + } break } } diff --git a/cleaner_test.go b/cleaner_test.go index 01759b4..3b6693b 100644 --- a/cleaner_test.go +++ b/cleaner_test.go @@ -35,5 +35,5 @@ func TestRemoveAds(t *testing.T) { makeTime(0, 1, 11, 005), []string{"No ninja!"}, }}} - assert.Equal(t, &expected, in.RemoveAds("")) + assert.Equal(t, &expected, in.RemoveAds("", false)) } diff --git a/cmd/subber/subber.go b/cmd/subber/subber.go index 0a0c73b..4e4109a 100644 --- a/cmd/subber/subber.go +++ b/cmd/subber/subber.go @@ -83,7 +83,7 @@ func cleanupSub(data []byte, filterName string, keepAds bool, sync int, cleanerO return "", err } if !keepAds { - subtitle.RemoveAds(cleanerOutputPrefix) + subtitle.RemoveAds(cleanerOutputPrefix, true) } if sync != 0 { subtitle.ResyncSubs(sync)