Skip to content

Commit

Permalink
fix: runtime utilties path
Browse files Browse the repository at this point in the history
  • Loading branch information
sandipndev committed Sep 21, 2024
1 parent b55c902 commit 9942dea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ FROM nixpkgs/nix-flakes:latest

# ffmpeg and yt-dlp are command line utilties being used often
RUN nix-env -iA nixpkgs.ffmpeg-full nixpkgs.yt-dlp
RUN ln -s /root/.nix-profile/bin/ffmpeg /usr/bin/ffmpeg && \
ln -s /root/.nix-profile/bin/yt-dlp /usr/bin/yt-dlp

COPY --from=build-backend /src/target/x86_64-unknown-linux-musl/release/accorde-server /usr/bin/accorde-server

WORKDIR /app
COPY --from=build-frontend /app/package.json /app/pnpm-lock.yaml ./
COPY --from=build-frontend /app/.next ./.next
COPY --from=build-frontend /app/public ./public
COPY --from=build-frontend /app/next.config.js ./
COPY --from=build-frontend /app .

USER 1000
WORKDIR /accorde
Expand All @@ -37,5 +36,6 @@ FROM nixpkgs/nix-flakes:latest
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENV ENV production
EXPOSE 3000 8765
CMD ["/entrypoint.sh"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ services:
depends_on:
- server-pg
environment:
- PG_CON=postgresql://user:password@server-pg:5432/pg"
- PG_CON=postgresql://user:password@server-pg:5432/pg
22 changes: 12 additions & 10 deletions server/src/process/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ use futures::stream::{FuturesUnordered, StreamExt};
use std::{process::Stdio, sync::Arc};
use tokio::{process::Command, sync::Semaphore};

fn get_command_path(command_name: &str) -> String {
match std::env::var("ENV").as_deref() {
Ok("production") => format!("/usr/bin/{}", command_name),
_ => command_name.to_string(),
}
}

impl Processes {
pub async fn download(&self, process_id: ProcessId) -> Result<(), ProcessError> {
let process = self.get(process_id).await?;
Expand All @@ -19,7 +26,8 @@ impl Processes {

let download_file_at = format!("{}/{}.mp3", self.config.home_absolute_path, process.id);

let status = Command::new("yt-dlp")
let yt_dlp_command = get_command_path("yt-dlp");
let status = Command::new(yt_dlp_command)
.arg("-x")
.arg("--audio-format")
.arg("mp3")
Expand Down Expand Up @@ -69,18 +77,14 @@ impl Processes {
return Err(ProcessError::FileNotFound);
}

// Semitone shifts from -10 to -1 and +1 to +10
let semitone_shifts: Vec<i32> = (-10..=10).filter(|&s| s != 0).collect();

// Limit the number of concurrent FFmpeg processes
let max_concurrent_processes = 4;
let semaphore = Arc::new(Semaphore::new(max_concurrent_processes));

// Use FuturesUnordered for efficient asynchronous iteration
let mut futures = FuturesUnordered::new();

for semitone in semitone_shifts {
// Clone variables for use in the async block
let downloaded_file_at = downloaded_file_at.clone();
let home_path = self.config.home_absolute_path.clone();
let process_id = process.id.clone();
Expand All @@ -91,10 +95,8 @@ impl Processes {
// Acquire a permit before starting the process
let _permit = semaphore.acquire().await;

// Calculate the pitch factor
let pitch_factor = 2f64.powf(semitone as f64 / 12.0);

// Construct the output file path
let output_file = format!(
"{}/{}_{}_ST.mp3",
home_path,
Expand All @@ -106,8 +108,9 @@ impl Processes {
}
);

// Build the FFmpeg command
let status = Command::new("ffmpeg")
let ffmpeg_command = get_command_path("ffmpeg");

let status = Command::new(ffmpeg_command)
.arg("-y") // Overwrite output files without asking
.arg("-i")
.arg(&downloaded_file_at)
Expand All @@ -133,7 +136,6 @@ impl Processes {
});
}

// Process the futures as they complete
while let Some(result) = futures.next().await {
if let Err(e) = result {
eprintln!("Error during conversion: {}", e);
Expand Down

0 comments on commit 9942dea

Please sign in to comment.