Moved to DownloadOptions

This commit is contained in:
Gamers_indo1223
2024-08-12 12:02:26 +00:00
parent 95037e2caf
commit 65804d5c0f

View File

@ -217,14 +217,14 @@ var TypeFromString = map[string]Type{
// Options for New()
type Options struct {
Type Type
PlaylistStart uint // --playlist-start
PlaylistEnd uint // --playlist-end
Downloader string // --downloader
DownloadThumbnail bool
DownloadSubtitles bool
DownloadSections string // --download-sections
DownloadAudioOnly bool // -x Download audio only from video
Type Type
PlaylistStart uint // --playlist-start
PlaylistEnd uint // --playlist-end
Downloader string // --downloader
DownloadThumbnail bool
DownloadSubtitles bool
DownloadSections string // --download-sections
ProxyUrl string // --proxy URL http://host:port or socks5://host:port
UseIPV4 bool // -4 Make all connections via IPv4
CookiesFromBrowser string // --cookies-from-browser BROWSER[:FOLDER]
@ -523,6 +523,8 @@ func (result Result) Download(ctx context.Context, filter string) (*DownloadResu
}
type DownloadOptions struct {
AudioFormats string // --audio-formats Download audio using formats (best, aac, alac, flac, m4a, mp3, opus, vorbis, wav)
DownloadAudioOnly bool // -x Download audio only from video
// Download format matched by filter (usually a format id or quality designator).
// If filter is empty, then youtube-dl will use its default format selector.
Filter string
@ -624,6 +626,14 @@ func (result Result) DownloadWithOptions(
cmd.Args = append(cmd.Args, "--playlist-items", fmt.Sprint(options.PlaylistIndex))
}
if options.DownloadAudioOnly {
cmd.Args = append(cmd.Args, "-x")
}
if options.AudioFormats != "" {
cmd.Args = append(cmd.Args, "--audio-format", options.AudioFormats)
}
if result.Options.ProxyUrl != "" {
cmd.Args = append(cmd.Args, "--proxy", result.Options.ProxyUrl)
}
@ -640,10 +650,6 @@ func (result Result) DownloadWithOptions(
cmd.Args = append(cmd.Args, "--cookies-from-browser", result.Options.CookiesFromBrowser)
}
if result.Options.DownloadAudioOnly {
cmd.Args = append(cmd.Args, "-x")
}
cmd.Args = append(cmd.Args, "--audio-format", "mp3")
if result.Options.MergeOutputFormat != "" {
cmd.Args = append(cmd.Args,
"--merge-output-format", result.Options.MergeOutputFormat,