@kud/qobuz-cli 0.1.0 → 0.2.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/README.md +8 -5
- package/dist/index.js +130 -45
- package/native/media-key.swift +5 -3
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
- **Fast search & metadata** — search albums, tracks, and artists; inspect album, artist, and track details.
|
|
16
16
|
- **Library & playlists** — list, add, and remove favourites; list, show, create, and edit playlists.
|
|
17
|
-
- **Media-key playback control** — `play`, `next`, and `
|
|
18
|
-
- **Quick open** — `open`
|
|
17
|
+
- **Media-key playback control** — `play`, `next`, `previous`, `forward`, and `rewind` drive the Qobuz desktop app via real media keys (macOS, requires Accessibility permission).
|
|
18
|
+
- **Quick open & copy** — `open` deep-links straight into the Qobuz app; `url` (alias `copy-url`) copies a link to the clipboard — bare `qobuz url` copies the **currently-playing** track.
|
|
19
19
|
- **Secure login** — stores a browser-borrowed token in the macOS Keychain; no password handling.
|
|
20
20
|
|
|
21
21
|
## Install
|
|
@@ -33,13 +33,16 @@ $ qobuz album 0634904032432
|
|
|
33
33
|
$ qobuz fav list
|
|
34
34
|
$ qobuz playlist create "Focus"
|
|
35
35
|
$ qobuz play # toggle play/pause in Qobuz
|
|
36
|
-
$ qobuz next # skip track
|
|
36
|
+
$ qobuz next # skip track (also: previous, forward, rewind)
|
|
37
37
|
$ qobuz open album 0634904032432 # open in the Qobuz app
|
|
38
|
+
$ qobuz url # copy the currently-playing track's link
|
|
39
|
+
$ qobuz url album 0634904032432 # copy a specific item's deep link
|
|
40
|
+
$ qobuz url --plain # print the bare URL (no clipboard) for scripting
|
|
38
41
|
```
|
|
39
42
|
|
|
40
|
-
Full command set: `login`, `logout`, `search`, `album`, `artist`, `track`, `similar`, `fav` (list/add/remove), `playlist` (list/show/create/add/remove), `url`, `open`, `play`, `next`, `previous` / `prev`.
|
|
43
|
+
Full command set: `login`, `logout`, `search`, `album`, `artist`, `track`, `similar`, `fav` (list/add/remove), `playlist` (list/show/create/add/remove), `url` / `copy-url`, `open`, `play`, `next`, `previous` / `prev`, `forward` / `ff`, `rewind` / `rew`.
|
|
41
44
|
|
|
42
|
-
> **macOS note** — playback commands (`play`, `next`, `previous`) use real media keys and require Accessibility permission granted to your terminal. The first playback command compiles a small Swift helper via `swiftc`.
|
|
45
|
+
> **macOS note** — playback commands (`play`, `next`, `previous`, `forward`, `rewind`) use real media keys and require Accessibility permission granted to your terminal. The first playback command compiles a small Swift helper via `swiftc`.
|
|
43
46
|
|
|
44
47
|
## Development
|
|
45
48
|
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { defineCommand as defineCommand13, runMain } from "citty";
|
|
5
5
|
|
|
6
|
+
// src/help.ts
|
|
7
|
+
import { renderUsage } from "citty";
|
|
8
|
+
var ESC = String.fromCharCode(27);
|
|
9
|
+
var stripAnsi = (value) => value.replace(new RegExp(`${ESC}\\[[0-9;]*m`, "g"), "");
|
|
10
|
+
var bold = (value) => `${ESC}[1m${value}${ESC}[22m`;
|
|
11
|
+
var underline = (value) => `${ESC}[4m${value}${ESC}[24m`;
|
|
12
|
+
var cyan = (value) => `${ESC}[36m${value}${ESC}[39m`;
|
|
13
|
+
var renderGenericUsage = async (command2) => {
|
|
14
|
+
const lines = (await renderUsage(command2)).split("\n");
|
|
15
|
+
const usageIndex = lines.findIndex(
|
|
16
|
+
(line) => stripAnsi(line).startsWith("USAGE")
|
|
17
|
+
);
|
|
18
|
+
if (usageIndex !== -1)
|
|
19
|
+
lines[usageIndex] = `${underline(bold("USAGE"))} ${cyan("qobuz <command> [options]")}`;
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
};
|
|
22
|
+
|
|
6
23
|
// src/commands/album.ts
|
|
7
24
|
import { defineCommand } from "citty";
|
|
8
25
|
|
|
@@ -47,9 +64,9 @@ var album = defineCommand({
|
|
|
47
64
|
args: {
|
|
48
65
|
id: { type: "positional", description: "Album ID", required: true }
|
|
49
66
|
},
|
|
50
|
-
run: async ({ args }) => {
|
|
67
|
+
run: async ({ args: args2 }) => {
|
|
51
68
|
const client = await connect();
|
|
52
|
-
const album2 = await client.albums.get(
|
|
69
|
+
const album2 = await client.albums.get(args2.id);
|
|
53
70
|
console.log(`${album2.title}`);
|
|
54
71
|
console.log(`by ${album2.artist?.name ?? "?"}`);
|
|
55
72
|
console.log(
|
|
@@ -66,9 +83,9 @@ var artist = defineCommand2({
|
|
|
66
83
|
args: {
|
|
67
84
|
id: { type: "positional", description: "Artist ID", required: true }
|
|
68
85
|
},
|
|
69
|
-
run: async ({ args }) => {
|
|
86
|
+
run: async ({ args: args2 }) => {
|
|
70
87
|
const client = await connect();
|
|
71
|
-
const artist2 = await client.artists.get(Number(
|
|
88
|
+
const artist2 = await client.artists.get(Number(args2.id));
|
|
72
89
|
console.log(artist2.name);
|
|
73
90
|
if (artist2.albumsCount !== void 0)
|
|
74
91
|
console.log(`${artist2.albumsCount} albums`);
|
|
@@ -87,9 +104,9 @@ var list = defineCommand3({
|
|
|
87
104
|
default: "albums"
|
|
88
105
|
}
|
|
89
106
|
},
|
|
90
|
-
run: async ({ args }) => {
|
|
107
|
+
run: async ({ args: args2 }) => {
|
|
91
108
|
const client = await connect();
|
|
92
|
-
const favourites = await client.favourites.list(
|
|
109
|
+
const favourites = await client.favourites.list(args2.type);
|
|
93
110
|
for (const album2 of favourites.albums)
|
|
94
111
|
console.log(
|
|
95
112
|
` ${album2.id} ${album2.artist?.name ?? "?"} \u2014 ${album2.title}`
|
|
@@ -116,10 +133,10 @@ var add = defineCommand3({
|
|
|
116
133
|
required: true
|
|
117
134
|
}
|
|
118
135
|
},
|
|
119
|
-
run: async ({ args }) => {
|
|
136
|
+
run: async ({ args: args2 }) => {
|
|
120
137
|
const client = await connect();
|
|
121
|
-
await client.favourites.add(
|
|
122
|
-
console.log(`\u2713 added ${
|
|
138
|
+
await client.favourites.add(args2.type, args2.id);
|
|
139
|
+
console.log(`\u2713 added ${args2.type} ${args2.id} to favourites`);
|
|
123
140
|
}
|
|
124
141
|
});
|
|
125
142
|
var remove = defineCommand3({
|
|
@@ -136,10 +153,10 @@ var remove = defineCommand3({
|
|
|
136
153
|
required: true
|
|
137
154
|
}
|
|
138
155
|
},
|
|
139
|
-
run: async ({ args }) => {
|
|
156
|
+
run: async ({ args: args2 }) => {
|
|
140
157
|
const client = await connect();
|
|
141
|
-
await client.favourites.remove(
|
|
142
|
-
console.log(`\u2713 removed ${
|
|
158
|
+
await client.favourites.remove(args2.type, args2.id);
|
|
159
|
+
console.log(`\u2713 removed ${args2.type} ${args2.id} from favourites`);
|
|
143
160
|
}
|
|
144
161
|
});
|
|
145
162
|
var fav = defineCommand3({
|
|
@@ -188,6 +205,16 @@ var openUrl = async (url2) => {
|
|
|
188
205
|
return false;
|
|
189
206
|
}
|
|
190
207
|
};
|
|
208
|
+
var copyToClipboard = async (text) => {
|
|
209
|
+
try {
|
|
210
|
+
const running = exec("pbcopy");
|
|
211
|
+
running.child.stdin?.end(text);
|
|
212
|
+
await running;
|
|
213
|
+
return true;
|
|
214
|
+
} catch {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
191
218
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
192
219
|
var countdownAndOpen = async (url2, seconds = 3) => {
|
|
193
220
|
for (const n of Array.from({ length: seconds }, (_, i) => seconds - i)) {
|
|
@@ -272,9 +299,9 @@ var open = defineCommand6({
|
|
|
272
299
|
},
|
|
273
300
|
id: { type: "positional", description: "ID", required: true }
|
|
274
301
|
},
|
|
275
|
-
run: async ({ args }) => {
|
|
302
|
+
run: async ({ args: args2 }) => {
|
|
276
303
|
const client = await connect();
|
|
277
|
-
const link = deepLinkFor(client,
|
|
304
|
+
const link = deepLinkFor(client, args2.type, args2.id);
|
|
278
305
|
if (!link) {
|
|
279
306
|
console.error("type must be one of: album, track, playlist, artist");
|
|
280
307
|
process.exit(1);
|
|
@@ -345,6 +372,16 @@ var previous = playbackCommand(
|
|
|
345
372
|
"Go to the previous track",
|
|
346
373
|
"previous"
|
|
347
374
|
);
|
|
375
|
+
var forward = playbackCommand(
|
|
376
|
+
"forward",
|
|
377
|
+
"Fast-forward within the current track",
|
|
378
|
+
"forward"
|
|
379
|
+
);
|
|
380
|
+
var rewind = playbackCommand(
|
|
381
|
+
"rewind",
|
|
382
|
+
"Rewind within the current track",
|
|
383
|
+
"rewind"
|
|
384
|
+
);
|
|
348
385
|
|
|
349
386
|
// src/commands/playlist.ts
|
|
350
387
|
import { defineCommand as defineCommand8 } from "citty";
|
|
@@ -365,9 +402,9 @@ var show = defineCommand8({
|
|
|
365
402
|
args: {
|
|
366
403
|
id: { type: "positional", description: "Playlist ID", required: true }
|
|
367
404
|
},
|
|
368
|
-
run: async ({ args }) => {
|
|
405
|
+
run: async ({ args: args2 }) => {
|
|
369
406
|
const client = await connect();
|
|
370
|
-
const playlist2 = await client.playlists.get(Number(
|
|
407
|
+
const playlist2 = await client.playlists.get(Number(args2.id));
|
|
371
408
|
console.log(`${playlist2.name} (${playlist2.tracksCount ?? 0} tracks)`);
|
|
372
409
|
if (playlist2.description) console.log(playlist2.description);
|
|
373
410
|
console.log(`open: ${client.deepLink.playlist(playlist2.id)}`);
|
|
@@ -383,11 +420,11 @@ var create = defineCommand8({
|
|
|
383
420
|
default: false
|
|
384
421
|
}
|
|
385
422
|
},
|
|
386
|
-
run: async ({ args }) => {
|
|
423
|
+
run: async ({ args: args2 }) => {
|
|
387
424
|
const client = await connect();
|
|
388
425
|
const playlist2 = await client.playlists.create({
|
|
389
|
-
name:
|
|
390
|
-
isPublic:
|
|
426
|
+
name: args2.name,
|
|
427
|
+
isPublic: args2.public
|
|
391
428
|
});
|
|
392
429
|
console.log(`\u2713 created playlist "${playlist2.name}" [${playlist2.id}]`);
|
|
393
430
|
}
|
|
@@ -402,12 +439,12 @@ var add2 = defineCommand8({
|
|
|
402
439
|
},
|
|
403
440
|
track: { type: "positional", description: "Track ID", required: true }
|
|
404
441
|
},
|
|
405
|
-
run: async ({ args }) => {
|
|
442
|
+
run: async ({ args: args2 }) => {
|
|
406
443
|
const client = await connect();
|
|
407
|
-
await client.playlists.addTracks(Number(
|
|
408
|
-
Number(
|
|
444
|
+
await client.playlists.addTracks(Number(args2.playlist), [
|
|
445
|
+
Number(args2.track)
|
|
409
446
|
]);
|
|
410
|
-
console.log(`\u2713 added track ${
|
|
447
|
+
console.log(`\u2713 added track ${args2.track} to playlist ${args2.playlist}`);
|
|
411
448
|
}
|
|
412
449
|
});
|
|
413
450
|
var remove2 = defineCommand8({
|
|
@@ -415,10 +452,10 @@ var remove2 = defineCommand8({
|
|
|
415
452
|
args: {
|
|
416
453
|
id: { type: "positional", description: "Playlist ID", required: true }
|
|
417
454
|
},
|
|
418
|
-
run: async ({ args }) => {
|
|
455
|
+
run: async ({ args: args2 }) => {
|
|
419
456
|
const client = await connect();
|
|
420
|
-
await client.playlists.remove(Number(
|
|
421
|
-
console.log(`\u2713 deleted playlist ${
|
|
457
|
+
await client.playlists.remove(Number(args2.id));
|
|
458
|
+
console.log(`\u2713 deleted playlist ${args2.id}`);
|
|
422
459
|
}
|
|
423
460
|
});
|
|
424
461
|
var playlist = defineCommand8({
|
|
@@ -441,10 +478,10 @@ var search = defineCommand9({
|
|
|
441
478
|
default: "10"
|
|
442
479
|
}
|
|
443
480
|
},
|
|
444
|
-
run: async ({ args }) => {
|
|
481
|
+
run: async ({ args: args2 }) => {
|
|
445
482
|
const client = await connect();
|
|
446
|
-
const results = await client.search.search(
|
|
447
|
-
limit: Number(
|
|
483
|
+
const results = await client.search.search(args2.query, {
|
|
484
|
+
limit: Number(args2.limit)
|
|
448
485
|
});
|
|
449
486
|
if (results.albums.length) {
|
|
450
487
|
console.log("\nAlbums");
|
|
@@ -480,9 +517,9 @@ var similar = defineCommand10({
|
|
|
480
517
|
args: {
|
|
481
518
|
id: { type: "positional", description: "Artist ID", required: true }
|
|
482
519
|
},
|
|
483
|
-
run: async ({ args }) => {
|
|
520
|
+
run: async ({ args: args2 }) => {
|
|
484
521
|
const client = await connect();
|
|
485
|
-
const artists = await client.artists.getSimilar(Number(
|
|
522
|
+
const artists = await client.artists.getSimilar(Number(args2.id));
|
|
486
523
|
for (const artist2 of artists) console.log(` ${artist2.id} ${artist2.name}`);
|
|
487
524
|
}
|
|
488
525
|
});
|
|
@@ -494,9 +531,9 @@ var track = defineCommand11({
|
|
|
494
531
|
args: {
|
|
495
532
|
id: { type: "positional", description: "Track ID", required: true }
|
|
496
533
|
},
|
|
497
|
-
run: async ({ args }) => {
|
|
534
|
+
run: async ({ args: args2 }) => {
|
|
498
535
|
const client = await connect();
|
|
499
|
-
const track2 = await client.tracks.get(Number(
|
|
536
|
+
const track2 = await client.tracks.get(Number(args2.id));
|
|
500
537
|
console.log(track2.title);
|
|
501
538
|
console.log(
|
|
502
539
|
`by ${track2.artist?.name ?? "?"}${track2.album ? ` \xB7 ${track2.album.title}` : ""}`
|
|
@@ -510,27 +547,60 @@ var track = defineCommand11({
|
|
|
510
547
|
|
|
511
548
|
// src/commands/url.ts
|
|
512
549
|
import { defineCommand as defineCommand12 } from "citty";
|
|
550
|
+
import { readNowPlayingTrackId } from "@kud/qobuz";
|
|
551
|
+
var currentTrackLink = async (client) => {
|
|
552
|
+
const trackId = await readNowPlayingTrackId();
|
|
553
|
+
if (!trackId) {
|
|
554
|
+
console.error(
|
|
555
|
+
"Nothing playing \u2014 couldn't read Qobuz's current track. Is the Qobuz app open and playing?"
|
|
556
|
+
);
|
|
557
|
+
process.exit(1);
|
|
558
|
+
}
|
|
559
|
+
return client.deepLink.track(trackId);
|
|
560
|
+
};
|
|
561
|
+
var specificLink = (client, type, id) => {
|
|
562
|
+
if (!id) {
|
|
563
|
+
console.error("usage: qobuz url <album|track|playlist|artist> <id>");
|
|
564
|
+
process.exit(1);
|
|
565
|
+
}
|
|
566
|
+
const link = deepLinkFor(client, type, id);
|
|
567
|
+
if (!link) {
|
|
568
|
+
console.error("type must be one of: album, track, playlist, artist");
|
|
569
|
+
process.exit(1);
|
|
570
|
+
}
|
|
571
|
+
return link;
|
|
572
|
+
};
|
|
513
573
|
var url = defineCommand12({
|
|
514
574
|
meta: {
|
|
515
575
|
name: "url",
|
|
516
|
-
description: "
|
|
576
|
+
description: "Copy a deep-link to the clipboard \u2014 the playing track, or a given item"
|
|
517
577
|
},
|
|
518
578
|
args: {
|
|
519
579
|
type: {
|
|
520
580
|
type: "positional",
|
|
521
|
-
description: "album | track | playlist | artist",
|
|
522
|
-
required:
|
|
581
|
+
description: "album | track | playlist | artist (omit for the current track)",
|
|
582
|
+
required: false
|
|
523
583
|
},
|
|
524
|
-
id: {
|
|
584
|
+
id: {
|
|
585
|
+
type: "positional",
|
|
586
|
+
description: "ID (omit for the current track)",
|
|
587
|
+
required: false
|
|
588
|
+
},
|
|
589
|
+
plain: {
|
|
590
|
+
type: "boolean",
|
|
591
|
+
description: "Print the bare URL to stdout (no clipboard) \u2014 for scripting",
|
|
592
|
+
default: false
|
|
593
|
+
}
|
|
525
594
|
},
|
|
526
|
-
run: async ({ args }) => {
|
|
595
|
+
run: async ({ args: args2 }) => {
|
|
527
596
|
const client = await connect();
|
|
528
|
-
const link =
|
|
529
|
-
if (
|
|
530
|
-
console.
|
|
531
|
-
|
|
597
|
+
const link = args2.type ? specificLink(client, args2.type, args2.id) : await currentTrackLink(client);
|
|
598
|
+
if (args2.plain) {
|
|
599
|
+
console.log(link);
|
|
600
|
+
return;
|
|
532
601
|
}
|
|
533
|
-
|
|
602
|
+
const copied = await copyToClipboard(link);
|
|
603
|
+
console.log(copied ? `\u2713 copied ${link}` : link);
|
|
534
604
|
}
|
|
535
605
|
});
|
|
536
606
|
|
|
@@ -555,7 +625,22 @@ var main = defineCommand13({
|
|
|
555
625
|
play,
|
|
556
626
|
next,
|
|
557
627
|
previous,
|
|
558
|
-
|
|
628
|
+
forward,
|
|
629
|
+
rewind
|
|
559
630
|
}
|
|
560
631
|
});
|
|
561
|
-
|
|
632
|
+
var aliases = {
|
|
633
|
+
"copy-url": "url",
|
|
634
|
+
prev: "previous",
|
|
635
|
+
ff: "forward",
|
|
636
|
+
rew: "rewind"
|
|
637
|
+
};
|
|
638
|
+
var args = process.argv.slice(2);
|
|
639
|
+
var [command, ...rest] = args;
|
|
640
|
+
var rawArgs = command && aliases[command] ? [aliases[command], ...rest] : args;
|
|
641
|
+
var isTopLevelHelp = rawArgs.length === 0 || rawArgs[0] === "--help" || rawArgs[0] === "-h";
|
|
642
|
+
if (isTopLevelHelp) {
|
|
643
|
+
console.log(await renderGenericUsage(main));
|
|
644
|
+
} else {
|
|
645
|
+
runMain(main, { rawArgs });
|
|
646
|
+
}
|
package/native/media-key.swift
CHANGED
|
@@ -4,8 +4,10 @@ import Cocoa
|
|
|
4
4
|
// IOKit ev_keymap.h media key codes.
|
|
5
5
|
let keyCodes: [String: Int32] = [
|
|
6
6
|
"play": 16, // NX_KEYTYPE_PLAY — play/pause toggle
|
|
7
|
-
"next": 17, // NX_KEYTYPE_NEXT
|
|
8
|
-
"previous": 18, // NX_KEYTYPE_PREVIOUS
|
|
7
|
+
"next": 17, // NX_KEYTYPE_NEXT — skip to next track
|
|
8
|
+
"previous": 18, // NX_KEYTYPE_PREVIOUS — skip to previous track
|
|
9
|
+
"forward": 19, // NX_KEYTYPE_FAST — fast-forward within the track
|
|
10
|
+
"rewind": 20, // NX_KEYTYPE_REWIND — rewind within the track
|
|
9
11
|
]
|
|
10
12
|
|
|
11
13
|
func postMediaKey(_ key: Int32) {
|
|
@@ -36,7 +38,7 @@ let fail = { (message: String, code: Int32) in
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
guard let name = CommandLine.arguments.dropFirst().first, let key = keyCodes[name] else {
|
|
39
|
-
fail("usage: media-key <play|next|previous>", 64)
|
|
41
|
+
fail("usage: media-key <play|next|previous|forward|rewind>", 64)
|
|
40
42
|
exit(64)
|
|
41
43
|
}
|
|
42
44
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kud/qobuz-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Command-line interface for Qobuz — search, library, and quick-open in the app",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/kud/qobuz-cli.git"
|
|
10
|
+
},
|
|
7
11
|
"bin": {
|
|
8
12
|
"qobuz": "./dist/index.js"
|
|
9
13
|
},
|
|
@@ -21,7 +25,7 @@
|
|
|
21
25
|
"node": ">=20"
|
|
22
26
|
},
|
|
23
27
|
"dependencies": {
|
|
24
|
-
"@kud/qobuz": "0.
|
|
28
|
+
"@kud/qobuz": "0.3.0",
|
|
25
29
|
"citty": "0.2.2"
|
|
26
30
|
},
|
|
27
31
|
"devDependencies": {
|