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 2 commits
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
20 changes: 20 additions & 0 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
InfoOnly bool
Silent bool
Stream string
AudioOnly bool
Refer string
OutputPath string
OutputName string
Expand Down Expand Up @@ -568,6 +569,25 @@
return errors.Errorf("no stream named %s", streamName)
}

if downloader.option.AudioOnly {
var isFound bool
for _, s := range sortedStreams {
// Looking for the best quality
matches, err := regexp.MatchString("audio", s.Quality)

Check failure on line 576 in downloader/downloader.go

View workflow job for this annotation

GitHub Actions / Go 1.21 in ubuntu-latest

SA6000: calling regexp.MatchString in a loop has poor performance, consider using regexp.Compile (staticcheck)
GNUSheep marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
if matches {
isFound = true
stream, _ = data.Streams[s.ID]

Check failure on line 582 in downloader/downloader.go

View workflow job for this annotation

GitHub Actions / Go 1.21 in ubuntu-latest

S1005: unnecessary assignment to the blank identifier (gosimple)
break
}
}
GNUSheep marked this conversation as resolved.
Show resolved Hide resolved
if !isFound {
return errors.Errorf("No audio stream found")
}
}

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