From 3abe5ae66a3654ceae6963e0517bdbab2ee28cbe Mon Sep 17 00:00:00 2001 From: Gamers_indo1223 <76719536+gamersindo1223@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:13:41 +0000 Subject: [PATCH 1/3] Added Download Audio Only --- goutubedl.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/goutubedl.go b/goutubedl.go index 610cbea..42a0660 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -224,6 +224,7 @@ type Options struct { DownloadThumbnail bool DownloadSubtitles bool DownloadSections string // --download-sections + DownloadAudioOnly bool // -x Download audio only from video 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] @@ -638,7 +639,9 @@ func (result Result) DownloadWithOptions( if result.Options.CookiesFromBrowser != "" { cmd.Args = append(cmd.Args, "--cookies-from-browser", result.Options.CookiesFromBrowser) } - + if result.Options.DownloadAudioOnly { + cmd.Args = append(cmd.Args, "-x") + } if result.Options.MergeOutputFormat != "" { cmd.Args = append(cmd.Args, "--merge-output-format", result.Options.MergeOutputFormat, From 346cfb47a050cfbb972933cb04836d9862d4c7b0 Mon Sep 17 00:00:00 2001 From: Gamers_indo1223 <76719536+gamersindo1223@users.noreply.github.com> Date: Mon, 12 Aug 2024 18:15:44 +0700 Subject: [PATCH 2/3] Update goutubedl.go --- goutubedl.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/goutubedl.go b/goutubedl.go index 42a0660..0862c79 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -639,9 +639,11 @@ func (result Result) DownloadWithOptions( if result.Options.CookiesFromBrowser != "" { 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, From 65804d5c0fddf09476f4e4356634b96628b66428 Mon Sep 17 00:00:00 2001 From: Gamers_indo1223 <76719536+gamersindo1223@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:02:26 +0000 Subject: [PATCH 3/3] Moved to DownloadOptions --- goutubedl.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/goutubedl.go b/goutubedl.go index 0862c79..b785a3c 100644 --- a/goutubedl.go +++ b/goutubedl.go @@ -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,