fix
This commit is contained in:
parent
31649314a5
commit
05d3848602
8 changed files with 102 additions and 91 deletions
|
@ -48,7 +48,7 @@ impl Album {
|
|||
.clone();
|
||||
let track_path = std::path::Path::new(&track_path);
|
||||
|
||||
for ext in ["png", "jpg", "jpeg", "avif"] {
|
||||
for ext in ["png", "jpg", "jpeg", "avif", "webp"] {
|
||||
let cover_file = track_path.parent()?.join(format!("cover.{ext}"));
|
||||
|
||||
if cover_file.exists() {
|
||||
|
|
|
@ -134,7 +134,7 @@ impl Libary {
|
|||
}
|
||||
|
||||
pub async fn get_artists(&self) -> Vec<Artist> {
|
||||
Artist::find(doc! {}, None).await.unwrap()
|
||||
Artist::find_all().await.unwrap()
|
||||
}
|
||||
|
||||
pub async fn get_albums_by_artist(&self, artist: &str) -> Vec<Album> {
|
||||
|
@ -240,7 +240,10 @@ impl Libary {
|
|||
|
||||
pub async fn clean_lost_files(&self) {
|
||||
// tracks
|
||||
for track in Track::find_partial(doc! {}, json!({"path": 1}), None).await.unwrap() {
|
||||
for track in Track::find_partial(doc! {}, json!({"path": 1}), None)
|
||||
.await
|
||||
.unwrap()
|
||||
{
|
||||
if !std::path::Path::new(&track.path.as_ref().unwrap()).exists() {
|
||||
log::info!("Cleaning lost {}", track.path.as_ref().unwrap());
|
||||
Track::remove(&track._id).await.unwrap();
|
||||
|
|
|
@ -44,21 +44,31 @@ impl Track {
|
|||
|
||||
/// Transcode audio to OPUS with `bitrate`
|
||||
pub fn get_opus(&self, bitrate: u32) -> Option<String> {
|
||||
let transcoded = format!("./data/transcode/opus/{}/{}.opus", bitrate, self._id);
|
||||
self.transcode("libopus", bitrate, "opus")
|
||||
}
|
||||
|
||||
/// Transcode audio to AAC with `bitrate`
|
||||
pub fn get_aac(&self, bitrate: u32) -> Option<String> {
|
||||
self.transcode("aac", bitrate, "m4a")
|
||||
}
|
||||
|
||||
/// Transcode audio
|
||||
pub fn transcode(&self, codec: &str, bitrate: u32, ext: &str) -> Option<String> {
|
||||
let transcoded = format!("./data/transcode/{codec}/{bitrate}/{}.{ext}", self._id);
|
||||
|
||||
if std::path::Path::new(&transcoded).exists() {
|
||||
return Some(transcoded);
|
||||
}
|
||||
|
||||
log::info!("Transcoding {} to OPUS {}", self._id, bitrate);
|
||||
log::info!("Transcoding {} to {} {}", self._id, codec, bitrate);
|
||||
|
||||
std::fs::create_dir_all(format!("./data/transcode/opus/{bitrate}")).unwrap();
|
||||
std::fs::create_dir_all(format!("./data/transcode/{codec}/{bitrate}")).unwrap();
|
||||
|
||||
let out = std::process::Command::new("ffmpeg")
|
||||
.arg("-i")
|
||||
.arg(&self.path)
|
||||
.arg("-c:a")
|
||||
.arg("libopus")
|
||||
.arg(codec)
|
||||
.arg("-b:a")
|
||||
.arg(format!("{bitrate}k"))
|
||||
.arg(&transcoded)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue