Example #1
0
func main() {
	var pn int
	var sc string
	var ps string
	var fl string
	var pageInc int

	flag.IntVar(&pn, "PN", 10000, "The page number (including carousel frame)")
	flag.StringVar(&sc, "SC", "0000", "Page subcode")
	flag.StringVar(&ps, "PS", "80C0", "Page status")
	flag.StringVar(&fl, "FL", "", "Fastext line")
	flag.IntVar(&pageInc, "pageinc", 100, "Page increment per input file")
	flag.Parse()

	for _, fname := range flag.Args() {
		log.Println("Converting", fname)
		bytes, err := ioutil.ReadFile(fname)
		if err != nil {
			log.Fatal(err)
		}

		page := teletext.ConvertTTV("", 0, bytes)
		for i := range page {
			page[i].GetHeader().Page = pn
		}

		ttiFname := fname + ".tti"

		headers := map[string]string{
			"PN": fmt.Sprintf("%d", pn),
			"SC": sc,
			"PS": ps,
		}
		if fl != "" {
			headers["FL"] = fl
		}
		outdata := page.BuildTTI(headers)
		if err := ioutil.WriteFile(ttiFname, outdata, 0666); err != nil {
			panic(err)
		}
		pn += pageInc
	}
	log.Println("Done")
}
Example #2
0
func loadfiles(p string) map[string]anim {
	files, err := ioutil.ReadDir(p)
	fatal(err)

	matcher, err := regexp.Compile("[a-z][0-9]+_[0-9]+\\.ttv")
	fatal(err)

	matches := []string{}
	for _, s := range files {
		if matcher.MatchString(strings.ToLower(path.Base(s.Name()))) {
			matches = append(matches, path.Join(p, s.Name()))
		}
	}

	anims := map[string]anim{}
	for _, m := range matches {
		name := path.Base(m)
		fields := strings.Split(name[1:], "_")

		index, err := strconv.Atoi(fields[0])
		fatal(err)

		length, err := strconv.Atoi(fields[1][:len(fields[1])-4])
		fatal(err)

		data, err := ioutil.ReadFile(m)
		fatal(err)

		ttxframe := teletext.ConvertTTV("televj", 100, data)

		key := strings.ToLower(string(name[0]))
		_, ok := anims[key]
		if !ok {
			anims[key] = anim{}
		}
		anims[key] = append(anims[key], frame{index, length, ttxframe.Serialize()})
	}

	return anims
}