@kud/qobuz-cli 0.3.0 → 0.4.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/dist/index.js +200 -90
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -58,6 +58,41 @@ var deepLinkFor = (client, type, id) => {
|
|
|
58
58
|
return builders[type]?.(id);
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
+
// src/ui.ts
|
|
62
|
+
var ESC2 = String.fromCharCode(27);
|
|
63
|
+
var colour = process.stdout.isTTY;
|
|
64
|
+
var ansi = new RegExp(`${ESC2}\\[[0-9;]*m`, "g");
|
|
65
|
+
var style = (open2, close) => (text) => colour ? `${ESC2}[${open2}m${text}${ESC2}[${close}m` : text;
|
|
66
|
+
var bold2 = style("1", "22");
|
|
67
|
+
var dim = style("2", "22");
|
|
68
|
+
var accent = style("36", "39");
|
|
69
|
+
var muted = style("90", "39");
|
|
70
|
+
var good = style("32", "39");
|
|
71
|
+
var heading = (text) => console.log(`
|
|
72
|
+
${bold2(text)}`);
|
|
73
|
+
var success = (text) => console.log(`${good("\u2713")} ${text}`);
|
|
74
|
+
var link = (url2) => `${dim("\u2197")} ${accent(url2)}`;
|
|
75
|
+
var visibleWidth = (text) => text.replace(ansi, "").length;
|
|
76
|
+
var columns = (rows, aligns = []) => {
|
|
77
|
+
const colCount = Math.max(0, ...rows.map((row) => row.length));
|
|
78
|
+
const widths = Array.from(
|
|
79
|
+
{ length: colCount },
|
|
80
|
+
(_, i) => Math.max(0, ...rows.map((row) => visibleWidth(row[i] ?? "")))
|
|
81
|
+
);
|
|
82
|
+
const pad = (cell, i) => {
|
|
83
|
+
const gap = " ".repeat(Math.max(0, (widths[i] ?? 0) - visibleWidth(cell)));
|
|
84
|
+
return aligns[i] === "right" ? gap + cell : cell + gap;
|
|
85
|
+
};
|
|
86
|
+
return rows.map((row) => ` ${row.map(pad).join(" ").trimEnd()}`).join("\n");
|
|
87
|
+
};
|
|
88
|
+
var BLOCKS = ["", "\u258F", "\u258E", "\u258D", "\u258C", "\u258B", "\u258A", "\u2589"];
|
|
89
|
+
var bar = (value, max, width = 22) => {
|
|
90
|
+
const units = max > 0 ? value / max * width : 0;
|
|
91
|
+
const full = Math.floor(units);
|
|
92
|
+
const partial = BLOCKS[Math.round((units - full) * 8)] ?? "";
|
|
93
|
+
return `${"\u2588".repeat(full)}${partial}`.padEnd(width);
|
|
94
|
+
};
|
|
95
|
+
|
|
61
96
|
// src/commands/album.ts
|
|
62
97
|
var album = defineCommand({
|
|
63
98
|
meta: { name: "album", description: "Show album details" },
|
|
@@ -67,12 +102,16 @@ var album = defineCommand({
|
|
|
67
102
|
run: async ({ args: args2 }) => {
|
|
68
103
|
const client = await connect();
|
|
69
104
|
const album2 = await client.albums.get(args2.id);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
);
|
|
75
|
-
console.log(`
|
|
105
|
+
const meta = [
|
|
106
|
+
`${album2.tracksCount ?? "?"} tracks`,
|
|
107
|
+
`released ${album2.releaseDate ?? "?"}`,
|
|
108
|
+
album2.hires ? "Hi-Res" : void 0
|
|
109
|
+
].filter(Boolean).join(" \xB7 ");
|
|
110
|
+
console.log(`
|
|
111
|
+
${bold2(`\u{1F4BF} ${album2.title}`)}`);
|
|
112
|
+
console.log(` ${dim(`by ${album2.artist?.name ?? "?"}`)}`);
|
|
113
|
+
console.log(` ${dim(meta)}`);
|
|
114
|
+
console.log(` ${link(client.deepLink.album(album2.id))}`);
|
|
76
115
|
}
|
|
77
116
|
});
|
|
78
117
|
|
|
@@ -86,10 +125,11 @@ var artist = defineCommand2({
|
|
|
86
125
|
run: async ({ args: args2 }) => {
|
|
87
126
|
const client = await connect();
|
|
88
127
|
const artist2 = await client.artists.get(Number(args2.id));
|
|
89
|
-
console.log(
|
|
128
|
+
console.log(`
|
|
129
|
+
${bold2(`\u{1F3A4} ${artist2.name}`)}`);
|
|
90
130
|
if (artist2.albumsCount !== void 0)
|
|
91
|
-
console.log(`${artist2.albumsCount} albums`);
|
|
92
|
-
console.log(`
|
|
131
|
+
console.log(` ${dim(`${artist2.albumsCount} albums`)}`);
|
|
132
|
+
console.log(` ${link(client.deepLink.artist(artist2.id))}`);
|
|
93
133
|
}
|
|
94
134
|
});
|
|
95
135
|
|
|
@@ -107,16 +147,41 @@ var list = defineCommand3({
|
|
|
107
147
|
run: async ({ args: args2 }) => {
|
|
108
148
|
const client = await connect();
|
|
109
149
|
const favourites = await client.favourites.list(args2.type);
|
|
110
|
-
|
|
150
|
+
if (favourites.albums.length) {
|
|
151
|
+
heading("\u{1F4BF} Albums");
|
|
111
152
|
console.log(
|
|
112
|
-
|
|
153
|
+
columns(
|
|
154
|
+
favourites.albums.map((album2) => [
|
|
155
|
+
accent(album2.title),
|
|
156
|
+
dim(album2.artist?.name ?? "?"),
|
|
157
|
+
muted(String(album2.id))
|
|
158
|
+
])
|
|
159
|
+
)
|
|
113
160
|
);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
161
|
+
}
|
|
162
|
+
if (favourites.artists.length) {
|
|
163
|
+
heading("\u{1F3A4} Artists");
|
|
164
|
+
console.log(
|
|
165
|
+
columns(
|
|
166
|
+
favourites.artists.map((artist2) => [
|
|
167
|
+
accent(artist2.name),
|
|
168
|
+
muted(String(artist2.id))
|
|
169
|
+
])
|
|
170
|
+
)
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
if (favourites.tracks.length) {
|
|
174
|
+
heading("\u{1F3B5} Tracks");
|
|
117
175
|
console.log(
|
|
118
|
-
|
|
176
|
+
columns(
|
|
177
|
+
favourites.tracks.map((track2) => [
|
|
178
|
+
accent(track2.title),
|
|
179
|
+
dim(track2.artist?.name ?? "?"),
|
|
180
|
+
muted(String(track2.id))
|
|
181
|
+
])
|
|
182
|
+
)
|
|
119
183
|
);
|
|
184
|
+
}
|
|
120
185
|
}
|
|
121
186
|
});
|
|
122
187
|
var add = defineCommand3({
|
|
@@ -136,7 +201,7 @@ var add = defineCommand3({
|
|
|
136
201
|
run: async ({ args: args2 }) => {
|
|
137
202
|
const client = await connect();
|
|
138
203
|
await client.favourites.add(args2.type, args2.id);
|
|
139
|
-
|
|
204
|
+
success(`added ${args2.type} ${args2.id} to favourites`);
|
|
140
205
|
}
|
|
141
206
|
});
|
|
142
207
|
var remove = defineCommand3({
|
|
@@ -156,7 +221,7 @@ var remove = defineCommand3({
|
|
|
156
221
|
run: async ({ args: args2 }) => {
|
|
157
222
|
const client = await connect();
|
|
158
223
|
await client.favourites.remove(args2.type, args2.id);
|
|
159
|
-
|
|
224
|
+
success(`removed ${args2.type} ${args2.id} from favourites`);
|
|
160
225
|
}
|
|
161
226
|
});
|
|
162
227
|
var fav = defineCommand3({
|
|
@@ -184,16 +249,16 @@ var createPrompts = () => {
|
|
|
184
249
|
(resolve) => rl.question(question, (answer) => resolve(answer.trim()))
|
|
185
250
|
);
|
|
186
251
|
const askHidden = (question) => new Promise((resolve) => {
|
|
187
|
-
let
|
|
252
|
+
let muted2 = false;
|
|
188
253
|
rl._writeToOutput = (chunk) => {
|
|
189
|
-
if (!
|
|
254
|
+
if (!muted2) process.stdout.write(chunk);
|
|
190
255
|
};
|
|
191
256
|
rl.question(question, (answer) => {
|
|
192
257
|
rl._writeToOutput = (chunk) => process.stdout.write(chunk);
|
|
193
258
|
process.stdout.write("\n");
|
|
194
259
|
resolve(answer);
|
|
195
260
|
});
|
|
196
|
-
|
|
261
|
+
muted2 = true;
|
|
197
262
|
});
|
|
198
263
|
return { ask, askHidden, close: () => rl.close() };
|
|
199
264
|
};
|
|
@@ -217,8 +282,8 @@ var copyToClipboard = async (text) => {
|
|
|
217
282
|
};
|
|
218
283
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
219
284
|
var countdownAndOpen = async (url2, seconds = 3) => {
|
|
220
|
-
for (const
|
|
221
|
-
process.stdout.write(`\r Opening ${url2} in ${
|
|
285
|
+
for (const n2 of Array.from({ length: seconds }, (_, i) => seconds - i)) {
|
|
286
|
+
process.stdout.write(`\r Opening ${url2} in ${n2}\u2026 `);
|
|
222
287
|
await sleep(1e3);
|
|
223
288
|
}
|
|
224
289
|
process.stdout.write(`\r Opening ${url2} now.${" ".repeat(20)}
|
|
@@ -301,13 +366,13 @@ var open = defineCommand6({
|
|
|
301
366
|
},
|
|
302
367
|
run: async ({ args: args2 }) => {
|
|
303
368
|
const client = await connect();
|
|
304
|
-
const
|
|
305
|
-
if (!
|
|
369
|
+
const link2 = deepLinkFor(client, args2.type, args2.id);
|
|
370
|
+
if (!link2) {
|
|
306
371
|
console.error("type must be one of: album, track, playlist, artist");
|
|
307
372
|
process.exit(1);
|
|
308
373
|
}
|
|
309
|
-
console.log(`opening ${
|
|
310
|
-
await openUrl(
|
|
374
|
+
console.log(`opening ${link2}`);
|
|
375
|
+
await openUrl(link2);
|
|
311
376
|
}
|
|
312
377
|
});
|
|
313
378
|
|
|
@@ -390,11 +455,17 @@ var list2 = defineCommand8({
|
|
|
390
455
|
run: async () => {
|
|
391
456
|
const client = await connect();
|
|
392
457
|
const playlists = await client.playlists.listForUser();
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
458
|
+
if (!playlists.length) return;
|
|
459
|
+
heading("\u{1F4DD} Playlists");
|
|
460
|
+
console.log(
|
|
461
|
+
columns(
|
|
462
|
+
playlists.map((playlist2) => [
|
|
463
|
+
accent(playlist2.name),
|
|
464
|
+
dim(`${playlist2.tracksCount ?? 0} tracks`),
|
|
465
|
+
muted(String(playlist2.id))
|
|
466
|
+
])
|
|
467
|
+
)
|
|
468
|
+
);
|
|
398
469
|
}
|
|
399
470
|
});
|
|
400
471
|
var show = defineCommand8({
|
|
@@ -405,9 +476,11 @@ var show = defineCommand8({
|
|
|
405
476
|
run: async ({ args: args2 }) => {
|
|
406
477
|
const client = await connect();
|
|
407
478
|
const playlist2 = await client.playlists.get(Number(args2.id));
|
|
408
|
-
console.log(
|
|
409
|
-
|
|
410
|
-
console.log(`
|
|
479
|
+
console.log(`
|
|
480
|
+
${bold2(`\u{1F4DD} ${playlist2.name}`)}`);
|
|
481
|
+
console.log(` ${dim(`${playlist2.tracksCount ?? 0} tracks`)}`);
|
|
482
|
+
if (playlist2.description) console.log(` ${dim(playlist2.description)}`);
|
|
483
|
+
console.log(` ${link(client.deepLink.playlist(playlist2.id))}`);
|
|
411
484
|
}
|
|
412
485
|
});
|
|
413
486
|
var create = defineCommand8({
|
|
@@ -426,7 +499,7 @@ var create = defineCommand8({
|
|
|
426
499
|
name: args2.name,
|
|
427
500
|
isPublic: args2.public
|
|
428
501
|
});
|
|
429
|
-
|
|
502
|
+
success(`created playlist "${playlist2.name}" [${playlist2.id}]`);
|
|
430
503
|
}
|
|
431
504
|
});
|
|
432
505
|
var add2 = defineCommand8({
|
|
@@ -444,7 +517,7 @@ var add2 = defineCommand8({
|
|
|
444
517
|
await client.playlists.addTracks(Number(args2.playlist), [
|
|
445
518
|
Number(args2.track)
|
|
446
519
|
]);
|
|
447
|
-
|
|
520
|
+
success(`added track ${args2.track} to playlist ${args2.playlist}`);
|
|
448
521
|
}
|
|
449
522
|
});
|
|
450
523
|
var remove2 = defineCommand8({
|
|
@@ -455,7 +528,7 @@ var remove2 = defineCommand8({
|
|
|
455
528
|
run: async ({ args: args2 }) => {
|
|
456
529
|
const client = await connect();
|
|
457
530
|
await client.playlists.remove(Number(args2.id));
|
|
458
|
-
|
|
531
|
+
success(`deleted playlist ${args2.id}`);
|
|
459
532
|
}
|
|
460
533
|
});
|
|
461
534
|
var playlist = defineCommand8({
|
|
@@ -484,25 +557,41 @@ var search = defineCommand9({
|
|
|
484
557
|
limit: Number(args2.limit)
|
|
485
558
|
});
|
|
486
559
|
if (results.albums.length) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
560
|
+
heading("\u{1F4BF} Albums");
|
|
561
|
+
console.log(
|
|
562
|
+
columns(
|
|
563
|
+
results.albums.map((album2) => [
|
|
564
|
+
accent(album2.title),
|
|
565
|
+
dim(album2.artist?.name ?? "?"),
|
|
566
|
+
muted(String(album2.id))
|
|
567
|
+
])
|
|
568
|
+
)
|
|
569
|
+
);
|
|
493
570
|
}
|
|
494
571
|
if (results.artists.length) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
572
|
+
heading("\u{1F3A4} Artists");
|
|
573
|
+
console.log(
|
|
574
|
+
columns(
|
|
575
|
+
results.artists.map((artist2) => [
|
|
576
|
+
accent(artist2.name),
|
|
577
|
+
muted(String(artist2.id))
|
|
578
|
+
])
|
|
579
|
+
)
|
|
580
|
+
);
|
|
498
581
|
}
|
|
499
582
|
if (results.tracks.length) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
583
|
+
heading("\u{1F3B5} Tracks");
|
|
584
|
+
console.log(
|
|
585
|
+
columns(
|
|
586
|
+
results.tracks.map((track2) => [
|
|
587
|
+
accent(track2.title),
|
|
588
|
+
dim(track2.artist?.name ?? "?"),
|
|
589
|
+
dim(formatDuration(track2.duration)),
|
|
590
|
+
muted(String(track2.id))
|
|
591
|
+
]),
|
|
592
|
+
["left", "left", "right", "left"]
|
|
593
|
+
)
|
|
594
|
+
);
|
|
506
595
|
}
|
|
507
596
|
}
|
|
508
597
|
});
|
|
@@ -520,21 +609,35 @@ var similar = defineCommand10({
|
|
|
520
609
|
run: async ({ args: args2 }) => {
|
|
521
610
|
const client = await connect();
|
|
522
611
|
const artists = await client.artists.getSimilar(Number(args2.id));
|
|
523
|
-
|
|
612
|
+
if (!artists.length) return;
|
|
613
|
+
heading("\u{1F3A4} Similar artists");
|
|
614
|
+
console.log(
|
|
615
|
+
columns(
|
|
616
|
+
artists.map((artist2) => [
|
|
617
|
+
accent(artist2.name),
|
|
618
|
+
muted(String(artist2.id))
|
|
619
|
+
])
|
|
620
|
+
)
|
|
621
|
+
);
|
|
524
622
|
}
|
|
525
623
|
});
|
|
526
624
|
|
|
527
625
|
// src/commands/stats.ts
|
|
528
626
|
import { defineCommand as defineCommand11 } from "citty";
|
|
529
627
|
import { readLibraryStats } from "@kud/qobuz";
|
|
628
|
+
var n = (value) => value.toLocaleString("en-US");
|
|
530
629
|
var pct = (count, total) => total ? `${Math.round(1e3 * count / total) / 10}%` : "";
|
|
531
|
-
var
|
|
630
|
+
var chart = (title, rows, scaleMax) => {
|
|
532
631
|
if (!rows.length) return;
|
|
533
|
-
const
|
|
632
|
+
const max = scaleMax ?? Math.max(...rows.map((r) => r.value));
|
|
633
|
+
const labelWidth = Math.max(...rows.map((r) => r.label.length));
|
|
634
|
+
const valueWidth = Math.max(...rows.map((r) => n(r.value).length));
|
|
534
635
|
console.log(`
|
|
535
|
-
${title}`);
|
|
536
|
-
for (const
|
|
537
|
-
|
|
636
|
+
${bold2(title)}`);
|
|
637
|
+
for (const { label, value, suffix } of rows) {
|
|
638
|
+
const line = ` ${label.padEnd(labelWidth)} ${accent(bar(value, max))} ${dim(n(value).padStart(valueWidth))}`;
|
|
639
|
+
console.log(suffix ? `${line} ${dim(suffix)}` : line);
|
|
640
|
+
}
|
|
538
641
|
};
|
|
539
642
|
var stats = defineCommand11({
|
|
540
643
|
meta: {
|
|
@@ -554,30 +657,34 @@ var stats = defineCommand11({
|
|
|
554
657
|
}
|
|
555
658
|
const { totals, quality, topGenres, topLabels, topArtists, recentlyAdded } = data;
|
|
556
659
|
console.log(
|
|
557
|
-
|
|
660
|
+
`${bold2("\u{1F4CA} Collection")} ${dim(
|
|
661
|
+
`${n(totals.offlineAlbums)} albums \xB7 ${n(totals.offlineArtists)} artists \xB7 ${n(totals.offlineTracks)} offline \xB7 ${n(totals.savedTracks)} saved`
|
|
662
|
+
)}`
|
|
558
663
|
);
|
|
559
|
-
|
|
560
|
-
"Quality
|
|
561
|
-
quality.map((q) =>
|
|
562
|
-
`${q.bitDepth}-bit`,
|
|
563
|
-
|
|
564
|
-
|
|
664
|
+
chart(
|
|
665
|
+
"\u{1F39A}\uFE0F Quality \xB7 offline tracks",
|
|
666
|
+
quality.map((q) => ({
|
|
667
|
+
label: `${q.bitDepth}-bit`,
|
|
668
|
+
value: q.count,
|
|
669
|
+
suffix: pct(q.count, totals.offlineTracks)
|
|
670
|
+
})),
|
|
671
|
+
totals.offlineTracks
|
|
565
672
|
);
|
|
566
|
-
|
|
567
|
-
"Top genres",
|
|
568
|
-
topGenres.map((g) =>
|
|
673
|
+
chart(
|
|
674
|
+
"\u{1F3B8} Top genres",
|
|
675
|
+
topGenres.map((g) => ({ label: g.name, value: g.count }))
|
|
569
676
|
);
|
|
570
|
-
|
|
571
|
-
"Top artists
|
|
572
|
-
topArtists.map((a) =>
|
|
677
|
+
chart(
|
|
678
|
+
"\u{1F3A4} Top artists \xB7 by albums",
|
|
679
|
+
topArtists.map((a) => ({ label: a.name, value: a.count }))
|
|
573
680
|
);
|
|
574
|
-
|
|
575
|
-
"Top labels",
|
|
576
|
-
topLabels.map((l) =>
|
|
681
|
+
chart(
|
|
682
|
+
"\u{1F3F7}\uFE0F Top labels",
|
|
683
|
+
topLabels.map((l) => ({ label: l.name, value: l.count }))
|
|
577
684
|
);
|
|
578
|
-
|
|
579
|
-
"Added recently",
|
|
580
|
-
recentlyAdded.map((m) =>
|
|
685
|
+
chart(
|
|
686
|
+
"\u{1F4C5} Added recently",
|
|
687
|
+
recentlyAdded.map((m) => ({ label: m.month, value: m.count }))
|
|
581
688
|
);
|
|
582
689
|
}
|
|
583
690
|
});
|
|
@@ -592,14 +699,17 @@ var track = defineCommand12({
|
|
|
592
699
|
run: async ({ args: args2 }) => {
|
|
593
700
|
const client = await connect();
|
|
594
701
|
const track2 = await client.tracks.get(Number(args2.id));
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
);
|
|
702
|
+
const meta = [
|
|
703
|
+
formatDuration(track2.duration),
|
|
704
|
+
track2.hires ? "Hi-Res" : void 0
|
|
705
|
+
].filter(Boolean).join(" \xB7 ");
|
|
706
|
+
console.log(`
|
|
707
|
+
${bold2(`\u{1F3B5} ${track2.title}`)}`);
|
|
599
708
|
console.log(
|
|
600
|
-
|
|
709
|
+
` ${dim(`by ${track2.artist?.name ?? "?"}${track2.album ? ` \xB7 ${track2.album.title}` : ""}`)}`
|
|
601
710
|
);
|
|
602
|
-
console.log(`
|
|
711
|
+
if (meta) console.log(` ${dim(meta)}`);
|
|
712
|
+
console.log(` ${link(client.deepLink.track(track2.id))}`);
|
|
603
713
|
}
|
|
604
714
|
});
|
|
605
715
|
|
|
@@ -621,12 +731,12 @@ var specificLink = (client, type, id) => {
|
|
|
621
731
|
console.error("usage: qobuz url <album|track|playlist|artist> <id>");
|
|
622
732
|
process.exit(1);
|
|
623
733
|
}
|
|
624
|
-
const
|
|
625
|
-
if (!
|
|
734
|
+
const link2 = deepLinkFor(client, type, id);
|
|
735
|
+
if (!link2) {
|
|
626
736
|
console.error("type must be one of: album, track, playlist, artist");
|
|
627
737
|
process.exit(1);
|
|
628
738
|
}
|
|
629
|
-
return
|
|
739
|
+
return link2;
|
|
630
740
|
};
|
|
631
741
|
var url = defineCommand13({
|
|
632
742
|
meta: {
|
|
@@ -652,13 +762,13 @@ var url = defineCommand13({
|
|
|
652
762
|
},
|
|
653
763
|
run: async ({ args: args2 }) => {
|
|
654
764
|
const client = await connect();
|
|
655
|
-
const
|
|
765
|
+
const link2 = args2.type ? specificLink(client, args2.type, args2.id) : await currentTrackLink(client);
|
|
656
766
|
if (args2.plain) {
|
|
657
|
-
console.log(
|
|
767
|
+
console.log(link2);
|
|
658
768
|
return;
|
|
659
769
|
}
|
|
660
|
-
const copied = await copyToClipboard(
|
|
661
|
-
console.log(copied ? `\u2713 copied ${
|
|
770
|
+
const copied = await copyToClipboard(link2);
|
|
771
|
+
console.log(copied ? `\u2713 copied ${link2}` : link2);
|
|
662
772
|
}
|
|
663
773
|
});
|
|
664
774
|
|