From e0b309bfa132bca972805ca0545561d0cf44c890 Mon Sep 17 00:00:00 2001 From: Abdul Moiz Date: Mon, 6 Jun 2022 23:56:24 +0500 Subject: [PATCH] disabled media formats looping. display complete path of the downloaded video file. Also added quality-label (e.g. 360p) in the video-file name. --- index.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2c38eb0..45f300c 100644 --- a/index.js +++ b/index.js @@ -3,11 +3,11 @@ const cliProgress = require('cli-progress'); const fs = require("fs"); +const path = require("path"); const ytdl = require("ytdl-core"); const inquirer = require('inquirer'); const { getInfo } = ytdl; const winston = require("winston"); -const { join } = require('path'); const { format: winstonFormat } = winston; const logger = winston.createLogger({ @@ -21,6 +21,10 @@ const logger = winston.createLogger({ }); const BYTES_IN_ONE_MB = 1048576; +/** + * @type {string} + */ +let filePath; const progressBar = new cliProgress.SingleBar({ format: 'Downloading [{bar}] {percentage}% | {totalDownloadedMegaBytes}/{totalMegaBytes} MB' @@ -67,16 +71,18 @@ async function Program() { type: "list", name: "value", message: "Select media type and format:", + loop: false, + pageSize: videoInfo.formats.length, }]); const format = videoInfo.formats[selectedIndex]; - const { itag, container } = format; + const { qualityLabel, itag, container } = format; // to follow windows file naming convention. const cleanedTitle = videoInfo.videoDetails.title.replace(/[\/\\\:\*\?\"\<\>\|]+/g, ""); - const filePath = `./${cleanedTitle}-${itag}.${container}`; + filePath = `./${cleanedTitle}-${qualityLabel}-${itag}.${container}`; - console.log("\n", "Saving file as: ", filePath, "\n"); + console.log(`\nSaving file as: ${filePath}\n`); logger.info("Saving file as: %s", filePath); progressBar.start(100, 0, { totalDownloadedMegaBytes: 0, totalMegaBytes: 0 }); @@ -104,7 +110,11 @@ function onProgressCallback(_, totalBytesDownloaded, totalBytes) { function onDownloadEnd() { progressBar.stop(); - console.log("Download complete! Need to download another video?\n"); + console.log("\nDownload complete!"); + const fileLocation = `Video has been saved at: ${path.resolve(filePath)}`; + console.log(fileLocation); + logger.info(fileLocation); + console.log("\nNeed to download another video?"); StartUp(); }