Skip to content

ykzts/go-mirakurun

Repository files navigation

go-mirakurun

go-mirakurun is a Mirakurun Client for Go.

build status GoDoc

Usage

import "ykzts.com/x/mirakurun"

Channel Scan

c := mirakurun.NewClient()

opt := &mirakurun.ChannelScanOptions{Type: "BS"}
stream, _, err := c.ChannelScan(context.Background(), opt)
if err != nil {
	log.Fatal(err)
}
defer stream.Close()

io.Copy(os.Stdout, stream)

Get Channel List

c := mirakurun.NewClient()

channels, _, err := c.GetChannels(context.Background(), nil)
if err != nil {
	log.Fatal(err)
}

for _, channel := range channels {
	fmt.Printf("%s (%s): %s\n", channel.Channel, channel.Type, channel.Name)
}

Recoding

c := mirakurun.NewClient()

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

stream, _, err := c.GetServiceStream(ctx, 3239123608, true)
if err != nil {
	log.Fatal(err)
}
defer stream.Close()

name := fmt.Sprintf("stream-%d.ts", time.Now().Unix())
file, err := os.Create(name)
if err != nil {
	log.Fatal(err)
}
defer file.Close()

fmt.Printf("save to %s\n", name)

io.Copy(file, stream)

License

MIT