fix + add transcode
This commit is contained in:
parent
76e2641008
commit
95a2a71f25
6 changed files with 50 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue