diff --git a/cmd/goutubedl/main.go b/cmd/goutubedl/main.go index 0c0af57..13efbab 100644 --- a/cmd/goutubedl/main.go +++ b/cmd/goutubedl/main.go @@ -31,7 +31,7 @@ func main() { } if *dumpFlag { - json.NewEncoder(os.Stdout).Encode(result.Info) + _ = json.NewEncoder(os.Stdout).Encode(result.Info) return } diff --git a/goutubedl.go b/goutubedl.go index 359b826..7df32be 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -202,8 +202,9 @@ var TypeFromString = map[string]Type{ // Options for New() type Options struct { Type Type - PlaylistStart uint // --playlist-start - PlaylistEnd uint // --playlist-end + PlaylistStart uint // --playlist-start + PlaylistEnd uint // --playlist-end + Downloader string // --downloader DownloadThumbnail bool DownloadSubtitles bool ProxyUrl string // --proxy URL http://host:port or socks5://host:port @@ -264,6 +265,10 @@ func infoFromURL(ctx context.Context, rawURL string, options Options) (info Info cmd.Args = append(cmd.Args, "--proxy", options.ProxyUrl) } + if options.Downloader != "" { + cmd.Args = append(cmd.Args, "--downloader", options.Downloader) + } + if options.Type == TypePlaylist { cmd.Args = append(cmd.Args, "--yes-playlist") @@ -465,6 +470,10 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu cmd.Args = append(cmd.Args, "--proxy", result.Options.ProxyUrl) } + if result.Options.Downloader != "" { + cmd.Args = append(cmd.Args, "--downloader", result.Options.Downloader) + } + cmd.Dir = tempPath var w io.WriteCloser dr.reader, w = io.Pipe() @@ -483,7 +492,7 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu } go func() { - cmd.Wait() + _ = cmd.Wait() w.Close() os.RemoveAll(tempPath) close(dr.waitCh) diff --git a/goutubedl_test.go b/goutubedl_test.go index bbb2a94..c4eb51b 100644 --- a/goutubedl_test.go +++ b/goutubedl_test.go @@ -187,7 +187,7 @@ func TestPlaylist(t *testing.T) { } } -func TestTestUnsupportedURL(t *testing.T) { +func TestUnsupportedURL(t *testing.T) { defer leaktest.Check(t)() _, ydlResultErr := goutubedl.New(context.Background(), "https://www.google.com", goutubedl.Options{}) @@ -273,6 +273,31 @@ func TestErrorNotASingleEntry(t *testing.T) { DownloadThumbnail: false, }) if ydlResultErr != goutubedl.ErrNotASingleEntry { - t.Errorf("expected is single entry error, got %s", ydlResultErr) + t.Fatalf("expected is single entry error, got %s", ydlResultErr) } } + +func TestOptionDownloader(t *testing.T) { + defer leakChecks(t)() + + ydlResult, ydlResultErr := goutubedl.New( + context.Background(), + testVideoRawURL, + goutubedl.Options{ + Downloader: "ffmpeg", + }) + + if ydlResultErr != nil { + t.Fatalf("failed to download: %s", ydlResultErr) + } + dr, err := ydlResult.Download(context.Background(), ydlResult.Info.Formats[0].FormatID) + if err != nil { + t.Fatal(err) + } + downloadBuf := &bytes.Buffer{} + _, err = io.Copy(downloadBuf, dr) + if err != nil { + t.Fatal(err) + } + dr.Close() +}