segmento/main.go

52 lines
1.0 KiB
Go
Raw Permalink Normal View History

2020-07-05 06:15:58 +00:00
package main
import (
"flag"
"log"
"net/http"
"os"
"segmento/pkg/media"
2020-07-08 17:46:14 +00:00
"segmento/pkg/playlist"
2020-07-10 08:35:03 +00:00
"segmento/pkg/s3"
2020-07-05 06:15:58 +00:00
)
func main() {
// TODO accept some flags with:
// URL - source of stream
// TargetLength - length of segments in seconds
// Output
// -d some_dir/ => output playlist and chunks to this directory, cleaning up old files from time to time.
// -b 0.0.0.0:3000 => serve playlist and chunks from an HTTP server bound to this address
var url string
flag.StringVar(&url, "url", "", "URL of MP3 stream")
flag.Parse()
if url == "" {
log.Println("Invalid arguments")
flag.PrintDefaults()
os.Exit(-1)
}
client := &http.Client{}
resp, err := client.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
segmenter := media.NewMP3Segmenter()
publisher := &media.FakePublisher{}
2020-07-08 17:46:14 +00:00
playlist := playlist.NewMediaPlaylist(resp.Body, segmenter, publisher)
2020-07-10 08:35:03 +00:00
playlist.AddConsumer(&s3.Consumer{})
if err = playlist.Run(); err != nil {
2020-07-07 21:28:50 +00:00
log.Fatal(err)
}
2020-07-05 06:15:58 +00:00
log.Println("exiting")
}