clipper/backend/cmd/progress-test/main.go

68 lines
1.3 KiB
Go
Raw Normal View History

2021-10-27 19:34:59 +00:00
package main
import (
"context"
2021-11-01 05:28:40 +00:00
"database/sql"
2021-10-27 19:34:59 +00:00
"io"
"log"
2021-11-01 05:28:40 +00:00
"os"
2021-10-27 19:34:59 +00:00
2021-11-01 05:28:40 +00:00
"git.netflux.io/rob/clipper/generated/store"
2021-10-27 19:34:59 +00:00
"git.netflux.io/rob/clipper/media"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
2021-11-01 05:28:40 +00:00
"github.com/google/uuid"
2021-10-27 19:34:59 +00:00
"github.com/kkdai/youtube/v2"
2021-11-01 05:28:40 +00:00
_ "github.com/lib/pq"
2021-10-27 19:34:59 +00:00
)
const (
videoID = "N1BufwrE1I8"
)
func main() {
ctx := context.Background()
2021-11-01 05:28:40 +00:00
// Create a store
databaseURL := os.Getenv("DATABASE_URL")
db, err := sql.Open("postgres", databaseURL)
2021-10-27 19:34:59 +00:00
if err != nil {
log.Fatal(err)
}
2021-11-01 05:28:40 +00:00
store := store.New(db)
2021-10-27 19:34:59 +00:00
// Create an Amazon S3 service s3Client
2021-11-01 05:28:40 +00:00
cfg, err := config.LoadDefaultConfig(ctx)
if err != nil {
log.Fatal(err)
}
2021-10-27 19:34:59 +00:00
s3Client := s3.NewFromConfig(cfg)
// Create a Youtube client
var youtubeClient youtube.Client
2021-11-01 05:28:40 +00:00
// Create a MediaSetService
mediaSetService := media.NewMediaSetService(store, &youtubeClient, s3Client)
2021-10-27 20:17:59 +00:00
// Create a progressReader
2021-11-01 05:28:40 +00:00
// TODO: fix
progressReader, err := mediaSetService.GetAudio(ctx, uuid.New(), 100)
2021-10-27 19:34:59 +00:00
if err != nil {
log.Fatalf("error calling fetch service: %v", err)
}
for {
2021-10-27 20:17:59 +00:00
progress, err := progressReader.Read()
2021-10-27 19:34:59 +00:00
if err != nil {
if err != io.EOF {
log.Printf("error reading progress: %v", err)
}
break
}
log.Printf("progress = %+v", progress)
}
log.Println("done")
}