knadh / go-get-youtube

A tiny Go library + client for downloading Youtube videos. The library is capable of fetching Youtube video metadata, in addition to downloading videos.
158 stars 35 forks source link

Example fails with video size returned as 0 Bytes #17

Open skekre98 opened 3 years ago

skekre98 commented 3 years ago
import (
    "fmt"
    "strings"
    // "errors"
    "github.com/pkg/browser"
    "github.com/spf13/cobra"
    yt "github.com/knadh/go-get-youtube/youtube"
)

func youtubeDownload(url string) error {
    video, err := yt.Get(url)
    if err != nil {
        return err
    }

    options := &yt.Option{
        Rename: true,  // rename file using video title
        Resume: true,  // resume cancelled download
        Mp3:    true,  // extract audio to MP3
    }
    video.Download(0, "video.mp4", options)
    return nil
}

Tried implementing youtube download functionality in my program, but the example is returning empty mp4 files on all videos I have tried including the one in the example. The actual code runs fine and somehow is not throwing any errors. Perhaps there is a missing error check somewhere?

cofonseca commented 3 years ago

@skekre98 I think you're probably seeing the same issue as #14 . You are indeed missing an error check! video.Download() returns an error, so make sure you're checking for an err when using video.Download(). For example:

err := vid.Download(0, "C:/Users/jsmith/Downloads/video.mp4", options)
if err != nil {
    fmt.Println(err)
}

Hope this helps.

incafox commented 3 years ago

@skekre98 I think you're probably seeing the same issue as #14 . You are indeed missing an error check! video.Download() returns an error, so make sure you're checking for an err when using video.Download(). For example:

err := vid.Download(0, "C:/Users/jsmith/Downloads/video.mp4", options)
if err != nil {
    fmt.Println(err)
}

Hope this helps.

"unsupported protocol scheme"