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

73 lines
1.4 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"
"github.com/kkdai/youtube/v2"
2021-11-01 05:28:40 +00:00
_ "github.com/lib/pq"
2021-11-16 06:48:30 +00:00
"go.uber.org/zap"
2021-10-27 19:34:59 +00:00
)
const (
// videoID = "N1BufwrE1I8"
videoID = "LBRIsFbOoc4"
2021-10-27 19:34:59 +00:00
)
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, media.S3API{S3Client: s3Client}, zap.NewNop())
2021-10-27 20:17:59 +00:00
2021-11-02 16:20:47 +00:00
mediaSet, err := mediaSetService.Get(ctx, videoID)
if err != nil {
log.Fatalf("error calling fetch service: %v", err)
}
2021-10-27 20:17:59 +00:00
// Create a progressReader
2021-11-02 18:03:26 +00:00
progressReader, err := mediaSetService.GetAudio(ctx, mediaSet.ID, 2_000)
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")
}