fix
This commit is contained in:
parent
ab75b1f3e4
commit
589a596a30
3 changed files with 16 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
/target
|
||||
/db
|
||||
/media
|
||||
/data
|
|
@ -41,27 +41,33 @@ impl Track {
|
|||
}
|
||||
|
||||
/// Transcode audio to OPUS with `bitrate`
|
||||
pub fn get_opus(&self, bitrate: u32) -> String {
|
||||
let transcoded = format!("./data/transcode/opus/{}/{}", bitrate, self._id);
|
||||
pub fn get_opus(&self, bitrate: u32) -> Option<String> {
|
||||
let transcoded = format!("./data/transcode/opus/{}/{}.opus", bitrate, self._id);
|
||||
|
||||
if std::path::Path::new(&transcoded).exists() {
|
||||
return transcoded;
|
||||
return Some(transcoded);
|
||||
}
|
||||
|
||||
log::info!("Transcoding {} to OPUS {}", self._id, bitrate);
|
||||
|
||||
std::fs::create_dir_all(format!("./data/transcode/opus/{bitrate}")).unwrap();
|
||||
|
||||
std::process::Command::new("ffmpeg")
|
||||
let out = std::process::Command::new("ffmpeg")
|
||||
.arg("-i")
|
||||
.arg(&self.path)
|
||||
.arg("-c:a")
|
||||
.arg("libopus")
|
||||
.arg("-b:a")
|
||||
.arg(bitrate.to_string())
|
||||
.arg(format!("{bitrate}k"))
|
||||
.arg(&transcoded)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
transcoded
|
||||
if !out.status.success() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(transcoded)
|
||||
}
|
||||
|
||||
/// Find tracks with no album or artist
|
||||
|
|
|
@ -28,5 +28,5 @@ pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<Na
|
|||
#[get("/track/<track_id>/audio/opus128")]
|
||||
pub async fn track_audio_opus128_route(track_id: &str, lib: &State<Libary>) -> Option<NamedFile> {
|
||||
let track = lib.get_track_by_id(track_id).await?;
|
||||
NamedFile::open(track.get_opus(128)).await.ok()
|
||||
NamedFile::open(track.get_opus(128)?).await.ok()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue