implement mp3 bitrate rounding up
This commit is contained in:
parent
0491be57c8
commit
bbcedac4e1
3 changed files with 16 additions and 2 deletions
|
|
@ -3,6 +3,17 @@ use super::spawn::{spawn, SpawnError};
|
||||||
pub struct FFMpeg {}
|
pub struct FFMpeg {}
|
||||||
|
|
||||||
impl FFMpeg {
|
impl FFMpeg {
|
||||||
|
const MP3_BITRATES: [u16; 14] = [
|
||||||
|
32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,
|
||||||
|
];
|
||||||
|
pub fn round_mp3_bitrate(abr: f32) -> u16 {
|
||||||
|
let abr = abr.ceil() as u16;
|
||||||
|
Self::MP3_BITRATES
|
||||||
|
.into_iter()
|
||||||
|
.find(|f| abr <= *f)
|
||||||
|
.unwrap_or(320)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn convert_to_mp3(
|
pub async fn convert_to_mp3(
|
||||||
input_path: &str,
|
input_path: &str,
|
||||||
output_path: &str,
|
output_path: &str,
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ impl YtDlpInfo {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum YtDlpError {
|
pub enum YtDlpError {
|
||||||
SpawnError(SpawnError),
|
SpawnError(SpawnError),
|
||||||
ErrorMessage(String), // keep it separate type if we ever plan to parse yt-dlp errors
|
ErrorMessage(String), // keep it separate type if we ever plan to parse yt-dlp errors
|
||||||
JsonError,
|
JsonError,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,7 +139,7 @@ impl From<SpawnError> for YtDlpError {
|
||||||
fn from(value: SpawnError) -> Self {
|
fn from(value: SpawnError) -> Self {
|
||||||
match value {
|
match value {
|
||||||
SpawnError::ErrorMessage(msg) => Self::ErrorMessage(msg),
|
SpawnError::ErrorMessage(msg) => Self::ErrorMessage(msg),
|
||||||
_ => Self::SpawnError(value)
|
_ => Self::SpawnError(value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ use teloxide::dispatching::UpdateHandler;
|
||||||
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
|
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
|
||||||
|
|
||||||
mod dl;
|
mod dl;
|
||||||
|
use dl::ffmpeg::FFMpeg;
|
||||||
use dl::yt_dlp::YtDlp;
|
use dl::yt_dlp::YtDlp;
|
||||||
|
|
||||||
type State = ();
|
type State = ();
|
||||||
|
|
@ -50,6 +51,8 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let audio = info.best_audio_format().unwrap();
|
let audio = info.best_audio_format().unwrap();
|
||||||
println!("{}", audio);
|
println!("{}", audio);
|
||||||
|
|
||||||
|
println!("abr {}", FFMpeg::round_mp3_bitrate(129.492));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
//bot_main().await
|
//bot_main().await
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue