A Go library for parsing subtitle files in .srt
, .ass
, .ssa
, .vtt
formats into a JSON format. This project is a Go rewrite of the TypeScript library SubParse, offering a simple and efficient way to work with subtitle data programmatically.
- Supports Multiple Subtitle Formats: Convert subtitle files in
.srt
,.ass
,.ssa
and.vtt
formats into JSON. - Automatic File Detection: Automatically identifies and parses subtitle files based on their extension.
- Customizable Output: Tailor the JSON output to your needs with various format options.
To install GoSubParse, you need to use Go modules. First, initialize your module, then get the library:
go mod init your-module-name
go get github.com/your-username/subparse-go
To use GoSubParse in your project, follow these steps:
-
Import the Library:
import "github.com/your-username/subparse-go/pkg/parser"
-
Call
ParseSubtitleFile
:Use the
ParseSubtitleFile
function to parse your subtitle files. Provide the path to the file you want to parse.The function automatically detects the subtitle format (e.g., SRT, ASS) based on the file content.
Example usage:
package main import ( "fmt" "log" "github.com/your-username/subparse-go/pkg/parser" ) func main() { filePath := "path/to/your/subtitle/file.srt" subtitleData, err := parser.ParseSubtitleFile(filePath) if err != nil { log.Fatalf("Error parsing file: %v", err) } fmt.Printf("Parsed data: %+v\n", subtitleData) }
Example output for an SRT file with the following content:
1 00:00:01,000 --> 00:00:04,000 Hello, world!
Would be:
[ { "line": 1, "start": "00:00:01,000", "end": "00:00:04,000", "text": "Hello, world!" } ]
This project is licensed under the MIT License. See the LICENSE file for details.