feat: basic ass processing (without style)

This commit is contained in:
CDN 2025-04-23 17:42:13 +08:00
parent 8897d7ae90
commit ebbf516689
Signed by: CDN
GPG key ID: 0C656827F9F80080
10 changed files with 2301 additions and 808 deletions

View file

@ -53,6 +53,34 @@ type SubtitleRegion struct {
Settings map[string]string
}
// ASSEvent represents an event entry in an ASS file (dialogue, comment, etc.)
type ASSEvent struct {
Type string // Dialogue, Comment, etc.
Layer int // Layer number (0-based)
StartTime Timestamp // Start time
EndTime Timestamp // End time
Style string // Style name
Name string // Character name
MarginL int // Left margin override
MarginR int // Right margin override
MarginV int // Vertical margin override
Effect string // Transition effect
Text string // The actual text
}
// ASSStyle represents a style definition in an ASS file
type ASSStyle struct {
Name string // Style name
Properties map[string]string // Font name, size, colors, etc.
}
// ASSFile represents an Advanced SubStation Alpha (ASS) file
type ASSFile struct {
ScriptInfo map[string]string // Format, Title, ScriptType, etc.
Styles []ASSStyle // Style definitions
Events []ASSEvent // Dialogue lines
}
// Creates a new empty Subtitle
func NewSubtitle() Subtitle {
return Subtitle{
@ -82,3 +110,42 @@ func NewSubtitleRegion(id string) SubtitleRegion {
Settings: make(map[string]string),
}
}
// NewASSFile creates a new empty ASS file structure with minimal defaults
func NewASSFile() ASSFile {
// Create minimal defaults for a valid ASS file
scriptInfo := map[string]string{
"ScriptType": "v4.00+",
"Collisions": "Normal",
"PlayResX": "640",
"PlayResY": "480",
"Timer": "100.0000",
}
// Create a default style
defaultStyle := ASSStyle{
Name: "Default",
Properties: map[string]string{
"Format": "Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding",
"Style": "Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1",
},
}
return ASSFile{
ScriptInfo: scriptInfo,
Styles: []ASSStyle{defaultStyle},
Events: []ASSEvent{},
}
}
// NewASSEvent creates a new ASS event with default values
func NewASSEvent() ASSEvent {
return ASSEvent{
Type: "Dialogue",
Layer: 0,
Style: "Default",
MarginL: 0,
MarginR: 0,
MarginV: 0,
}
}