fix + add transcode
This commit is contained in:
parent
76e2641008
commit
95a2a71f25
6 changed files with 50 additions and 4 deletions
|
@ -8,7 +8,7 @@ RUN cargo build --release
|
||||||
FROM debian:buster
|
FROM debian:buster
|
||||||
|
|
||||||
RUN apt update && apt upgrade -y
|
RUN apt update && apt upgrade -y
|
||||||
RUN apt install -y gnupg ca-certificates openssl
|
RUN apt install -y gnupg ca-certificates openssl ffmpeg
|
||||||
|
|
||||||
COPY --from=builder /app/target/release/synthwave /synthwave
|
COPY --from=builder /app/target/release/synthwave /synthwave
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@ services:
|
||||||
# - "8080:8080"
|
# - "8080:8080"
|
||||||
# depends_on:
|
# depends_on:
|
||||||
# - mongodb
|
# - mongodb
|
||||||
|
# volumes:
|
||||||
|
# - ./data:/data
|
||||||
|
# - ./media:/media
|
||||||
# environment:
|
# environment:
|
||||||
# - "DB_URI=mongodb://user:pass@mongodb:27017"
|
# - "DB_URI=mongodb://user:pass@mongodb:27017"
|
||||||
# - "DB=synthwrld"
|
# - "DB=synthwrld"
|
||||||
|
|
|
@ -106,6 +106,18 @@ impl Libary {
|
||||||
.insert("meta".into(), metadata.0);
|
.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;
|
Track::create(&entry.as_object().unwrap()).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,30 @@ impl Track {
|
||||||
.unwrap();
|
.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 {
|
pub async fn api(&self) -> serde_json::Value {
|
||||||
let album_title = if let Some(album_ref) = &self.album_id {
|
let album_title = if let Some(album_ref) = &self.album_id {
|
||||||
album_ref
|
album_ref
|
||||||
|
|
|
@ -3,9 +3,9 @@ use library::Libary;
|
||||||
mod library;
|
mod library;
|
||||||
mod route;
|
mod route;
|
||||||
|
|
||||||
|
use library::user::{User, UserRole};
|
||||||
use rocket::routes;
|
use rocket::routes;
|
||||||
use rocket::{http::Method, launch};
|
use rocket::{http::Method, launch};
|
||||||
use library::user::{User, UserRole};
|
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
async fn rocket() -> _ {
|
async fn rocket() -> _ {
|
||||||
|
@ -22,7 +22,7 @@ async fn rocket() -> _ {
|
||||||
.to_cors()
|
.to_cors()
|
||||||
.expect("error creating CORS options");
|
.expect("error creating CORS options");
|
||||||
|
|
||||||
let lib = Libary::new("/Users/angelo/Downloads/Music".into()).await;
|
let lib = Libary::new("/Users/angelo/Downloads/Music/syv".into()).await;
|
||||||
|
|
||||||
lib.rescan().await;
|
lib.rescan().await;
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@ async fn rocket() -> _ {
|
||||||
route::track::track_route,
|
route::track::track_route,
|
||||||
route::track::track_audio_route,
|
route::track::track_audio_route,
|
||||||
route::album::album_cover_route,
|
route::album::album_cover_route,
|
||||||
route::user::login_route
|
route::user::login_route,
|
||||||
|
route::track::track_audio_opus128_route
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.manage(lib)
|
.manage(lib)
|
||||||
|
|
|
@ -23,3 +23,9 @@ pub async fn track_audio_route(track_id: &str, lib: &State<Libary>) -> Option<Na
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue