fix + add transcode

This commit is contained in:
JMARyA 2024-08-01 14:55:31 +02:00
parent 76e2641008
commit 95a2a71f25
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 50 additions and 4 deletions

View file

@ -106,6 +106,18 @@ impl Libary {
.insert("meta".into(), metadata.0);
}
if entry.as_object().unwrap().get("title").is_none() {
entry.as_object_mut().unwrap().insert(
"title".into(),
std::path::Path::new(path)
.file_stem()
.unwrap()
.to_str()
.unwrap()
.into(),
);
}
Track::create(&entry.as_object().unwrap()).await;
}

View file

@ -36,6 +36,30 @@ impl Track {
.unwrap();
}
/// Transcode audio to OPUS with `bitrate`
pub fn get_opus(&self, bitrate: u32) -> String {
let transcoded = format!("./data/transcode/opus/{}/{}", bitrate, self._id);
if std::path::Path::new(&transcoded).exists() {
return transcoded;
}
std::fs::create_dir_all(format!("./data/transcode/opus/{bitrate}")).unwrap();
std::process::Command::new("ffmpeg")
.arg("-i")
.arg(&self.path)
.arg("-c:a")
.arg("libopus")
.arg("-b:a")
.arg(bitrate.to_string())
.arg(&transcoded)
.output()
.unwrap();
transcoded
}
pub async fn api(&self) -> serde_json::Value {
let album_title = if let Some(album_ref) = &self.album_id {
album_ref