Skip to content

Commit

Permalink
Copy file to transcode folder if same format
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Jul 24, 2024
1 parent e825722 commit a4012b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/worker_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/worker_transcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")]
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion static/fragments/download_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion static/fragments/transcode_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a4012b2

Please sign in to comment.