From 1e7c16b06b73e2984e9954913dda5b27dd99094e Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Tue, 30 Nov 2021 17:33:33 +0330 Subject: [PATCH 01/15] use item index in WriteToWebVTT --- webvtt.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webvtt.go b/webvtt.go index ebbaec8..2ac74c1 100644 --- a/webvtt.go +++ b/webvtt.go @@ -338,7 +338,7 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) { } // Loop through subtitles - for index, item := range s.Items { + for _, item := range s.Items { // Add comments if len(item.Comments) > 0 { c = append(c, []byte("NOTE ")...) @@ -350,7 +350,7 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) { } // Add time boundaries - c = append(c, []byte(strconv.Itoa(index+1))...) + c = append(c, []byte(strconv.Itoa(item.Index+1))...) c = append(c, bytesLineSeparator...) c = append(c, []byte(formatDurationWebVTT(item.StartAt))...) c = append(c, bytesWebVTTTimeBoundariesSeparator...) From 969140edda40562efd04bfe53d2da3f51eeb8b47 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Wed, 1 Dec 2021 16:30:22 +0330 Subject: [PATCH 02/15] test repo --- README.md | 2 +- astisub/main.go | 2 +- go.mod | 2 +- srt_test.go | 2 +- ssa_test.go | 2 +- stl_test.go | 2 +- subtitles_test.go | 2 +- ttml_test.go | 5 +++-- webvtt_test.go | 2 +- 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d844ee3..9f9ff70 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Available operations are `parsing`, `writing`, `syncing`, `fragmenting`, `unfrag To install the library and command line program, use the following: - go get -u github.com/asticode/go-astisub/... + go get -u github.com/mysamimi/go-astisub/... # Using the library in your code diff --git a/astisub/main.go b/astisub/main.go index 51bc823..4ae50d8 100644 --- a/astisub/main.go +++ b/astisub/main.go @@ -5,7 +5,7 @@ import ( "log" "github.com/asticode/go-astikit" - "github.com/asticode/go-astisub" + "github.com/mysamimi/go-astisub" ) // Flags diff --git a/go.mod b/go.mod index f50c273..eff0d16 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/asticode/go-astisub +module github.com/mysamimi/go-astisub go 1.13 diff --git a/srt_test.go b/srt_test.go index 24cb656..2b654b3 100644 --- a/srt_test.go +++ b/srt_test.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "testing" - "github.com/asticode/go-astisub" + "github.com/mysamimi/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/ssa_test.go b/ssa_test.go index 1807e18..2dfde34 100644 --- a/ssa_test.go +++ b/ssa_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/asticode/go-astikit" - "github.com/asticode/go-astisub" + "github.com/mysamimi/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/stl_test.go b/stl_test.go index f46d2bd..7f50cd7 100644 --- a/stl_test.go +++ b/stl_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/asticode/go-astikit" - "github.com/asticode/go-astisub" + "github.com/mysamimi/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/subtitles_test.go b/subtitles_test.go index 35b573f..e53e0fa 100644 --- a/subtitles_test.go +++ b/subtitles_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/asticode/go-astisub" + "github.com/mysamimi/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/ttml_test.go b/ttml_test.go index 990c821..8d7a130 100644 --- a/ttml_test.go +++ b/ttml_test.go @@ -2,11 +2,12 @@ package astisub_test import ( "bytes" - "github.com/asticode/go-astikit" "io/ioutil" "testing" - "github.com/asticode/go-astisub" + "github.com/asticode/go-astikit" + + "github.com/mysamimi/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/webvtt_test.go b/webvtt_test.go index 3746515..91b2c5c 100644 --- a/webvtt_test.go +++ b/webvtt_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/asticode/go-astisub" + "github.com/mysamimi/go-astisub" "github.com/stretchr/testify/assert" ) From 102b36b4e5c90d75b3f796c7e1b027b203a851f4 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Wed, 1 Dec 2021 18:07:31 +0330 Subject: [PATCH 03/15] rev test repo --- README.md | 2 +- astisub/main.go | 2 +- go.mod | 2 +- srt_test.go | 2 +- ssa_test.go | 2 +- stl_test.go | 2 +- subtitles_test.go | 2 +- ttml_test.go | 2 +- webvtt_test.go | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9f9ff70..d844ee3 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Available operations are `parsing`, `writing`, `syncing`, `fragmenting`, `unfrag To install the library and command line program, use the following: - go get -u github.com/mysamimi/go-astisub/... + go get -u github.com/asticode/go-astisub/... # Using the library in your code diff --git a/astisub/main.go b/astisub/main.go index 4ae50d8..51bc823 100644 --- a/astisub/main.go +++ b/astisub/main.go @@ -5,7 +5,7 @@ import ( "log" "github.com/asticode/go-astikit" - "github.com/mysamimi/go-astisub" + "github.com/asticode/go-astisub" ) // Flags diff --git a/go.mod b/go.mod index eff0d16..f50c273 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/mysamimi/go-astisub +module github.com/asticode/go-astisub go 1.13 diff --git a/srt_test.go b/srt_test.go index 2b654b3..24cb656 100644 --- a/srt_test.go +++ b/srt_test.go @@ -5,7 +5,7 @@ import ( "io/ioutil" "testing" - "github.com/mysamimi/go-astisub" + "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/ssa_test.go b/ssa_test.go index 2dfde34..1807e18 100644 --- a/ssa_test.go +++ b/ssa_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/asticode/go-astikit" - "github.com/mysamimi/go-astisub" + "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/stl_test.go b/stl_test.go index 7f50cd7..f46d2bd 100644 --- a/stl_test.go +++ b/stl_test.go @@ -8,7 +8,7 @@ import ( "time" "github.com/asticode/go-astikit" - "github.com/mysamimi/go-astisub" + "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/subtitles_test.go b/subtitles_test.go index e53e0fa..35b573f 100644 --- a/subtitles_test.go +++ b/subtitles_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/mysamimi/go-astisub" + "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/ttml_test.go b/ttml_test.go index 8d7a130..2d4395b 100644 --- a/ttml_test.go +++ b/ttml_test.go @@ -7,7 +7,7 @@ import ( "github.com/asticode/go-astikit" - "github.com/mysamimi/go-astisub" + "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) diff --git a/webvtt_test.go b/webvtt_test.go index 91b2c5c..3746515 100644 --- a/webvtt_test.go +++ b/webvtt_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/mysamimi/go-astisub" + "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) From d2f7670964fbcdfa67dc96dd5ca3c2a66433ed30 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Thu, 2 Dec 2021 23:48:37 +0330 Subject: [PATCH 04/15] fix index in Order method --- subtitles.go | 1 + 1 file changed, 1 insertion(+) diff --git a/subtitles.go b/subtitles.go index e661799..01d7162 100644 --- a/subtitles.go +++ b/subtitles.go @@ -589,6 +589,7 @@ func (s *Subtitles) Order() { var tmp = s.Items[index-1] s.Items[index-1] = s.Items[index] s.Items[index] = tmp + s.Items[index].Index = index swapped = true } } From abc0985ba868d22583d9e85fdecc136bb4852241 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Thu, 2 Dec 2021 23:59:07 +0330 Subject: [PATCH 05/15] remove index plus one! --- webvtt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webvtt.go b/webvtt.go index 2ac74c1..d422124 100644 --- a/webvtt.go +++ b/webvtt.go @@ -350,7 +350,7 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) { } // Add time boundaries - c = append(c, []byte(strconv.Itoa(item.Index+1))...) + c = append(c, []byte(strconv.Itoa(item.Index))...) c = append(c, bytesLineSeparator...) c = append(c, []byte(formatDurationWebVTT(item.StartAt))...) c = append(c, bytesWebVTTTimeBoundariesSeparator...) From 820c2cb65105cc12d6b5742063d33724b3475987 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Fri, 3 Dec 2021 00:06:06 +0330 Subject: [PATCH 06/15] add FixIndex for Items --- subtitles.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/subtitles.go b/subtitles.go index 01d7162..9652452 100644 --- a/subtitles.go +++ b/subtitles.go @@ -596,6 +596,13 @@ func (s *Subtitles) Order() { } } +// FixIndex fix item index +func (s *Subtitles) FixIndex() { + for i := 0; i < len(s.Items); i++ { + s.Items[i].Index = i + 1 + } +} + // RemoveStyling removes the styling from the subtitles func (s *Subtitles) RemoveStyling() { s.Regions = map[string]*Region{} From 9abe444cb4a00ec1f3be39c4ee0804a6f19a53bf Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Sat, 4 Dec 2021 16:24:38 +0330 Subject: [PATCH 07/15] fix unnessery change --- ttml_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttml_test.go b/ttml_test.go index 2d4395b..8f1e3b0 100644 --- a/ttml_test.go +++ b/ttml_test.go @@ -2,10 +2,10 @@ package astisub_test import ( "bytes" + "github.com/asticode/go-astikit" "io/ioutil" "testing" - "github.com/asticode/go-astikit" "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" From 4ae3e61fea5c253ac3b3419005a8c28a9e2e74ba Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Sat, 4 Dec 2021 16:26:29 +0330 Subject: [PATCH 08/15] fix --- ttml_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ttml_test.go b/ttml_test.go index 8f1e3b0..990c821 100644 --- a/ttml_test.go +++ b/ttml_test.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "testing" - "github.com/asticode/go-astisub" "github.com/stretchr/testify/assert" ) From 82e090d81d1b5babd888af69b9c10d651f9e3e28 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Sun, 16 Jan 2022 08:51:02 +0330 Subject: [PATCH 09/15] fix bad build test & add ClipFrom, ClipTo method --- subtitles.go | 36 +++++++++++++++++++++++++++++++++++- webvtt.go | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/subtitles.go b/subtitles.go index 9652452..cc6fbeb 100644 --- a/subtitles.go +++ b/subtitles.go @@ -596,10 +596,44 @@ func (s *Subtitles) Order() { } } +// ClipFrom clip items from input time +func (s *Subtitles) ClipFrom(cf time.Duration) { + newIndex := 0 + for index := 1; index < len(s.Items); index++ { + s.Items[index].StartAt -= cf + s.Items[index].EndAt -= cf + s.Items[index].Index = newIndex + if s.Items[index].StartAt < 0 { + s.Items[index].StartAt = 0 + } + if s.Items[index].EndAt > 0 { + s.Items[index] = s.Items[newIndex] + newIndex++ + } + } + s.Items = s.Items[:newIndex] +} + +// ClipFrom clip items until input time +func (s *Subtitles) ClipTo(ct time.Duration) { + lastIndex := 0 + for index := 1; index < len(s.Items); index++ { + lastIndex = index + if s.Items[index].StartAt > ct { + break + } + if s.Items[index].EndAt > ct { + s.Items[index].EndAt = ct + break + } + } + s.Items = s.Items[:lastIndex] +} + // FixIndex fix item index func (s *Subtitles) FixIndex() { for i := 0; i < len(s.Items); i++ { - s.Items[i].Index = i + 1 + s.Items[i].Index = i } } diff --git a/webvtt.go b/webvtt.go index d422124..2ac74c1 100644 --- a/webvtt.go +++ b/webvtt.go @@ -350,7 +350,7 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) { } // Add time boundaries - c = append(c, []byte(strconv.Itoa(item.Index))...) + c = append(c, []byte(strconv.Itoa(item.Index+1))...) c = append(c, bytesLineSeparator...) c = append(c, []byte(formatDurationWebVTT(item.StartAt))...) c = append(c, bytesWebVTTTimeBoundariesSeparator...) From aa08cbae866f0ec8bf498016729b94f7a0c18f0e Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Sun, 16 Jan 2022 09:59:56 +0330 Subject: [PATCH 10/15] overload WriteToWebVTT, 2 arg force use item index --- webvtt.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/webvtt.go b/webvtt.go index 2ac74c1..a39c5d4 100644 --- a/webvtt.go +++ b/webvtt.go @@ -277,7 +277,26 @@ func formatDurationWebVTT(i time.Duration) string { } // WriteToWebVTT writes subtitles in .vtt format -func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) { +// if set true in second args write index as item index +func (s Subtitles) WriteToWebVTT(args ...interface{}) (err error) { + var o io.Writer + writeWithIndex := false + for i, arg := range args { + switch i { + case 0: // default output writer + out, ok := arg.(io.Writer) + if !ok { + return fmt.Errorf("first input argument must be io.Writer") + } + o = out + case 1: + b, ok := arg.(bool) + if !ok { + return fmt.Errorf("second input argument must be boolean") + } + writeWithIndex = b + } + } // Do not write anything if no subtitles if len(s.Items) == 0 { err = ErrNoSubtitlesToWrite @@ -338,7 +357,7 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) { } // Loop through subtitles - for _, item := range s.Items { + for index, item := range s.Items { // Add comments if len(item.Comments) > 0 { c = append(c, []byte("NOTE ")...) @@ -350,7 +369,11 @@ func (s Subtitles) WriteToWebVTT(o io.Writer) (err error) { } // Add time boundaries - c = append(c, []byte(strconv.Itoa(item.Index+1))...) + if writeWithIndex { + c = append(c, []byte(strconv.Itoa(item.Index+1))...) + } else { + c = append(c, []byte(strconv.Itoa(index+1))...) + } c = append(c, bytesLineSeparator...) c = append(c, []byte(formatDurationWebVTT(item.StartAt))...) c = append(c, bytesWebVTTTimeBoundariesSeparator...) From d6b6e46cc689f3431985710b76e14d160b0c0eee Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Sun, 16 Jan 2022 10:19:03 +0330 Subject: [PATCH 11/15] remove change in Order method --- subtitles.go | 3 +-- webvtt.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/subtitles.go b/subtitles.go index cc6fbeb..567403c 100644 --- a/subtitles.go +++ b/subtitles.go @@ -589,7 +589,6 @@ func (s *Subtitles) Order() { var tmp = s.Items[index-1] s.Items[index-1] = s.Items[index] s.Items[index] = tmp - s.Items[index].Index = index swapped = true } } @@ -633,7 +632,7 @@ func (s *Subtitles) ClipTo(ct time.Duration) { // FixIndex fix item index func (s *Subtitles) FixIndex() { for i := 0; i < len(s.Items); i++ { - s.Items[i].Index = i + s.Items[i].Index = i + 1 } } diff --git a/webvtt.go b/webvtt.go index a39c5d4..d982f11 100644 --- a/webvtt.go +++ b/webvtt.go @@ -370,7 +370,7 @@ func (s Subtitles) WriteToWebVTT(args ...interface{}) (err error) { // Add time boundaries if writeWithIndex { - c = append(c, []byte(strconv.Itoa(item.Index+1))...) + c = append(c, []byte(strconv.Itoa(item.Index))...) } else { c = append(c, []byte(strconv.Itoa(index+1))...) } From f8731f9b57fd881d261f9240dd9dc3b4aaea1512 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Sun, 16 Jan 2022 10:54:23 +0330 Subject: [PATCH 12/15] add new tests, fix bug :) --- subtitles.go | 6 +++--- subtitles_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/subtitles.go b/subtitles.go index 567403c..f4b2680 100644 --- a/subtitles.go +++ b/subtitles.go @@ -598,7 +598,7 @@ func (s *Subtitles) Order() { // ClipFrom clip items from input time func (s *Subtitles) ClipFrom(cf time.Duration) { newIndex := 0 - for index := 1; index < len(s.Items); index++ { + for index := 0; index < len(s.Items); index++ { s.Items[index].StartAt -= cf s.Items[index].EndAt -= cf s.Items[index].Index = newIndex @@ -616,7 +616,7 @@ func (s *Subtitles) ClipFrom(cf time.Duration) { // ClipFrom clip items until input time func (s *Subtitles) ClipTo(ct time.Duration) { lastIndex := 0 - for index := 1; index < len(s.Items); index++ { + for index := 0; index < len(s.Items); index++ { lastIndex = index if s.Items[index].StartAt > ct { break @@ -626,7 +626,7 @@ func (s *Subtitles) ClipTo(ct time.Duration) { break } } - s.Items = s.Items[:lastIndex] + s.Items = s.Items[:lastIndex+1] } // FixIndex fix item index diff --git a/subtitles_test.go b/subtitles_test.go index 35b573f..3803005 100644 --- a/subtitles_test.go +++ b/subtitles_test.go @@ -276,3 +276,29 @@ func TestSubtitles_RemoveStyling(t *testing.T) { Styles: map[string]*astisub.Style{}, }, s) } + +func TestSubtitles_FixIndex(t *testing.T) { + var s = mockSubtitles() + s.FixIndex() + for i := 0; i < len(s.Items); i++ { + assert.Equal(t, i+1, s.Items[i].Index) + } +} + +func TestSubtitles_ClipTo(t *testing.T) { + var s = mockSubtitles() + s.ClipTo(2 * time.Second) + assert.Equal(t, 1, len(s.Items)) + assert.Equal(t, 1*time.Second, s.Items[0].StartAt) + assert.Equal(t, 2*time.Second, s.Items[0].EndAt) +} + +func TestSubtitles_ClipFrom(t *testing.T) { + var s = mockSubtitles() + s.ClipFrom(2 * time.Second) + assert.Equal(t, 2, len(s.Items)) + assert.Equal(t, 0*time.Second, s.Items[0].StartAt) + assert.Equal(t, 1*time.Second, s.Items[0].EndAt) + assert.Equal(t, 1*time.Second, s.Items[1].StartAt) + assert.Equal(t, 5*time.Second, s.Items[1].EndAt) +} From b0e80b61ec20a129693e1cd8ee5e974d67509d2c Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Tue, 1 Feb 2022 11:06:42 +0330 Subject: [PATCH 13/15] fix clipFrom --- subtitles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subtitles.go b/subtitles.go index f4b2680..b232d4b 100644 --- a/subtitles.go +++ b/subtitles.go @@ -606,7 +606,7 @@ func (s *Subtitles) ClipFrom(cf time.Duration) { s.Items[index].StartAt = 0 } if s.Items[index].EndAt > 0 { - s.Items[index] = s.Items[newIndex] + s.Items[newIndex] = s.Items[index] newIndex++ } } From 44a67b7723a507a37bf1140a3016f3adfff94482 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Tue, 1 Feb 2022 12:28:49 +0330 Subject: [PATCH 14/15] fix clipFrom --- subtitles.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subtitles.go b/subtitles.go index b232d4b..3806649 100644 --- a/subtitles.go +++ b/subtitles.go @@ -598,6 +598,7 @@ func (s *Subtitles) Order() { // ClipFrom clip items from input time func (s *Subtitles) ClipFrom(cf time.Duration) { newIndex := 0 + var items []*Item for index := 0; index < len(s.Items); index++ { s.Items[index].StartAt -= cf s.Items[index].EndAt -= cf @@ -606,11 +607,10 @@ func (s *Subtitles) ClipFrom(cf time.Duration) { s.Items[index].StartAt = 0 } if s.Items[index].EndAt > 0 { - s.Items[newIndex] = s.Items[index] - newIndex++ + items = append(items, s.Items[index]) } } - s.Items = s.Items[:newIndex] + s.Items = items } // ClipFrom clip items until input time From 06b222630812240fefb4c59ef20f636ece2a1c76 Mon Sep 17 00:00:00 2001 From: Mohammad Samimi Date: Tue, 1 Feb 2022 13:49:42 +0330 Subject: [PATCH 15/15] add clone method --- subtitles.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/subtitles.go b/subtitles.go index 3806649..e79fa90 100644 --- a/subtitles.go +++ b/subtitles.go @@ -6,6 +6,7 @@ import ( "math" "os" "path/filepath" + "reflect" "strconv" "strings" "time" @@ -613,6 +614,35 @@ func (s *Subtitles) ClipFrom(cf time.Duration) { s.Items = items } +func copy(source interface{}, destin interface{}) { + x := reflect.ValueOf(source) + if x.Kind() == reflect.Ptr { + starX := x.Elem() + y := reflect.New(starX.Type()) + starY := y.Elem() + starY.Set(starX) + reflect.ValueOf(destin).Elem().Set(y.Elem()) + } +} + +// Clone subtitles +func (s *Subtitles) Clone() *Subtitles { + sub := &Subtitles{} + copy(s.Metadata, sub.Metadata) + for k, r := range s.Regions { + copy(r, sub.Regions[k]) + } + for k, r := range s.Styles { + copy(r, sub.Styles[k]) + } + for i := 0; i < len(s.Items); i++ { + n := &Item{} + copy(s.Items[i], n) + sub.Items = append(sub.Items, n) + } + return sub +} + // ClipFrom clip items until input time func (s *Subtitles) ClipTo(ct time.Duration) { lastIndex := 0