feat: vtt converting

This commit is contained in:
CDN 2025-04-23 10:44:08 +08:00
parent ba2e477dc0
commit ba66894e42
Signed by: CDN
GPG key ID: 0C656827F9F80080
7 changed files with 693 additions and 107 deletions

View file

@ -0,0 +1,30 @@
package txt
import (
"fmt"
"os"
"sub-cli/internal/model"
)
// GenerateFromSubtitle converts our intermediate Subtitle to plain text format
func GenerateFromSubtitle(subtitle model.Subtitle, filePath string) error {
file, err := os.Create(filePath)
if err != nil {
return fmt.Errorf("error creating TXT file: %w", err)
}
defer file.Close()
// Write title if available
if subtitle.Title != "" {
fmt.Fprintln(file, subtitle.Title)
fmt.Fprintln(file)
}
// Write content without timestamps
for _, entry := range subtitle.Entries {
fmt.Fprintln(file, entry.Text)
}
return nil
}