fix(examples): stop progress bars on completion

This commit is contained in:
Luan
2024-09-15 15:42:01 -03:00
parent a1e573831b
commit 5549a97173
2 changed files with 13 additions and 13 deletions

View File

@@ -6,7 +6,7 @@ import { Innertube, UniversalCache } from 'youtubei.js';
import GoogleVideo, { type Format, MediaType } from '../../dist/src/index.js';
const progressBars = new cliProgress.MultiBar({
clearOnComplete: false,
stopOnComplete: true,
hideCursor: true
}, cliProgress.Presets.rect);
@@ -132,6 +132,8 @@ if (audioOutput)
if (videoOutput)
videoOutput.end();
progressBars.stop();
const outputFilename = `${sanitizedTitle}_final.webm`;
await new Promise<void>((resolve, reject) => {

View File

@@ -5,7 +5,7 @@ import { Innertube, UniversalCache } from 'youtubei.js';
import GoogleVideo, { type Format, MediaType } from '../../dist/src/index.js';
const progressBars = new cliProgress.MultiBar({
clearOnComplete: false,
stopOnComplete: true,
hideCursor: true
}, cliProgress.Presets.rect);
@@ -126,16 +126,6 @@ serverAbrStream.on('error', (error) => {
console.error(error);
});
serverAbrStream.on('end', () => {
progressBars.stop();
if (audioOutput)
audioOutput.end();
if (videoOutput)
videoOutput.end();
});
await serverAbrStream.init({
audioFormats: [ selectedAudioFormat ],
videoFormats: [ selectedVideoFormat ],
@@ -148,4 +138,12 @@ await serverAbrStream.init({
mediaType: MediaType.MEDIA_TYPE_DEFAULT,
startTimeMs: 0
}
});
});
progressBars.stop();
if (audioOutput)
audioOutput.end();
if (videoOutput)
videoOutput.end();