diff --git a/internal/movie/file.go b/internal/movie/file.go index d00ec37..4773c92 100644 --- a/internal/movie/file.go +++ b/internal/movie/file.go @@ -74,7 +74,7 @@ func (m *Movie) LoadFile(path string, src io.Reader, speed float64) error { bar := progressbar.New() totalDuration := m.Duration() - // Build the rest of every frame and write to disk + // Build the rest of every frame var currentPosition time.Duration m.Sections = make([]int, m.Width+1) for i, f := range m.Frames { diff --git a/internal/movie/file_test.go b/internal/movie/file_test.go index 026b78c..e0a31af 100644 --- a/internal/movie/file_test.go +++ b/internal/movie/file_test.go @@ -1,6 +1,7 @@ package movie import ( + "slices" "testing" "time" @@ -10,7 +11,7 @@ import ( ) func TestLoadFile(t *testing.T) { - const TestFile = "short_intro.txt" + const TestFile = "sw1.txt" f, err := movies.Movies.Open(TestFile) require.NoError(t, err) @@ -22,6 +23,18 @@ func TestLoadFile(t *testing.T) { require.NoError(t, movie.LoadFile(TestFile, f, 1)) assert.Equal(t, TestFile, movie.Filename) - assert.EqualValues(t, 3*time.Second, movie.Duration().Truncate(time.Second)) - assert.Len(t, movie.Frames, 45) + assert.EqualValues(t, 17*time.Minute+44*time.Second, movie.Duration().Truncate(time.Second)) + assert.Len(t, movie.Frames, 3410) + assert.Equal(t, 67, movie.Width) + assert.Equal(t, 13, movie.Height) + assert.Len(t, movie.Sections, 68) + var current time.Duration + totalDuration := movie.Duration() + for i, frame := range movie.Frames { + current += frame.Duration + if sectionIdx := slices.Index(movie.Sections, i); sectionIdx != -1 { + timeSection := int(current * time.Duration(movie.Width) / totalDuration) + assert.Equal(t, sectionIdx, timeSection) + } + } }