fix yt-dlp's "none" string value to real None variant
This commit is contained in:
parent
852f27ca73
commit
4c6804a76f
3 changed files with 29 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
/target
|
||||
.env
|
||||
*.json
|
||||
*.txt
|
||||
|
|
@ -12,12 +12,24 @@ pub struct YtDlpFormat {
|
|||
pub width: Option<u16>,
|
||||
pub height: Option<u16>,
|
||||
pub ext: String,
|
||||
pub vcodec: Option<String>,
|
||||
pub acodec: Option<String>,
|
||||
pub vcodec: Option<String>,
|
||||
pub abr: Option<f32>,
|
||||
pub vbr: Option<f32>,
|
||||
}
|
||||
|
||||
impl YtDlpFormat {
|
||||
pub fn process(&mut self) {
|
||||
if self.acodec.as_ref().is_some_and(|v| v == "none") {
|
||||
self.acodec = None
|
||||
}
|
||||
|
||||
if self.vcodec.as_ref().is_some_and(|v| v == "none") {
|
||||
self.vcodec = None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct YtDlpInfo {
|
||||
pub id: String,
|
||||
|
|
@ -25,6 +37,14 @@ pub struct YtDlpInfo {
|
|||
pub formats: Vec<YtDlpFormat>,
|
||||
}
|
||||
|
||||
impl YtDlpInfo {
|
||||
pub fn process(&mut self) {
|
||||
for format in &mut self.formats {
|
||||
format.process()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum YtDlpError {
|
||||
CommandError(std::io::Error),
|
||||
|
|
@ -77,7 +97,8 @@ impl YtDlp {
|
|||
return Err(YtDlpError::ErrorMessage(message.to_string()));
|
||||
}
|
||||
|
||||
let info: YtDlpInfo = serde_json::from_slice(&output.stdout)?;
|
||||
let mut info: YtDlpInfo = serde_json::from_slice(&output.stdout)?;
|
||||
info.process();
|
||||
|
||||
Ok(info)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,10 @@ where
|
|||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv().ok();
|
||||
|
||||
let _ = YtDlp::load_info(env::var("TEST_URL")?.as_str()).await;
|
||||
let info = YtDlp::load_info(env::var("TEST_URL")?.as_str())
|
||||
.await
|
||||
.expect("load_info");
|
||||
dbg!(info);
|
||||
|
||||
Ok(())
|
||||
//bot_main().await
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue