diff --git a/cam/utils.go b/cam/utils.go index 4613e5f..722be24 100644 --- a/cam/utils.go +++ b/cam/utils.go @@ -169,20 +169,24 @@ func getSortedFiles(path string) ([]string, error) { if err != nil { return nil, err } - var filePaths []string + var validFilePaths []string for _, file := range files { - filePaths = append(filePaths, filepath.Join(path, file.Name())) + filePath := filepath.Join(path, file.Name()) + _, err := extractDateTimeFromFilename(filePath) + if err == nil { + validFilePaths = append(validFilePaths, filePath) + } } - sort.Slice(filePaths, func(i, j int) bool { - timeI, errI := extractDateTimeFromFilename(filePaths[i]) - timeJ, errJ := extractDateTimeFromFilename(filePaths[j]) + sort.Slice(validFilePaths, func(i, j int) bool { + timeI, errI := extractDateTimeFromFilename(validFilePaths[i]) + timeJ, errJ := extractDateTimeFromFilename(validFilePaths[j]) if errI != nil || errJ != nil { return false } return timeI.Before(timeJ) }) - return filePaths, nil + return validFilePaths, nil } // extractDateTimeFromFilename extracts the date and time from the filename. diff --git a/tests/video-storage/malformed_file_name.mp4 b/tests/video-storage/malformed_file_name.mp4 new file mode 100644 index 0000000..e69de29