mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-18 12:39:42 +00:00
Fix progress bar, remove temp file on ffmpeg error (#66)
* Delete the video file on ffmpeg error * rework chunk calculation (with more tests it turns out it was not good for all durations) Co-authored-by: kylon <kylonux@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import isElevated from 'is-elevated';
|
||||
import puppeteer from 'puppeteer';
|
||||
import colors from 'colors';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import sanitize from 'sanitize-filename';
|
||||
import cliProgress from 'cli-progress';
|
||||
|
||||
@@ -148,7 +149,6 @@ async function downloadVideo(videoUrls: string[], outputDirectories: string[], s
|
||||
const outDirsIdxInc = outputDirectories.length > 1 ? 1:0;
|
||||
for (let i=0, j=0, l=metadata.length; i<l; ++i, j+=outDirsIdxInc) {
|
||||
const video = metadata[i];
|
||||
let previousChunks = 0;
|
||||
const pbar = new cliProgress.SingleBar({
|
||||
barCompleteChar: '\u2588',
|
||||
barIncompleteChar: '\u2591',
|
||||
@@ -186,17 +186,15 @@ async function downloadVideo(videoUrls: string[], outputDirectories: string[], s
|
||||
// set events
|
||||
ffmpegCmd.on('update', (data: any) => {
|
||||
const currentChunks = ffmpegTimemarkToChunk(data.out_time);
|
||||
const incChunk = currentChunks - previousChunks;
|
||||
|
||||
pbar.increment(incChunk, {
|
||||
pbar.update(currentChunks, {
|
||||
speed: data.bitrate
|
||||
});
|
||||
|
||||
previousChunks = currentChunks;
|
||||
});
|
||||
|
||||
ffmpegCmd.on('error', (error: any) => {
|
||||
pbar.stop();
|
||||
fs.unlinkSync(outputPath);
|
||||
console.log(`\nffmpeg returned an error: ${error.message}`);
|
||||
process.exit(ERROR_CODE.UNK_FFMPEG_ERROR);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user