73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
|
|
"git.netflux.io/rob/clipper/generated/store"
|
|
"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/google/uuid"
|
|
"github.com/kkdai/youtube/v2"
|
|
_ "github.com/lib/pq"
|
|
)
|
|
|
|
const (
|
|
videoID = "N1BufwrE1I8"
|
|
)
|
|
|
|
func main() {
|
|
ctx := context.Background()
|
|
|
|
// Create a store
|
|
databaseURL := os.Getenv("DATABASE_URL")
|
|
db, err := sql.Open("postgres", databaseURL)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
store := store.New(db)
|
|
|
|
// Create an Amazon S3 service s3Client
|
|
cfg, err := config.LoadDefaultConfig(ctx)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
s3Client := s3.NewFromConfig(cfg)
|
|
|
|
// Create a Youtube client
|
|
var youtubeClient youtube.Client
|
|
|
|
// Create a MediaSetService
|
|
mediaSetService := media.NewMediaSetService(store, &youtubeClient, s3Client)
|
|
|
|
mediaSet, err := mediaSetService.Get(ctx, videoID)
|
|
if err != nil {
|
|
log.Fatalf("error calling fetch service: %v", err)
|
|
}
|
|
|
|
// Create a progressReader
|
|
id := uuid.MustParse(mediaSet.ID)
|
|
progressReader, err := mediaSetService.GetAudio(ctx, id, 100)
|
|
if err != nil {
|
|
log.Fatalf("error calling fetch service: %v", err)
|
|
}
|
|
|
|
for {
|
|
progress, err := progressReader.Read()
|
|
if err != nil {
|
|
if err != io.EOF {
|
|
log.Printf("error reading progress: %v", err)
|
|
}
|
|
break
|
|
}
|
|
|
|
log.Printf("progress = %+v", progress)
|
|
}
|
|
|
|
log.Println("done")
|
|
}
|