Merge pull request #154 from nonoo/master
Add 2 new options, and make filter use optional
This commit is contained in:
21
goutubedl.go
21
goutubedl.go
@ -211,6 +211,8 @@ type Options struct {
|
|||||||
DebugLog Printer
|
DebugLog Printer
|
||||||
StderrFn func(cmd *exec.Cmd) io.Writer // if not nil, function to get Writer for stderr
|
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)
|
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.
|
// Version of youtube-dl.
|
||||||
@ -425,9 +427,8 @@ type DownloadResult struct {
|
|||||||
waitCh chan struct{}
|
waitCh chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Download format matched by filter (usually a format id or "best").
|
// Download format matched by filter (usually a format id or quality designator).
|
||||||
// Filter should not be a combine filter like "1+2" as then youtube-dl
|
// If filter is empty, then youtube-dl will use its default format selector.
|
||||||
// won't write to stdout.
|
|
||||||
func (result Result) Download(ctx context.Context, filter string) (*DownloadResult, error) {
|
func (result Result) Download(ctx context.Context, filter string) (*DownloadResult, error) {
|
||||||
debugLog := result.Options.DebugLog
|
debugLog := result.Options.DebugLog
|
||||||
|
|
||||||
@ -462,7 +463,7 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
|
|||||||
)
|
)
|
||||||
// don't need to specify if direct as there is only one
|
// don't need to specify if direct as there is only one
|
||||||
// also seems to be issues when using filter with generic extractor
|
// 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)
|
cmd.Args = append(cmd.Args, "-f", filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,6 +475,18 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
|
|||||||
cmd.Args = append(cmd.Args, "--downloader", result.Options.Downloader)
|
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
|
cmd.Dir = tempPath
|
||||||
var w io.WriteCloser
|
var w io.WriteCloser
|
||||||
dr.reader, w = io.Pipe()
|
dr.reader, w = io.Pipe()
|
||||||
|
Reference in New Issue
Block a user