@vbarbarosh/node-helpers 3.37.0 → 3.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/fastdl.js +2 -2
- package/src/format_bytes.test.js +1 -1
- package/src/format_kilo.js +17 -0
- package/src/format_kilo.test.js +23 -0
- package/src/format_percents.test.js +1 -1
- package/src/{format_progress.js → format_progress_bytes.js} +2 -2
- package/src/{format_progress.test.js → format_progress_bytes.test.js} +3 -3
- package/src/format_progress_kilo.js +25 -0
- package/src/format_progress_kilo.test.js +19 -0
- package/src/format_seconds.test.js +1 -1
- package/src/format_thousands.test.js +1 -1
- package/src/shell_ytdlp_progress.js +6 -1
- package/src/stream_progress.js +2 -2
- package/src/stream_ytdlp_progress.js +47 -3
package/package.json
CHANGED
package/src/fastdl.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const UserFriendlyError = require('./errors/UserFriendlyError');
|
|
2
2
|
const format_bytes = require('./format_bytes');
|
|
3
|
-
const
|
|
3
|
+
const format_progress_bytes = require('./format_progress_bytes');
|
|
4
4
|
const format_thousands = require('./format_thousands');
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const fs_path_basename = require('./fs_path_basename');
|
|
@@ -40,7 +40,7 @@ async function fastdl({file, read_stream_with_range, concurrency = 60, user_frie
|
|
|
40
40
|
const timer = setInterval(tick, 1000);
|
|
41
41
|
function tick() {
|
|
42
42
|
progress.refresh();
|
|
43
|
-
user_friendly_status(`${
|
|
43
|
+
user_friendly_status(`${format_progress_bytes(progress)} connections=${connections}`);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
user_friendly_status(`${format_bytes(total)} [${format_thousands(total)} bytes] to download`);
|
package/src/format_bytes.test.js
CHANGED
|
@@ -16,7 +16,7 @@ const items = [
|
|
|
16
16
|
describe('format_bytes', function () {
|
|
17
17
|
items.forEach(function ([input, expected]) {
|
|
18
18
|
it(`${input} → ${expected}`, function () {
|
|
19
|
-
assert.strictEqual(
|
|
19
|
+
assert.strictEqual(format_bytes(input), expected);
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function format_kilo(num)
|
|
2
|
+
{
|
|
3
|
+
const sizes = ['', 'K', 'M', 'G', 'T', 'P'];
|
|
4
|
+
if (typeof num !== 'number' || Number.isNaN(num)) {
|
|
5
|
+
return 'n/a';
|
|
6
|
+
}
|
|
7
|
+
if (!num) {
|
|
8
|
+
return '0';
|
|
9
|
+
}
|
|
10
|
+
if (num < 1000) {
|
|
11
|
+
return num.toString();
|
|
12
|
+
}
|
|
13
|
+
const i = parseInt(Math.floor(Math.log(num) / Math.log(1000)), 10);
|
|
14
|
+
return `${(num / (1000 ** i)).toFixed(2)}`.replace(/0$/, '').replace(/\.0$/, '') + sizes[i];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = format_kilo;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const format_kilo = require('./format_kilo');
|
|
3
|
+
|
|
4
|
+
const items = [
|
|
5
|
+
['', 'n/a'],
|
|
6
|
+
[null, 'n/a'],
|
|
7
|
+
[undefined, 'n/a'],
|
|
8
|
+
[0, '0'],
|
|
9
|
+
[1, '1'],
|
|
10
|
+
[900, '900'],
|
|
11
|
+
[1500, '1.5K'],
|
|
12
|
+
[2000, '2K'],
|
|
13
|
+
[35.45*1000*1000, '35.45M'],
|
|
14
|
+
[3.92*1000*1000*1000, '3.92G'],
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
describe('format_kilo', function () {
|
|
18
|
+
items.forEach(function ([input, expected]) {
|
|
19
|
+
it(`${input} → ${expected}`, function () {
|
|
20
|
+
assert.strictEqual(format_kilo(input), expected);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -16,7 +16,7 @@ const items = [
|
|
|
16
16
|
describe('format_percents', function () {
|
|
17
17
|
items.forEach(function ([input, expected]) {
|
|
18
18
|
it(`${input} → ${expected}`, function () {
|
|
19
|
-
assert.strictEqual(
|
|
19
|
+
assert.strictEqual(format_percents(input), expected);
|
|
20
20
|
});
|
|
21
21
|
});
|
|
22
22
|
});
|
|
@@ -3,7 +3,7 @@ const format_percents = require('./format_percents');
|
|
|
3
3
|
const format_seconds = require('./format_seconds');
|
|
4
4
|
const is_number_gt = require('./is_number_gt');
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function format_progress_bytes({percents, total, done, rate, eta, duration})
|
|
7
7
|
{
|
|
8
8
|
const bps = is_number_gt(rate, 0) ? `${format_bytes(rate)}/s` : '~';
|
|
9
9
|
if (done > total) {
|
|
@@ -22,4 +22,4 @@ function format_progress({percents, total, done, rate, eta, duration})
|
|
|
22
22
|
return '~';
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
module.exports =
|
|
25
|
+
module.exports = format_progress_bytes;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const assert = require('assert');
|
|
2
|
-
const
|
|
2
|
+
const format_progress_bytes = require('./format_progress_bytes');
|
|
3
3
|
|
|
4
4
|
const items = [
|
|
5
5
|
['~', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 0}],
|
|
@@ -10,10 +10,10 @@ const items = [
|
|
|
10
10
|
['15.0MB at 10.0MB/s duration=00:00:01', {percents: 5.2525, total: 5*1024*1024, done: 15*1024*1024, rate: 10*1024*1024, eta: 5, duration: 1}],
|
|
11
11
|
];
|
|
12
12
|
|
|
13
|
-
describe('
|
|
13
|
+
describe('format_progress_bytes', function () {
|
|
14
14
|
items.forEach(function ([expected, input]) {
|
|
15
15
|
it(expected, function () {
|
|
16
|
-
assert.strictEqual(
|
|
16
|
+
assert.strictEqual(format_progress_bytes(input), expected);
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const format_kilo = require('./format_kilo');
|
|
2
|
+
const format_percents = require('./format_percents');
|
|
3
|
+
const format_seconds = require('./format_seconds');
|
|
4
|
+
const is_number_gt = require('./is_number_gt');
|
|
5
|
+
|
|
6
|
+
function format_progress_kilo({percents, total, done, rate, eta, duration})
|
|
7
|
+
{
|
|
8
|
+
const speed = is_number_gt(rate, 0) ? `${format_kilo(rate)}/s` : '~';
|
|
9
|
+
if (done > total) {
|
|
10
|
+
return `${format_kilo(done)} at ${speed} duration=${format_seconds(duration)}`;
|
|
11
|
+
}
|
|
12
|
+
if (is_number_gt(total, 0)) {
|
|
13
|
+
const eta_str = is_number_gt(eta, 0) ? format_seconds(eta) : '~';
|
|
14
|
+
return `${format_percents(percents)} | ${format_kilo(done)} of ${format_kilo(total)} at ${speed} ETA ${eta_str} duration=${format_seconds(duration)}`;
|
|
15
|
+
}
|
|
16
|
+
if (is_number_gt(done, 0)) {
|
|
17
|
+
return `${format_kilo(done)} of ~ at ${speed} duration=${format_seconds(duration)}`;
|
|
18
|
+
}
|
|
19
|
+
if (is_number_gt(duration, 0)) {
|
|
20
|
+
return `~ duration=${format_seconds(duration)}`;
|
|
21
|
+
}
|
|
22
|
+
return '~';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = format_progress_kilo;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const format_progress_kilo = require('./format_progress_kilo');
|
|
3
|
+
|
|
4
|
+
const items = [
|
|
5
|
+
['~', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 0}],
|
|
6
|
+
['~ duration=00:00:01', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 1}],
|
|
7
|
+
['25.25% | 5M of 15M at ~ ETA ~ duration=00:00:01', {percents: 0.2525, total: 15*1000*1000, done: 5*1000*1000, rate: 0, eta: 0, duration: 1}],
|
|
8
|
+
['25.25% | 5M of 15M at 10M/s ETA 00:00:05 duration=00:00:01', {percents: 0.2525, total: 15*1000*1000, done: 5*1000*1000, rate: 10*1000*1000, eta: 5, duration: 1}],
|
|
9
|
+
// edge case: done > total
|
|
10
|
+
['15M at 10M/s duration=00:00:01', {percents: 5.2525, total: 5*1000*1000, done: 15*1000*1000, rate: 10*1000*1000, eta: 5, duration: 1}],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
describe('format_progress_kilo', function () {
|
|
14
|
+
items.forEach(function ([expected, input]) {
|
|
15
|
+
it(expected, function () {
|
|
16
|
+
assert.strictEqual(format_progress_kilo(input), expected);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -36,7 +36,7 @@ const items = [
|
|
|
36
36
|
describe('format_seconds', function () {
|
|
37
37
|
items.forEach(function ([expected, ...args]) {
|
|
38
38
|
it(`${args} → ${expected}`, function () {
|
|
39
|
-
assert.strictEqual(
|
|
39
|
+
assert.strictEqual(format_seconds(...args), expected);
|
|
40
40
|
});
|
|
41
41
|
});
|
|
42
42
|
});
|
|
@@ -22,7 +22,7 @@ const items = [
|
|
|
22
22
|
describe('format_thousands', function () {
|
|
23
23
|
items.forEach(function ([expected, ...args]) {
|
|
24
24
|
it(`${args} → ${expected}`, function () {
|
|
25
|
-
assert.strictEqual(
|
|
25
|
+
assert.strictEqual(format_thousands(...args), expected);
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
});
|
|
@@ -21,7 +21,12 @@ async function shell_ytdlp_progress(args, {user_friendly_status, ...options})
|
|
|
21
21
|
|
|
22
22
|
function progress_fn(v) {
|
|
23
23
|
const duration = format_seconds((Date.now() - time0)/1000);
|
|
24
|
-
|
|
24
|
+
if (v.merging) {
|
|
25
|
+
user_friendly_status(`Merging... duration=${duration}`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
user_friendly_status(`${v.perc} | [${v.current_part}/${v.total_parts}] ${v.done} of ${v.total} at ${v.speed} ETA ${v.eta} duration=${duration}`);
|
|
29
|
+
}
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
|
package/src/stream_progress.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const format_progress_bytes = require('./format_progress_bytes');
|
|
2
2
|
const make_progress = require('./make_progress');
|
|
3
3
|
const stream = require('stream');
|
|
4
4
|
|
|
@@ -33,7 +33,7 @@ function stream_progress({objectMode = false, total, user_friendly_status = s =>
|
|
|
33
33
|
});
|
|
34
34
|
function tick() {
|
|
35
35
|
progress.update(done);
|
|
36
|
-
user_friendly_status(
|
|
36
|
+
user_friendly_status(format_progress_bytes(progress));
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -6,8 +6,41 @@ const stream_filter = require('./stream_filter');
|
|
|
6
6
|
const stream_lines = require('./stream_lines');
|
|
7
7
|
const stream_map = require('./stream_map');
|
|
8
8
|
|
|
9
|
+
// [download] 0.0% of 15.71MiB at Unknown B/s ETA Unknown
|
|
10
|
+
// [download] 0.0% of 15.71MiB at Unknown B/s ETA Unknown
|
|
11
|
+
// [download] 0.0% of 15.71MiB at Unknown B/s ETA Unknown
|
|
12
|
+
// [download] 0.1% of 15.71MiB at Unknown B/s ETA Unknown
|
|
13
|
+
// [download] 0.2% of 15.71MiB at 21.76MiB/s ETA 00:00
|
|
14
|
+
// [download] 0.4% of 15.71MiB at 16.48MiB/s ETA 00:00
|
|
15
|
+
// [download] 0.8% of 15.71MiB at 25.54MiB/s ETA 00:00
|
|
16
|
+
// [download] 1.6% of 15.71MiB at 30.65MiB/s ETA 00:00
|
|
17
|
+
// [download] 3.2% of 15.71MiB at 42.99MiB/s ETA 00:00
|
|
18
|
+
// [download] 6.4% of 15.71MiB at 66.25MiB/s ETA 00:00
|
|
19
|
+
// [download] 12.7% of 15.71MiB at 81.24MiB/s ETA 00:00
|
|
20
|
+
// [download] 25.5% of 15.71MiB at 55.11MiB/s ETA 00:00
|
|
21
|
+
// [download] 50.9% of 15.71MiB at 33.83MiB/s ETA 00:00
|
|
22
|
+
// [download] 61.7% of 15.71MiB at 33.98MiB/s ETA 00:00
|
|
23
|
+
// [download] 61.7% of 15.71MiB at Unknown B/s ETA Unknown
|
|
24
|
+
// [download] 61.7% of 15.71MiB at Unknown B/s ETA Unknown
|
|
25
|
+
// [download] 61.7% of 15.71MiB at Unknown B/s ETA Unknown
|
|
26
|
+
// [download] 61.8% of 15.71MiB at Unknown B/s ETA Unknown
|
|
27
|
+
// [download] 61.9% of 15.71MiB at 12.32MiB/s ETA 00:00
|
|
28
|
+
// [download] 62.1% of 15.71MiB at 14.26MiB/s ETA 00:00
|
|
29
|
+
// [download] 62.5% of 15.71MiB at 25.10MiB/s ETA 00:00
|
|
30
|
+
// [download] 63.3% of 15.71MiB at 34.18MiB/s ETA 00:00
|
|
31
|
+
// [download] 64.9% of 15.71MiB at 8.95MiB/s ETA 00:00
|
|
32
|
+
// [download] 68.1% of 15.71MiB at 16.75MiB/s ETA 00:00
|
|
33
|
+
// [download] 74.4% of 15.71MiB at 29.10MiB/s ETA 00:00
|
|
34
|
+
// [download] 87.2% of 15.71MiB at 40.45MiB/s ETA 00:00
|
|
35
|
+
// [download] 100.0% of 15.71MiB at 47.64MiB/s ETA 00:00
|
|
36
|
+
// [download] 100% of 15.71MiB in 00:00:00 at 29.07MiB/s
|
|
37
|
+
// [Merger] Merging formats into "xxxxxxxxxxxxxxx.webm"
|
|
38
|
+
// Deleting original file xxxxxxxxxxxxxxx.f251.webm (pass -k to keep)
|
|
39
|
+
// Deleting original file xxxxxxxxxxxxxxx.f248.webm (pass -k to keep)
|
|
40
|
+
|
|
9
41
|
function stream_ytdlp_progress()
|
|
10
42
|
{
|
|
43
|
+
let last = {};
|
|
11
44
|
let current_part = 1;
|
|
12
45
|
const downloading_formats = [];
|
|
13
46
|
return stream.compose(
|
|
@@ -22,14 +55,25 @@ function stream_ytdlp_progress()
|
|
|
22
55
|
current_part = downloading_formats.indexOf(m[1]) + 1;
|
|
23
56
|
return false;
|
|
24
57
|
}
|
|
58
|
+
if (m = line.match(/^\[Merger]/i)) {
|
|
59
|
+
last.merging = true;
|
|
60
|
+
return last;
|
|
61
|
+
}
|
|
25
62
|
if (m = line.match(/^\[download] (.*) of (.*) at (.*) ETA (.*)$/)) {
|
|
26
63
|
const percentage = parseFloat(m[1].trim())/100;
|
|
27
64
|
const total = parse_bytes(m[2].trim());
|
|
28
65
|
const speed = m[3].trim().replace('i', '');
|
|
29
66
|
const eta = m[4].trim();
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
|
|
67
|
+
return last = {
|
|
68
|
+
current_part,
|
|
69
|
+
total_parts: downloading_formats.length,
|
|
70
|
+
perc: format_percents(percentage),
|
|
71
|
+
done: format_bytes(percentage*total),
|
|
72
|
+
total: format_bytes(total),
|
|
73
|
+
speed: speed.toLowerCase().includes('unknown') ? '~' : speed,
|
|
74
|
+
eta: eta.toLowerCase().includes('unknown') ? '~' : eta,
|
|
75
|
+
merging: false,
|
|
76
|
+
};
|
|
33
77
|
}
|
|
34
78
|
return false;
|
|
35
79
|
}),
|