// writeFiles writes the output files specified by the '-out' and '-out2' flags. func writeFiles() (err error) { wf := func(name string, sp *srtgears.SubsPack) (err error) { ext := strings.ToLower(path.Ext(name)) switch ext { case ".srt": return srtgears.WriteSrtFile(name, sp) case ".ssa": return srtgears.WriteSsaFile(name, sp) case "": return fmt.Errorf("Output extension not specified!") } return fmt.Errorf("Unsupported file extension, only *.srt and *.ssa are supported: %s", ext) } if e.Out != "" && e.Sp1 != nil { if err = wf(e.Out, e.Sp1); err != nil { return } } if e.Out2 != "" && e.Sp2 != nil { if err = wf(e.Out2, e.Sp2); err != nil { return } } return }
// This example shows how to merge 2 subtitle files to have a dual sub saved in Sub Station Alpha (*.ssa) format. func Example_merge() { sp1, err := srtgears.ReadSrtFile("eng.srt") check(err) // Check / handle error sp2, err := srtgears.ReadSrtFile("hun.srt") check(err) // Check / handle error sp1.Merge(sp2) err = srtgears.WriteSsaFile("eng+hun.ssa", sp1) check(err) // Check / handle error }
// This example shows how to change subtitle color to yellow, // move to top, remove HI (hearing impaired lines), // increase display duration by 10% and save result as a // Sub Station Alpha (*.ssa) file. func Example_misc() { sp1, err := srtgears.ReadSrtFile("eng.srt") check(err) // Check / handle error sp1.SetColor("yellow") sp1.SetPos(srtgears.Top) sp1.RemoveHI() sp1.Lengthen(1.1) err = srtgears.WriteSsaFile("eng2.ssa", sp1) check(err) // Check / handle error }