Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --audio-only flag #1304

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func New() *cli.App {
Aliases: []string{"f"},
Usage: "Select specific stream to download",
},
&cli.BoolFlag{
Name: "audio-only",
Aliases: []string{"ao"},
Usage: "Download audio only at best quality",
},
&cli.StringFlag{
Name: "file",
Aliases: []string{"F"},
Expand Down Expand Up @@ -300,6 +305,7 @@ func download(c *cli.Context, videoURL string) error {
Silent: c.Bool("silent"),
InfoOnly: c.Bool("info"),
Stream: c.String("stream-format"),
AudioOnly: c.Bool("audio-only"),
Refer: c.String("refer"),
OutputPath: c.String("output-path"),
OutputName: c.String("output-name"),
Expand Down
15 changes: 15 additions & 0 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Options struct {
InfoOnly bool
Silent bool
Stream string
AudioOnly bool
Refer string
OutputPath string
OutputName string
Expand Down Expand Up @@ -568,6 +569,20 @@ func (downloader *Downloader) Download(data *extractors.Data) error {
return errors.Errorf("no stream named %s", streamName)
}

if downloader.option.AudioOnly {
for _, s := range sortedStreams {
// Looking for the best quality
matches, ok := regexp.MatchString("audio", s.Quality)
if ok != nil {
return errors.Errorf("No audio stream found")
GNUSheep marked this conversation as resolved.
Show resolved Hide resolved
}
if matches {
stream, _ = data.Streams[s.ID]
break
}
}
GNUSheep marked this conversation as resolved.
Show resolved Hide resolved
}

if !downloader.option.Silent {
printStreamInfo(data, stream)
}
Expand Down