From 05d384860207e87f760c9ac697a96ebcd0934302 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 15 Aug 2024 16:45:04 +0200 Subject: [PATCH] fix --- Cargo.lock | 155 ++++++++++++++++++++----------------------- src/library/album.rs | 2 +- src/library/mod.rs | 7 +- src/library/track.rs | 18 +++-- src/main.rs | 1 + src/route/album.rs | 2 +- src/route/track.rs | 6 ++ src/route/user.rs | 2 +- 8 files changed, 102 insertions(+), 91 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7b8715e..e931184 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,7 +27,7 @@ dependencies = [ "getrandom", "once_cell", "version_check", - "zerocopy 0.7.35", + "zerocopy", ] [[package]] @@ -122,7 +122,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -133,7 +133,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -305,9 +305,9 @@ checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c" [[package]] name = "cc" -version = "1.1.7" +version = "1.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" +checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" [[package]] name = "cfg-if" @@ -364,15 +364,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cpufeatures" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad" dependencies = [ "libc", ] @@ -458,7 +458,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.0", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -491,7 +491,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -668,7 +668,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -1004,9 +1004,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" -version = "0.3.69" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] @@ -1129,9 +1129,9 @@ dependencies = [ [[package]] name = "mio" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ "hermit-abi", "libc", @@ -1142,7 +1142,7 @@ dependencies = [ [[package]] name = "mongod" version = "0.2.0" -source = "git+https://git.hydrar.de/jmarya/mongod#c4f2b6eb8152dd086a2f296119a1898032712cd8" +source = "git+https://git.hydrar.de/jmarya/mongod#84ef28312e1d4dfa5bb8c99d842db9fc79ad3701" dependencies = [ "chrono", "futures", @@ -1158,7 +1158,7 @@ dependencies = [ [[package]] name = "mongod_derive" version = "0.1.0" -source = "git+https://git.hydrar.de/jmarya/mongod#c4f2b6eb8152dd086a2f296119a1898032712cd8" +source = "git+https://git.hydrar.de/jmarya/mongod#84ef28312e1d4dfa5bb8c99d842db9fc79ad3701" dependencies = [ "case", "proc-macro2", @@ -1269,9 +1269,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.2" +version = "0.36.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" +checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" dependencies = [ "memchr", ] @@ -1340,7 +1340,7 @@ dependencies = [ "proc-macro2", "proc-macro2-diagnostics", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -1369,11 +1369,11 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" -version = "0.2.18" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee4364d9f3b902ef14fab8a1ddffb783a1cb6b4bba3bfc1fa3922732c7de97f" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "zerocopy 0.6.6", + "zerocopy", ] [[package]] @@ -1393,7 +1393,7 @@ checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", "version_check", "yansi", ] @@ -1475,14 +1475,14 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1597,7 +1597,7 @@ dependencies = [ "proc-macro2", "quote", "rocket_http", - "syn 2.0.72", + "syn 2.0.74", "unicode-xid", "version_check", ] @@ -1790,9 +1790,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.207" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "5665e14a49a4ea1b91029ba7d3bca9f299e1f7cfa194388ccc20f14743e784f2" dependencies = [ "serde_derive", ] @@ -1808,20 +1808,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.207" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] name = "serde_json" -version = "1.0.122" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" +checksum = "66ad62847a56b3dba58cc891acd13884b9c61138d330c0d7b6181713d4fce38d" dependencies = [ "indexmap", "itoa", @@ -1996,9 +1996,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.72" +version = "2.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" dependencies = [ "proc-macro2", "quote", @@ -2039,14 +2039,15 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tempfile" -version = "3.10.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ "cfg-if", "fastrand", + "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2066,7 +2067,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -2150,7 +2151,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -2247,7 +2248,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] @@ -2500,34 +2501,35 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2535,22 +2537,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.92" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "webpki-roots" @@ -2582,11 +2584,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2631,6 +2633,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-targets" version = "0.48.5" @@ -2789,34 +2800,14 @@ dependencies = [ "is-terminal", ] -[[package]] -name = "zerocopy" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6" -dependencies = [ - "byteorder", - "zerocopy-derive 0.6.6", -] - [[package]] name = "zerocopy" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "zerocopy-derive 0.7.35", -] - -[[package]] -name = "zerocopy-derive" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", + "byteorder", + "zerocopy-derive", ] [[package]] @@ -2827,7 +2818,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.74", ] [[package]] diff --git a/src/library/album.rs b/src/library/album.rs index 2e55233..b5a4468 100644 --- a/src/library/album.rs +++ b/src/library/album.rs @@ -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() { diff --git a/src/library/mod.rs b/src/library/mod.rs index fb6a18c..02af76b 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -134,7 +134,7 @@ impl Libary { } pub async fn get_artists(&self) -> Vec { - Artist::find(doc! {}, None).await.unwrap() + Artist::find_all().await.unwrap() } pub async fn get_albums_by_artist(&self, artist: &str) -> Vec { @@ -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(); diff --git a/src/library/track.rs b/src/library/track.rs index 136264d..f37735f 100644 --- a/src/library/track.rs +++ b/src/library/track.rs @@ -44,21 +44,31 @@ impl Track { /// Transcode audio to OPUS with `bitrate` pub fn get_opus(&self, bitrate: u32) -> Option { - 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 { + self.transcode("aac", bitrate, "m4a") + } + + /// Transcode audio + pub fn transcode(&self, codec: &str, bitrate: u32, ext: &str) -> Option { + 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) diff --git a/src/main.rs b/src/main.rs index 6b27231..0387250 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,6 +61,7 @@ async fn rocket() -> _ { route::user::user_create_route, route::user::users_route, route::track::track_audio_opus128_route, + route::track::track_audio_aac128_route, route::playlist::playlists_route, route::playlist::playlist_route, route::playlist::playlist_add_route, diff --git a/src/route/album.rs b/src/route/album.rs index 076de38..7d7abe8 100644 --- a/src/route/album.rs +++ b/src/route/album.rs @@ -62,7 +62,7 @@ pub async fn album_cover_route( pub async fn latest_albums_route(cache: &State) -> FallibleApiResponse { use_api_cache!("albums", "latest", cache); - let albums = Album::find(doc! {}, None).await.unwrap(); + let albums = Album::find_all().await.unwrap(); let mut albums_tracks = vec![]; diff --git a/src/route/track.rs b/src/route/track.rs index 7346fb0..b1a69f0 100644 --- a/src/route/track.rs +++ b/src/route/track.rs @@ -46,3 +46,9 @@ pub async fn track_audio_opus128_route(track_id: &str, lib: &State) -> O let track = lib.get_track_by_id(track_id).await?; NamedFile::open(track.get_opus(128)?).await.ok() } + +#[get("/track//audio/aac128")] +pub async fn track_audio_aac128_route(track_id: &str, lib: &State) -> Option { + let track = lib.get_track_by_id(track_id).await?; + NamedFile::open(track.get_aac(128)?).await.ok() +} diff --git a/src/route/user.rs b/src/route/user.rs index bffcaa0..0cf8eb6 100644 --- a/src/route/user.rs +++ b/src/route/user.rs @@ -83,7 +83,7 @@ pub async fn passwd_route(passwd: Json, mut u: User) -> FallibleApiR pub async fn users_route(u: User) -> FallibleApiResponse { check_admin!(u); - let users: Vec<_> = to_api(&User::find(doc! {}, None).await.unwrap()).await; + let users: Vec<_> = to_api(&User::find_all().await.unwrap()).await; Ok(json!({"users": users})) }