Skip to content

Commit

Permalink
fix(examples): stop progress bars on completion
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Sep 15, 2024
1 parent a1e5738 commit 5549a97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 3 additions & 1 deletion examples/downloader/ffmpeg-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -132,6 +132,8 @@ if (audioOutput)
if (videoOutput)
videoOutput.end();

progressBars.stop();

const outputFilename = `${sanitizedTitle}_final.webm`;

await new Promise<void>((resolve, reject) => {
Expand Down
22 changes: 10 additions & 12 deletions examples/downloader/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 ],
Expand All @@ -148,4 +138,12 @@ await serverAbrStream.init({
mediaType: MediaType.MEDIA_TYPE_DEFAULT,
startTimeMs: 0
}
});
});

progressBars.stop();

if (audioOutput)
audioOutput.end();

if (videoOutput)
videoOutput.end();

0 comments on commit 5549a97

Please sign in to comment.