Skip to content

Commit

Permalink
Indicate when file has been loaded from existing file (cached)
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Jul 24, 2024
1 parent 9ebc249 commit 83e9ff3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/worker_download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::ytdlp;
#[derive(Clone,Debug,Serialize)]
pub struct DownloadState {
pub worker_status: WorkerStatus,
pub file_cached: bool,
pub fail_reason: Option<String>,
pub start_time_unix: u64,
pub end_time_unix: u64,
Expand All @@ -35,6 +36,7 @@ impl Default for DownloadState {
let curr_time = get_unix_time();
Self {
worker_status: WorkerStatus::None,
file_cached: false,
fail_reason: None,
start_time_unix: curr_time,
end_time_unix: curr_time,
Expand Down Expand Up @@ -142,7 +144,9 @@ pub fn try_start_download_worker(
let audio_path = PathBuf::from(audio_path);
if status == WorkerStatus::Finished && audio_path.exists() {
let download_state = download_cache.entry(video_id.clone()).or_default();
download_state.0.lock().unwrap().worker_status = status;
let mut state = download_state.0.lock().unwrap();
state.worker_status = status;
state.file_cached = true;
download_state.1.notify_all();
*is_queue_success.borrow_mut() = true;
return Ok(status);
Expand Down
6 changes: 5 additions & 1 deletion src/worker_transcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl TranscodeKey {
#[derive(Debug,Clone,Serialize)]
pub struct TranscodeState {
pub worker_status: WorkerStatus,
pub file_cached: bool,
pub fail_reason: Option<String>,
pub start_time_unix: u64,
pub end_time_unix: u64,
Expand All @@ -50,6 +51,7 @@ impl Default for TranscodeState {
let curr_time = get_unix_time();
Self {
worker_status: WorkerStatus::None,
file_cached: false,
fail_reason: None,
start_time_unix: curr_time,
end_time_unix: curr_time,
Expand Down Expand Up @@ -167,7 +169,9 @@ pub fn try_start_transcode_worker(
let audio_path = PathBuf::from(audio_path);
if status == WorkerStatus::Finished && audio_path.exists() {
let transcode_state = transcode_cache.entry(key.clone()).or_default();
transcode_state.0.lock().unwrap().worker_status = status;
let mut state = transcode_state.0.lock().unwrap();
state.worker_status = status;
state.file_cached = true;
transcode_state.1.notify_all();
*is_queue_success.borrow_mut() = true;
return Ok(status);
Expand Down
2 changes: 1 addition & 1 deletion static/fragments/download_progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
</div>
<div v-if="subtitle_text != null">{{ subtitle_text }}</div>
<table v-if="showTable && (table_information != null)" class="w-100">
<table v-if="showTable && (table_information != null)" class="w-100" style="margin-top: 2px">
<tbody>
<tr><td style="width: 20%">Start time</td><td>{{ table_information.start_time }}</td></tr>
<tr><td>End time</td><td>{{ table_information.end_time }}</td></tr>
Expand Down
7 changes: 4 additions & 3 deletions static/fragments/download_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const DownloadProgress = {
return false;
},
progress_bar() {
if (this.progress == null) {
if (this.progress == null || this.progress?.file_cached) {
let is_cached = (this.state.status == WorkerStatus.Finished) || (this.state.status == WorkerStatus.Failed);
return {
width: (this.state.status == WorkerStatus.Running) ? 0 : 100,
Expand Down Expand Up @@ -63,7 +63,7 @@ export const DownloadProgress = {
return { width: 100, class: 'bg-warning', text: "Unknown"};
},
subtitle_text() {
if (this.progress == null) return null;
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";

Expand All @@ -83,12 +83,13 @@ export const DownloadProgress = {
return text;
},
table_information() {
if (this.progress == null) return null;
if (this.progress == null || this.progress?.file_cached) return null;
let status = this.progress.worker_status;
if ((status == WorkerStatus.None) || (status == WorkerStatus.Queued)) return null;
let table = {};
table.start_time = unix_time_to_string(this.progress.start_time_unix);
table.end_time = unix_time_to_string(this.progress.end_time_unix);
table.file_cached = this.progress.file_cached;
let elapsed_time = this.progress.end_time_unix-this.progress.start_time_unix;
table.elapsed_time = convert_dhms_to_string(convert_seconds_to_dhms(elapsed_time));
if (this.progress.percentage != null) {
Expand Down
2 changes: 1 addition & 1 deletion static/fragments/transcode_progress.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
</div>
<div v-if="subtitle_text != null">{{ subtitle_text }}</div>
<table v-if="showTable && (table_information != null)" class="w-100">
<table v-if="showTable && (table_information != null)" class="w-100" style="margin-top: 2px">
<tbody>
<tr><td style="width: 20%">Start time</td><td>{{ table_information.start_time }}</td></tr>
<tr><td>End time</td><td>{{ table_information.end_time }}</td></tr>
Expand Down
7 changes: 4 additions & 3 deletions static/fragments/transcode_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const TranscodeProgress = {
return false;
},
progress_bar() {
if (this.progress == null) {
if (this.progress == null || this.progress?.file_cached) {
let is_cached = (this.state.status == WorkerStatus.Finished) || (this.state.status == WorkerStatus.Failed);
return {
width: (this.state.status == WorkerStatus.Running) ? 0 : 100,
Expand Down Expand Up @@ -66,7 +66,7 @@ export const TranscodeProgress = {
return { width: 100, class: 'bg-warning', text: "Unknown"};
},
subtitle_text() {
if (this.progress == null) return null;
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";
// Bitrate doesn't tell us anything useful about progress
Expand Down Expand Up @@ -100,12 +100,13 @@ export const TranscodeProgress = {
return text;
},
table_information() {
if (this.progress == null) return null;
if (this.progress == null || this.progress?.file_cached) return null;
let status = this.progress.worker_status;
if ((status == WorkerStatus.None) || (status == WorkerStatus.Queued)) return null;
let table = {};
table.start_time = unix_time_to_string(this.progress.start_time_unix);
table.end_time = unix_time_to_string(this.progress.end_time_unix);
table.file_cached = this.progress.file_cached;
let elapsed_time = this.progress.end_time_unix-this.progress.start_time_unix;
table.elapsed_time = convert_dhms_to_string(convert_seconds_to_dhms(elapsed_time));
if (this.progress.source_duration_milliseconds != null) {
Expand Down

0 comments on commit 83e9ff3

Please sign in to comment.