From a4012b2f7817aafa732df854daf1cfe9ae4803e0 Mon Sep 17 00:00:00 2001 From: William Yang Date: Thu, 25 Jul 2024 03:21:59 +1000 Subject: [PATCH] Copy file to transcode folder if same format --- src/worker_download.rs | 2 +- src/worker_transcode.rs | 12 ++++++++++++ static/fragments/download_progress.js | 4 +++- static/fragments/transcode_progress.js | 4 +++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/worker_download.rs b/src/worker_download.rs index e7cc828..6bf098e 100644 --- a/src/worker_download.rs +++ b/src/worker_download.rs @@ -330,7 +330,7 @@ fn enqueue_download_worker( let Some(audio_path) = audio_path else { return Err(DownloadError::MissingOutputPath) }; - let audio_path = PathBuf::from(audio_path); + let audio_path = app_config.root.join(audio_path); if audio_path.exists() { Ok(audio_path) } else { diff --git a/src/worker_transcode.rs b/src/worker_transcode.rs index 0835bc3..e427ed8 100644 --- a/src/worker_transcode.rs +++ b/src/worker_transcode.rs @@ -113,6 +113,8 @@ pub enum TranscodeError { DownloadPathMissing, #[error("Missing output download file from worker: {0}")] DownloadFileMissing(PathBuf), + #[error("Copying identically formatted download to transcode failed: {0}")] + CopyDownloadSameFormat(std::io::Error), #[error("Error stored in system log")] LoggedFail, #[error("Database connection failed: {0:?}")] @@ -255,6 +257,16 @@ fn enqueue_transcode_worker( if !source_path.exists() { return Err(TranscodeError::DownloadFileMissing(source_path)); } + // If the download path is the same format as transcode path then just copy it + if source_path.file_name() == audio_path.file_name() { + let _ = std::fs::copy(source_path.clone(), audio_path.clone()).map_err(TranscodeError::CopyDownloadSameFormat)?; + writeln!( + &mut system_log_writer.lock().unwrap(), + "Transcode has same format as download. Copying {0} to {1}", + source_path.to_string_lossy(), audio_path.to_string_lossy(), + ).map_err(WorkerError::SystemWriteFail)?; + return Ok(audio_path); + } // TODO: avoid retranscodeing file if on disk already - make this an option // if audio_path.exists() { // *is_transcoded.borrow_mut() = true; diff --git a/static/fragments/download_progress.js b/static/fragments/download_progress.js index 7ef66d0..90da75b 100644 --- a/static/fragments/download_progress.js +++ b/static/fragments/download_progress.js @@ -67,7 +67,9 @@ export const DownloadProgress = { subtitle_text() { if (this.progress == null || this.progress?.file_cached) return null; if (this.progress.worker_status == WorkerStatus.Failed) return this.progress.fail_reason; - if (this.progress.downloaded_bytes == null) return "Waiting for download to start"; + if (this.progress.downloaded_bytes == null) { + return (this.progress.worker_status == WorkerStatus.Finished) ? null : "Waiting for download to start"; + } let [curr_bytes, curr_bytes_unit] = convert_to_short_standard_prefix(this.progress.downloaded_bytes); let [total_bytes, total_bytes_unit] = convert_to_short_standard_prefix(this.progress.total_bytes); diff --git a/static/fragments/transcode_progress.js b/static/fragments/transcode_progress.js index 8b31a17..2d463e9 100644 --- a/static/fragments/transcode_progress.js +++ b/static/fragments/transcode_progress.js @@ -68,7 +68,9 @@ export const TranscodeProgress = { subtitle_text() { if (this.progress == null || this.progress?.file_cached) return null; if (this.progress.worker_status == WorkerStatus.Failed) return this.progress.fail_reason; - if (this.progress.transcode_duration_milliseconds == null) return "Waiting for transcode to start"; + if (this.progress.transcode_duration_milliseconds == null) { + return (this.progress.worker_status == WorkerStatus.Finished) ? null : "Waiting for transcode to start"; + } // Bitrate doesn't tell us anything useful about progress // let [speed_bits, speed_bits_unit] = convert_to_short_standard_prefix(this.progress.source_speed_bits); // let [speed_bits, speed_bits_unit] = convert_to_short_standard_prefix(this.progress.transcode_speed_bits);