From 2300f995560f2056e3c182b091d87564752f173a Mon Sep 17 00:00:00 2001 From: Alfred S Date: Wed, 21 Apr 2021 00:50:57 +0300 Subject: [PATCH 1/2] Show downloaded percentage on prompt --- app.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app.js b/app.js index 86c5c7a..734cba8 100755 --- a/app.js +++ b/app.js @@ -15,6 +15,7 @@ var parsetorrent = require('parse-torrent') var bufferFrom = require('buffer-from') var path = require('path') +var fs = require('fs') process.title = 'peerflix' @@ -153,6 +154,16 @@ var ontorrent = function (torrent) { var onready = function () { if (interactive) { + + var getDownloadedSize = function(file) { + var p = path.join(engine.path, file.path) + if (fs.existsSync(p)) { + var size = fs.statSync(p).size + return Math.round(size / file.length) * 100 // percentage + } + return 0 + } + var filenamesInOriginalOrder = engine.files.map(file => file.path) inquirer.prompt([{ type: 'list', @@ -162,7 +173,7 @@ var ontorrent = function (torrent) { .sort((file1, file2) => file1.path.localeCompare(file2.path)) .map(function (file, i) { return { - name: file.name + ' : ' + bytes(file.length), + name: file.name + ' : ' + bytes(file.length) + " (" + getDownloadedSize(file) + "%)", value: filenamesInOriginalOrder.indexOf(file.path) } }) From c545f3f188f664dd552054922659641d34f0ef15 Mon Sep 17 00:00:00 2001 From: Alfred S Date: Wed, 21 Apr 2021 01:04:37 +0300 Subject: [PATCH 2/2] Fixed formatting --- app.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 734cba8..a1906ae 100755 --- a/app.js +++ b/app.js @@ -154,8 +154,7 @@ var ontorrent = function (torrent) { var onready = function () { if (interactive) { - - var getDownloadedSize = function(file) { + var getDownloadedSize = function (file) { var p = path.join(engine.path, file.path) if (fs.existsSync(p)) { var size = fs.statSync(p).size @@ -173,7 +172,7 @@ var ontorrent = function (torrent) { .sort((file1, file2) => file1.path.localeCompare(file2.path)) .map(function (file, i) { return { - name: file.name + ' : ' + bytes(file.length) + " (" + getDownloadedSize(file) + "%)", + name: file.name + ' : ' + bytes(file.length) + ' (' + getDownloadedSize(file) + '%)', value: filenamesInOriginalOrder.indexOf(file.path) } })