Skip to content

Commit

Permalink
fix: 错误往B站接口提交不存在的参数 (#158)
Browse files Browse the repository at this point in the history
* CLI upload supports switching submission interface

* Change submit option scope

* Using enum for SubmitOption

* Use derive to simplify code

* Replace tabs with spaces

* fix
  • Loading branch information
xxxxuanran authored Jun 6, 2024
1 parent 36790ce commit a39ece2
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 49 deletions.
62 changes: 31 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,37 @@ B 站命令行投稿工具,支持**短信登录**、**账号密码登录**、*

```shell
$ biliup help upload

USAGE:
biliup.exe upload [OPTIONS] [VIDEO_PATH]...

ARGS:
<VIDEO_PATH>... 需要上传的视频路径,若指定配置文件投稿不需要此参数

OPTIONS:
-c, --config <FILE> Sets a custom config file
--copyright <COPYRIGHT> 是否转载, 1-自制 2-转载 [default: 1]
--cover <COVER> 视频封面 [default: ]
--desc <DESC> 视频简介 [default: ]
--dolby <DOLBY> 是否开启杜比音效, 0-关闭 1-开启 [default: 0]
--hires <LOSSLESS_MUSIC> 是否开启 Hi-Res, 0-关闭 1-开启 [default: 0]
--dtime <DTIME> 延时发布时间,距离提交大于4小时,格式为10位时间戳
--dynamic <DYNAMIC> 空间动态 [default: ]
-h, --help Print help information
--interactive <INTERACTIVE> [default: 0]
-l, --line <LINE> 选择上传线路 [possible values: bda2, ws, qn, kodo, cos, cos-
internal, bldsa]
--limit <LIMIT> 单视频文件最大并发数 [default: 3]
--mission-id <MISSION_ID>
--no-reprint <NO_REPRINT> 自制声明, 0-允许转载,1-禁止转载 [default: 0]
--open-elec <OPEN_ELEC> 是否开启充电面板, 0-关闭 1-开启 [default: 0]
--source <SOURCE> 转载来源 [default: ]
--tag <TAG> 视频标签,逗号分隔多个tag [default: ]
--tid <TID> 投稿分区 [default: 171]
--title <TITLE> 视频标题 [default: ]
--up-close-danmu
--up-close-reply
--up-selection-reply
上传视频

Usage: biliup upload [OPTIONS] [VIDEO_PATH]...

Arguments:
[VIDEO_PATH]... 需要上传的视频路径,若指定配置文件投稿不需要此参数

Options:
--submit <SUBMIT> 提交接口 [default: client] [possible values: client, app, web]
-c, --config <FILE> Sets a custom config file
-l, --line <LINE> 选择上传线路 [possible values: bda2, ws, qn, bldsa, tx, txa, bda]
--limit <LIMIT> 单视频文件最大并发数 [default: 3]
--copyright <COPYRIGHT> 是否转载, 1-自制 2-转载 [default: 1]
--source <SOURCE> 转载来源 [default: ]
--tid <TID> 投稿分区 [default: 171]
--cover <COVER> 视频封面 [default: ]
--title <TITLE> 视频标题 [default: ]
--desc <DESC> 视频简介 [default: ]
--dynamic <DYNAMIC> 空间动态 [default: ]
--tag <TAG> 视频标签,逗号分隔多个tag [default: ]
--dtime <DTIME> 延时发布时间,距离提交大于4小时,格式为10位时间戳
--interactive <INTERACTIVE> [default: 0]
--mission-id <MISSION_ID>
--dolby <DOLBY> 是否开启杜比音效, 0-关闭 1-开启 [default: 0]
--hires <LOSSLESS_MUSIC> 是否开启 Hi-Res, 0-关闭 1-开启 [default: 0]
--no-reprint <NO_REPRINT> 0-允许转载,1-禁止转载 [default: 0]
--open-elec <OPEN_ELEC> 是否开启充电, 0-关闭 1-开启 [default: 0]
--up-selection-reply 是否开启精选评论,仅提交接口为app时可用
--up-close-reply 是否关闭评论,仅提交接口为app时可用
--up-close-danmu 是否关闭弹幕,仅提交接口为app时可用
-h, --help Print help
```

- 下载视频:`./biliup download https://xxxx`
Expand Down
11 changes: 7 additions & 4 deletions crates/biliup/src/uploader/bilibili.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,24 @@ pub struct Studio {
#[clap(skip)]
pub aid: Option<u64>,

/// 是否开启精选评论,仅提交接口为app时可用
#[clap(long)]
#[serde(default)]
pub up_selection_reply: bool,

/// 是否关闭评论,仅提交接口为app时可用
#[clap(long)]
#[serde(default)]
pub up_close_reply: bool,

/// 是否关闭弹幕,仅提交接口为app时可用
#[clap(long)]
#[serde(default)]
pub up_close_danmu: bool,

#[clap(long)]
#[serde(default)]
pub submit_by_app: bool,
// #[clap(long)]
// #[serde(default)]
// pub submit_by_app: bool,
}

#[derive(Default, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -199,7 +202,7 @@ impl FromStr for Vid {
let s = s.trim();
if s.len() < 3 {
return s.parse::<u64>()
.map(|val| Vid::Aid(val));
.map(Vid::Aid);
}
match &s[..2] {
"BV" => Ok(Vid::Bvid(s.to_string())),
Expand Down
13 changes: 13 additions & 0 deletions crates/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ pub enum Commands {
Renew,
/// 上传视频
Upload {
/// 提交接口
#[arg(long, default_value = "client")]
submit: SubmitOption,

// Optional name to operate on
// name: Option<String>,

/// 需要上传的视频路径,若指定配置文件投稿不需要此参数
#[arg()]
video_path: Vec<PathBuf>,
Expand Down Expand Up @@ -144,6 +149,14 @@ pub enum UploadLine {
Bda
}

#[derive(Debug, Clone, ValueEnum)]
pub enum SubmitOption {
Client,
App,
Web,
}


fn human_size(s: &str) -> Result<u64, String> {
let ret = match s.as_bytes() {
[init @ .., b'K'] => parse_u8(init)? * 1000.0,
Expand Down
4 changes: 2 additions & 2 deletions crates/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ async fn main() -> Result<()> {
line,
limit,
studio,
// submit,
} => upload_by_command(studio, cli.user_cookie, video_path, line, limit).await?,
submit,
} => upload_by_command(studio, cli.user_cookie, video_path, line, limit, submit).await?,
Commands::Upload {
video_path: _,
config: Some(config),
Expand Down
25 changes: 13 additions & 12 deletions crates/bin/uploader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cli::UploadLine;
use crate::cli::{SubmitOption, UploadLine};
use anyhow::{anyhow, Context, Result};
use biliup::client::StatelessClient;
use biliup::error::Kind;
Expand Down Expand Up @@ -70,7 +70,7 @@ pub async fn upload_by_command(
video_path: Vec<PathBuf>,
line: Option<UploadLine>,
limit: usize,
// submit: Option<String>,
submit: SubmitOption,
) -> Result<()> {
let bili = login_by_cookies(user_cookie).await?;
if studio.title.is_empty() {
Expand All @@ -83,16 +83,17 @@ pub async fn upload_by_command(
cover_up(&mut studio, &bili).await?;
studio.videos = upload(&video_path, &bili, line, limit).await?;

if studio.submit_by_app {
bili.submit_by_app(&studio).await?;
}
else {
bili.submit(&studio).await?;
}
// match submit.as_deref() {
// Some("app") => bili.submit_by_app(&studio).await?,
// _ => bili.submit(&studio).await?,
// };
// if studio.submit_by_app {
// bili.submit_by_app(&studio).await?;
// }
// else {
// bili.submit(&studio).await?;
// }
// 说不定会适配 web 呢...?
match submit {
SubmitOption::App => bili.submit_by_app(&studio).await?,
_ => bili.submit(&studio).await?,
};

Ok(())
}
Expand Down

0 comments on commit a39ece2

Please sign in to comment.