Skip to content

Commit

Permalink
added demo video
Browse files Browse the repository at this point in the history
  • Loading branch information
allan committed Jul 8, 2024
1 parent 48bbc7b commit b28c2fd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": "launch",
"mode": "auto",
"cwd": "${workspaceFolder}",
"program": "main.go",
"program": "${workspaceFolder}",
"env": {
"APP_ENV": "local"
},
Expand Down
Binary file added BigBuckBunny_320x180.mp4
Binary file not shown.
25 changes: 25 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package main

import (
"flag"
"fmt"
"log"
"os"

"google.golang.org/api/youtube/v3"
)

var (
filename = flag.String("filename", "BigBuckBunny_320x180.mp4", "Name of video file to upload")
)

func main() {

//appConfig := env.GetEnvConfig()

flag.Parse()

if *filename == "" {
log.Fatalf("You must provide a filename of a video file to upload")
}

client := getClient(youtube.YoutubeUploadScope)

service, err := youtube.New(client)
Expand All @@ -34,4 +47,16 @@ func main() {
log.Println("Uploading video...", service)
call := service.Videos.Insert([]string{"snippet", "status"}, upload)
log.Println("Uploading video...", call)

file, err := os.Open(*filename)
defer file.Close()
if err != nil {
log.Fatalf("Error opening %v: %v", *filename, err)
}

response, err := call.Media(file).Do()
if err != nil {
log.Fatalf("Error making YouTube API call: %v", err)
}
fmt.Printf("Upload successful! Video ID: %v\n", response.Id)
}
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
// config.RedirectURL = "urn:ietf:wg:oauth:2.0:oob"
// 3. When running the script, complete the auth flow. Then copy the
// authorization code from the browser and enter it on the command line.
const launchWebServer = false
const launchWebServer = true

// getClient uses a Context and Config to retrieve a Token
// then generate a Client. It returns the generated Client.
Expand Down

0 comments on commit b28c2fd

Please sign in to comment.