From 3c1f4ce6dac98dc70efe29a904e23963cf1a25cb Mon Sep 17 00:00:00 2001 From: Nonoo Date: Mon, 14 Aug 2023 13:47:06 +0200 Subject: [PATCH 1/4] Only use -f arg if filter is given If filter is not given then we let youtube-dl/yt-dlp decide the format to download. --- goutubedl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goutubedl.go b/goutubedl.go index 7df32be..1da583e 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -462,7 +462,7 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu ) // don't need to specify if direct as there is only one // also seems to be issues when using filter with generic extractor - if !result.Info.Direct { + if !result.Info.Direct && filter != "" { cmd.Args = append(cmd.Args, "-f", filter) } From c1dcced79138554c74d0cb9336feb02906d64d8e Mon Sep 17 00:00:00 2001 From: Nonoo Date: Mon, 14 Aug 2023 13:48:26 +0200 Subject: [PATCH 2/4] Add options to set merge output format and sorting format yt-dlp uses mp4 format by default to merge sources with separate video and audio streams. mp4 format does not handle VP9 codec, so adding the ability to set the merge output format, we can set it to use for ex. mkv, which handles VP9 well. With the possibility of setting the sorting format we can tell yt-dlp which criteria to consider as the best format. --- goutubedl.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/goutubedl.go b/goutubedl.go index 1da583e..4e2110c 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -211,6 +211,8 @@ type Options struct { DebugLog Printer StderrFn func(cmd *exec.Cmd) io.Writer // if not nil, function to get Writer for stderr HTTPClient *http.Client // Client for download thumbnail and subtitles (nil use http.DefaultClient) + MergeOutputFormat string // --merge-output-format + SortingFormat string // --format-sort } // Version of youtube-dl. @@ -474,6 +476,18 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu cmd.Args = append(cmd.Args, "--downloader", result.Options.Downloader) } + if result.Options.MergeOutputFormat != "" { + cmd.Args = append(cmd.Args, + "--merge-output-format", result.Options.MergeOutputFormat, + ) + } + + if result.Options.SortingFormat != "" { + cmd.Args = append(cmd.Args, + "--format-sort", result.Options.SortingFormat, + ) + } + cmd.Dir = tempPath var w io.WriteCloser dr.reader, w = io.Pipe() From f483ae69c8c5cf0cbd8bf9661dda50ad13b2ab2a Mon Sep 17 00:00:00 2001 From: Nonoo Date: Tue, 15 Aug 2023 11:51:02 +0200 Subject: [PATCH 3/4] Update Download() usage comment lines --- goutubedl.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/goutubedl.go b/goutubedl.go index 4e2110c..70ec26b 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -427,9 +427,8 @@ type DownloadResult struct { waitCh chan struct{} } -// Download format matched by filter (usually a format id or "best"). -// Filter should not be a combine filter like "1+2" as then youtube-dl -// won't write to stdout. +// Download format matched by filter (usually a format id or quality designator). +// If filter is empty, then youtube-dl will use "best" as the format by default. func (result Result) Download(ctx context.Context, filter string) (*DownloadResult, error) { debugLog := result.Options.DebugLog From 4b1de1d3ad4676716224088a97110da9942ec6ce Mon Sep 17 00:00:00 2001 From: Nonoo Date: Tue, 15 Aug 2023 13:06:07 +0200 Subject: [PATCH 4/4] Make Download() function comment more clear --- goutubedl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/goutubedl.go b/goutubedl.go index 70ec26b..213b71f 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -428,7 +428,7 @@ type DownloadResult struct { } // Download format matched by filter (usually a format id or quality designator). -// If filter is empty, then youtube-dl will use "best" as the format by default. +// If filter is empty, then youtube-dl will use its default format selector. func (result Result) Download(ctx context.Context, filter string) (*DownloadResult, error) { debugLog := result.Options.DebugLog