示例#1
0
文件: srtgears.go 项目: icza/srtgears
// 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
}
示例#2
0
// This example shows how to concatenate 2 files where 2nd part of the movie starts at 51 min 15 sec.
func Example_concat() {
	sp1, err := srtgears.ReadSrtFile("cd1.srt")
	check(err) // Check / handle error
	sp2, err := srtgears.ReadSrtFile("cd2.srt")
	check(err) // Check / handle error
	secPartStart := time.Minute*51 + time.Second*15
	sp1.Concatenate(sp2, secPartStart)
	err = srtgears.WriteSrtFile("cd12.srt", sp1)
	check(err) // Check / handle error
}