tidying up a *lot*; add QoL options
This commit is contained in:
parent
84de96df31
commit
2954689784
6 changed files with 261 additions and 154 deletions
|
|
@ -3,7 +3,6 @@ package youtube
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -161,14 +160,14 @@ func BuildDescription(video *Video) (string, error) {
|
|||
return out.String(), nil
|
||||
}
|
||||
|
||||
func UploadVideo(ctx context.Context, token *oauth2.Token, video *Video) error {
|
||||
func UploadVideo(ctx context.Context, token *oauth2.Token, video *Video) (*youtube.Video, error) {
|
||||
title, err := BuildTitle(video)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to build title: %v", err)
|
||||
return nil, fmt.Errorf("failed to build title: %v", err)
|
||||
}
|
||||
description, err := BuildDescription(video)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to build description: %v", err)
|
||||
return nil, fmt.Errorf("failed to build description: %v", err)
|
||||
}
|
||||
|
||||
service, err := youtube.NewService(
|
||||
|
|
@ -178,7 +177,7 @@ func UploadVideo(ctx context.Context, token *oauth2.Token, video *Video) error {
|
|||
)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create youtube service: %v\n", err)
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
videoService := youtube.NewVideosService(service)
|
||||
|
|
@ -208,24 +207,17 @@ func UploadVideo(ctx context.Context, token *oauth2.Token, video *Video) error {
|
|||
file, err := os.Open(video.Filename)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to open file: %v\n", err)
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
call.Media(file)
|
||||
|
||||
log.Println("Uploading video...")
|
||||
|
||||
res, err := call.Do()
|
||||
ytVideo, err := call.Do()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to upload video: %v\n", err)
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(res, "", " ")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to marshal video data json: %v\n", err)
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(string(data))
|
||||
return nil
|
||||
return ytVideo, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue