From b6e90e8f380569803b9a83f8997159b34d64e501 Mon Sep 17 00:00:00 2001 From: liam4 Date: Fri, 21 Jul 2017 22:27:34 -0300 Subject: Make some error handling for YouTube downloads --- src/download-playlist.js | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'src/download-playlist.js') diff --git a/src/download-playlist.js b/src/download-playlist.js index 87d60c3..390d241 100755 --- a/src/download-playlist.js +++ b/src/download-playlist.js @@ -88,34 +88,43 @@ async function downloadCrawl(topPlaylist, initialOutPath = './out/') { ` => ${targetFile}\x1b[0m` ) - const downloader = makePowerfulDownloader( - getDownloaderFor(item.downloaderArg) - ) + // Woo-hoo, using block labels for their intended purpose! (Maybe?) + downloadProcess: { + const downloader = makePowerfulDownloader( + getDownloaderFor(item.downloaderArg) + ) - const outputtedFile = await downloader(item.downloaderArg) + const outputtedFile = await downloader(item.downloaderArg) - let ffmpegSuccess = false + // If the return of the downloader is false, then the download + // failed. + if (outputtedFile === false) { + console.error( + `\x1b[33;1mDownload failed (item skipped): ${item.name}\x1b[0m` + ) - try { - await promisifyProcess(spawn('ffmpeg', [ - '-i', outputtedFile, + break downloadProcess + } - // A bug (in ffmpeg or macOS; not this) makes it necessary to have - // these options on macOS, otherwise the outputted file length is - // wrong. - '-write_xing', '0', + try { + await promisifyProcess(spawn('ffmpeg', [ + '-i', outputtedFile, - targetFile - ]), false) + // A bug (in ffmpeg or macOS; not this) makes it necessary to have + // these options on macOS, otherwise the outputted file length is + // wrong. + '-write_xing', '0', - ffmpegSuccess = true - } catch(err) { - console.error( - `\x1b[33;1mFFmpeg failed (item skipped): ${item.name}\x1b[0m` - ) - } + targetFile + ]), false) + } catch(err) { + console.error( + `\x1b[33;1mFFmpeg failed (item skipped): ${item.name}\x1b[0m` + ) + + break downloadProcess + } - if (ffmpegSuccess) { console.log('Added:', item.name) outPlaylist.push({name: item.name, downloaderArg: targetFile}) } -- cgit 1.3.0-6-gf8a5