Skip to content

Commit

Permalink
Start progress request and metadata search without delay
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Jul 25, 2024
1 parent a4012b2 commit 3c74116
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2 class="my-auto">Transcode request</h2>
type="text" class="flex-grow-1"
v-model="transcode_request.url"
placeholder="Youtube URL"
@blur="update_request_id()"
@input="(ev) => update_request_id()"
:class="{ 'form-input-invalid': transcode_request.url_error !== null }"
/>
<select v-model="transcode_request.format">
Expand Down
36 changes: 24 additions & 12 deletions static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export let create_app = () => createApp({
const is_worker_finished = (status) => {
return (status == WorkerStatus.Failed) || (status == WorkerStatus.Finished);
};
let timer_handle = setInterval(async () => {
timers[key] = null;
const request_progress = async () => {
let is_finished = false;
try {
let progress = await TranscodeApi.get_download_progress(video_id);
Expand All @@ -200,12 +201,17 @@ export let create_app = () => createApp({
} catch {
is_finished = true;
}
if (is_finished) {
clearInterval(timer_handle);
timers[key] = undefined;
if (is_finished && timers[key] !== null) {
clearInterval(timers[key]);
delete timers[key];
}
}, 1000);
timers[key] = timer_handle;
return is_finished;
};
request_progress().then((is_finished) => {
if (!is_finished) {
timers[key] = setInterval(request_progress, 1000);
}
});
return true;
},
subscribe_to_transcode(video_id, audio_ext) {
Expand All @@ -215,7 +221,8 @@ export let create_app = () => createApp({
const is_worker_finished = (status) => {
return (status == WorkerStatus.Failed) || (status == WorkerStatus.Finished);
};
let timer_handle = setInterval(async () => {
timers[key] = null;
const request_progress = async () => {
let is_finished = false;
try {
let progress = await TranscodeApi.get_transcode_progress(video_id, audio_ext);
Expand All @@ -229,12 +236,17 @@ export let create_app = () => createApp({
} catch {
is_finished = true;
}
if (is_finished) {
clearInterval(timer_handle);
timers[key] = undefined;
if (is_finished && timers[key] !== null) {
clearInterval(timers[key]);
delete timers[key];
}
return is_finished;
};
request_progress().then((is_finished) => {
if (!is_finished) {
timers[key] = setInterval(request_progress, 1000);
}
}, 1000);
timers[key] = timer_handle;
});
return true;
},
async download_file() {
Expand Down

0 comments on commit 3c74116

Please sign in to comment.