Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ package-lock.json
# 程序生成
config.json
Cache/*
Download/*
Download/*

.agent
102 changes: 0 additions & 102 deletions actions.go

This file was deleted.

1 change: 1 addition & 0 deletions backend/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ type TaskInfo struct {
SongName string
SongAuthor string
CoverUrl string
IsDelete bool
}
21 changes: 18 additions & 3 deletions backend/adapter/bilibili/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Audio struct {
option adapter.Option
path adapter.Path
metaData adapter.MetaData
isDelete bool
}

func (a *Audio) SetID(id int) {
Expand All @@ -38,10 +39,23 @@ func NewAudio(auid string, coverUrl, sessdata string, metaData adapter.MetaData)
OutputFormat: constants.AudioType.M4a,
},
metaData: metaData,
isDelete: false,
}
}

func (a *Audio) SetDelete(del bool) {
a.isDelete = del
}

func (a *Audio) SetMeta(songName, author string) {
a.metaData.SongName = songName
a.metaData.Author = author
}

func (a *Audio) Download() error {
if a.isDelete {
return nil
}
var wg sync.WaitGroup
errorResults := make(chan error, 2)

Expand Down Expand Up @@ -77,7 +91,7 @@ func (a *Audio) Download() error {

var err error
for i := 0; i < config.Cfg.DownloadConfig.RetryCount; i++ {
err = utils.SaveFromURL(a.coverUrl, a.path.CoverPath)
err = utils.SaveFromURL(a.coverUrl, a.path.CoverPath, bilibili.GetRandomUA())
if err != nil {
err = errors.New(fmt.Sprintf("failed to download video stream: %v (retry %d)", err, i))
continue
Expand Down Expand Up @@ -116,7 +130,7 @@ func (a *Audio) ConventFormat() error {
}

func (a *Audio) WriteMetadata() error {
newPath := fmt.Sprintf("%s.meta", a.path.StreamPath)
newPath := fmt.Sprintf("%s_meta%s", a.path.StreamPath, a.path.OutputFormat)
err := ffmpeg.WriteMetadata(a.path.CurrentPath, newPath, a.path.CoverPath, a.metaData.SongName, a.metaData.Author, a.path.OutputFormat)
if err != nil {
return err
Expand All @@ -143,7 +157,7 @@ func (a *Audio) downloadStream(streamPath string) error {
}

// 通过流地址下载
err = utils.StreamingDownloader(audio.Stream.StreamLink, streamPath)
err = utils.StreamingDownloader(audio.Stream.StreamLink, streamPath, bilibili.GetRandomUA())
if err != nil {
return errors.New(fmt.Sprintf("failed to download stream: %s", err))
}
Expand All @@ -155,6 +169,7 @@ func (a *Audio) GetTaskInfo() *adapter.TaskInfo {
SongName: a.metaData.SongName,
SongAuthor: a.metaData.Author,
CoverUrl: a.coverUrl,
IsDelete: a.isDelete,
}
return &taskInfo
}
23 changes: 20 additions & 3 deletions backend/adapter/bilibili/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"bili-audio-downloader/bilibili"
"errors"
"fmt"
"github.com/tidwall/gjson"
"strconv"
"sync"

"github.com/tidwall/gjson"
)

type Video struct {
Expand All @@ -23,6 +24,7 @@ type Video struct {
option adapter.Option
path adapter.Path
metaData adapter.MetaData
isDelete bool
}

func NewVideo(bvid string, cid int, coverUrl, sessdata string, metaData adapter.MetaData) *Video {
Expand All @@ -38,14 +40,28 @@ func NewVideo(bvid string, cid int, coverUrl, sessdata string, metaData adapter.
OutputFormat: constants.AudioType.M4a,
},
metaData: metaData,
isDelete: false,
}
}

func (v *Video) SetID(id int) {
v.listId = id
}

func (v *Video) SetDelete(del bool) {
v.isDelete = del
}

func (v *Video) SetMeta(songName, author string) {
v.metaData.SongName = songName
v.metaData.Author = author
}

func (v *Video) Download() error {
if v.isDelete {
return nil
}

var wg sync.WaitGroup
errorResults := make(chan error, 2)

Expand Down Expand Up @@ -80,7 +96,7 @@ func (v *Video) Download() error {

var err error
for i := 0; i < config.Cfg.DownloadConfig.RetryCount; i++ {
err = utils.SaveFromURL(v.coverUrl, v.path.CoverPath)
err = utils.SaveFromURL(v.coverUrl, v.path.CoverPath, bilibili.GetRandomUA())
if err != nil {
err = errors.New(fmt.Sprintf("failed to download video stream: %v (retry %d)", err, i))
continue
Expand Down Expand Up @@ -129,7 +145,7 @@ func (v *Video) downloadStream(streamPath string) error {
}

// 通过流地址下载
err = utils.StreamingDownloader(stream, streamPath)
err = utils.StreamingDownloader(stream, streamPath, bilibili.GetRandomUA())
if err != nil {
return errors.New(fmt.Sprintf("failed to download stream: %s", err))
}
Expand Down Expand Up @@ -179,6 +195,7 @@ func (w *Video) GetTaskInfo() *adapter.TaskInfo {
SongName: w.metaData.SongName,
SongAuthor: w.metaData.Author,
CoverUrl: w.coverUrl,
IsDelete: w.isDelete,
}
return &taskInfo
}
7 changes: 4 additions & 3 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"context"
"errors"
"fmt"
wails "github.com/wailsapp/wails/v2/pkg/runtime"
"log"
"os"
"path/filepath"

wails "github.com/wailsapp/wails/v2/pkg/runtime"

"github.com/spf13/viper"
)

Expand Down Expand Up @@ -165,14 +166,14 @@ func DefaultConfig() *Config {
cfg := Config{
ConfigVersion: constants.CONFIG_VERSION,
DeleteCache: true,
Theme: "lightPink",
Theme: "lightBlue",
DownloadConfig: DownloadConfig{
DownloadThreads: 5,
RetryCount: 10,
},
FileConfig: FileConfig{
ConvertFormat: false, // TODO
FileNameTemplate: "{{.ID}}_{{.Title}}({{.Subtitle}})_{{.Quality}}.{{.Format}}",
FileNameTemplate: "{{.ID}}_{{.Title}}({{.Subtitle}})_{{.Quality}}{{.Format}}",
DownloadPath: "./Download",
CachePath: "./Cache",
VideoListPath: "./Cache/video_list.json",
Expand Down
2 changes: 1 addition & 1 deletion backend/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package constants

const CONFIG_VERSION int = 2
const APP_VERSION string = "4.10.0"
const APP_VERSION string = "4.10.1-rc1"

var AudioType = struct {
M4a string
Expand Down
2 changes: 2 additions & 0 deletions backend/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ type DownloadTask interface {
WriteMetadata() error
ExportFile() error
GetTaskInfo() *adapter.TaskInfo
SetDelete(bool)
SetMeta(string, string)
}
19 changes: 16 additions & 3 deletions backend/download/task_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
bilibili2 "bili-audio-downloader/backend/adapter/bilibili"
"bili-audio-downloader/backend/utils"
"bili-audio-downloader/bilibili"
"github.com/tidwall/gjson"
"strconv"

"github.com/tidwall/gjson"
)

var DownloadList []DownloadTask
Expand Down Expand Up @@ -119,14 +120,20 @@ func AddCollectionTask(sessdata, favlistId string, count int, downloadCompilatio

// 主循环
for i := 0; i < pageCount; i++ {
pageSize := 20
// 处理非完整尾页
if i+1 == pageCount && count%20 != 0 {
pageSize = count % 20
}

// 获取当前分页信息
favlist, err := bilibili.GetFavListObj(favlistId, sessdata, 20, i+1)
if err != nil {
return err
}

// 遍历分页
for j := 0; j < len(favlist.Data.Medias); j++ {
for j := 0; j < len(favlist.Data.Medias) && j < pageSize; j++ {

if favlist.Data.Medias[j].Type == 2 {
// 添加视频到列表
Expand Down Expand Up @@ -170,13 +177,19 @@ func AddCompilationTask(sessdata string, mid, sid, count int, downloadCompilatio

// 主循环
for i := 0; i < pageCount; i++ {
pageSize := 20
// 处理非完整尾页
if i+1 == pageCount && count%20 != 0 {
pageSize = count % 20
}

// 获取当前分页信息
favlist, err := bilibili.GetCompliationObj(mid, sid, 20, i+1)
if err != nil {
return err
}
// 遍历分页
for j := 0; j < len(favlist.Data.Archives); j++ {
for j := 0; j < len(favlist.Data.Archives) && j < pageSize; j++ {
// 添加视频到列表
err := AddVideoTask(sessdata, favlist.Data.Archives[j].Bvid, downloadCompilation)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion backend/ffmpeg/metadata_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ func WriteMetadata(input, output, coverPath, songName, songAuthor string, format
args = append(args, "-id3v2_version", "3")
}

args = append(args, "-f", format[1:], output)
// 确定 ffmpeg 的 -f 参数
formatFlag := format[1:]
if format == constants.AudioType.M4a {
formatFlag = "mp4"
}

args = append(args, "-f", formatFlag, output)

log, err := utils.RunCommand("ffmpeg", args...)
if err != nil {
Expand Down
Loading
Loading