From 1d5f247aa2fff5e3afbc076fb6091aab3b4dd097 Mon Sep 17 00:00:00 2001 From: ocfox Date: Fri, 27 Sep 2024 14:42:27 +0800 Subject: [PATCH] feat: support bilibili audio only download --- downloader/downloader.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/downloader/downloader.go b/downloader/downloader.go index b374dc30f..6abd1a447 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -587,6 +587,13 @@ func (downloader *Downloader) Download(data *extractors.Data) error { stream = data.Streams[s.ID] break } + for _, part := range s.Parts { + if part.Ext == "m4a" { + isFound = true + stream = data.Streams[s.ID] + break + } + } } if !isFound { return errors.Errorf("No audio stream found") @@ -658,6 +665,10 @@ func (downloader *Downloader) Download(data *extractors.Data) error { break } + if downloader.option.AudioOnly && (part.Ext != "m4a") { + continue + } + partFileName := fmt.Sprintf("%s[%d]", title, index) partFilePath, err := utils.FilePath(partFileName, part.Ext, downloader.option.FileNameLength, downloader.option.OutputPath, false) if err != nil { @@ -687,7 +698,7 @@ func (downloader *Downloader) Download(data *extractors.Data) error { } downloader.bar.Finish() - if data.Type != extractors.DataTypeVideo { + if data.Type != extractors.DataTypeVideo || downloader.option.AudioOnly { return nil }