aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/bvd
diff options
context:
space:
mode:
authorfengnightstarts <fengnightstarts@users.noreply.github.com>2026-02-12 16:24:54 +0800
committerfengnightstarts <fengnightstarts@users.noreply.github.com>2026-02-12 16:24:54 +0800
commitb665cb604ac5ad9322b536c4de7334ae2efd84dc (patch)
treeeee8cdfc82bd03f2e4b464e4ca66738f7cc5dc81 /cmd/bvd
parentc52f41545df179b542f106d08e6dd013a70216e7 (diff)
downloadbvd-b665cb604ac5ad9322b536c4de7334ae2efd84dc.tar.gz
bvd-b665cb604ac5ad9322b536c4de7334ae2efd84dc.zip
feat: 修复下载错误并添加输出路径选项
- 修复 B站 API 返回 412 错误:添加 User-Agent 和 Referer 请求头 - 新增 -f/--file 参数:指定单个视频的输出文件名 - 新增 -d/--director 参数:指定下载目标文件夹(自动创建不存在的目录) - 添加 DownloadOptions 结构体支持灵活的下载配置
Diffstat (limited to 'cmd/bvd')
-rw-r--r--cmd/bvd/main.go24
1 files changed, 22 insertions, 2 deletions
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: "<BVID> 欲下载视频的 BV 号",
},