From b665cb604ac5ad9322b536c4de7334ae2efd84dc Mon Sep 17 00:00:00 2001 From: fengnightstarts Date: Thu, 12 Feb 2026 16:24:54 +0800 Subject: feat: 修复下载错误并添加输出路径选项 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 B站 API 返回 412 错误:添加 User-Agent 和 Referer 请求头 - 新增 -f/--file 参数:指定单个视频的输出文件名 - 新增 -d/--director 参数:指定下载目标文件夹(自动创建不存在的目录) - 添加 DownloadOptions 结构体支持灵活的下载配置 --- cmd/bvd/main.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'cmd/bvd/main.go') diff --git a/cmd/bvd/main.go b/cmd/bvd/main.go index 3a537b4..db473b5 100644 --- a/cmd/bvd/main.go +++ b/cmd/bvd/main.go @@ -19,16 +19,36 @@ func main() { { Name: "download", Usage: "下载指定 BV 号的视频", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "file", + Aliases: []string{"f"}, + Usage: "指定单个视频下载时的输出文件名(不含扩展名)", + }, + &cli.StringFlag{ + Name: "director", + Aliases: []string{"d"}, + Usage: "指定下载目标文件夹(不存在时会自动创建)", + }, + }, Action: func(c *cli.Context) error { bvid := c.Args().First() if bvid == "" { return fmt.Errorf("请提供视频 BV 号") } + outputFile := c.String("file") + outputDir := c.String("director") + // fmt.Printf("Debug: outputFile=%s, outputDir=%s\n", outputFile, outputDir) + biliAPI := api.NewBiliAPI() - downloader := downloader.NewDownloader() + dl := downloader.NewDownloader() + opts := &downloader.DownloadOptions{ + OutputFile: outputFile, + OutputDir: outputDir, + } - return downloader.Start(bvid, biliAPI) + return dl.Start(bvid, biliAPI, opts) }, ArgsUsage: " 欲下载视频的 BV 号", }, -- cgit v1.2.3