@kud/qobuz-cli 0.1.0 → 0.3.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 CHANGED
@@ -14,8 +14,9 @@
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 `previous` drive the Qobuz desktop app via real media keys (macOS, requires Accessibility permission).
18
- - **Quick open** — `open` and `url` deep-link straight into the Qobuz app.
17
+ - **Collection stats** — `qobuz stats` shows your genre mix, hi-res ratio, and top artists/labels from the local desktop library.
18
+ - **Media-key playback control** — `play`, `next`, `previous`, `forward`, and `rewind` drive the Qobuz desktop app via real media keys (macOS, requires Accessibility permission).
19
+ - **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
20
  - **Secure login** — stores a browser-borrowed token in the macOS Keychain; no password handling.
20
21
 
21
22
  ## Install
@@ -32,14 +33,18 @@ $ qobuz search "radiohead"
32
33
  $ qobuz album 0634904032432
33
34
  $ qobuz fav list
34
35
  $ qobuz playlist create "Focus"
36
+ $ qobuz stats # collection analytics from the desktop library
35
37
  $ qobuz play # toggle play/pause in Qobuz
36
- $ qobuz next # skip track
38
+ $ qobuz next # skip track (also: previous, forward, rewind)
37
39
  $ qobuz open album 0634904032432 # open in the Qobuz app
40
+ $ qobuz url # copy the currently-playing track's link
41
+ $ qobuz url album 0634904032432 # copy a specific item's deep link
42
+ $ qobuz url --plain # print the bare URL (no clipboard) for scripting
38
43
  ```
39
44
 
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`.
45
+ Full command set: `login`, `logout`, `search`, `album`, `artist`, `track`, `similar`, `fav` (list/add/remove), `playlist` (list/show/create/add/remove), `stats`, `url` / `copy-url`, `open`, `play`, `next`, `previous` / `prev`, `forward` / `ff`, `rewind` / `rew`.
41
46
 
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`.
47
+ > **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
48
 
44
49
  ## Development
45
50
 
package/dist/index.js CHANGED
@@ -1,7 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { defineCommand as defineCommand13, runMain } from "citty";
4
+ import { defineCommand as defineCommand14, runMain } from "citty";
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
+ };
5
22
 
6
23
  // src/commands/album.ts
7
24
  import { defineCommand } from "citty";
@@ -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(args.id);
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(args.id));
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(args.type);
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(args.type, args.id);
122
- console.log(`\u2713 added ${args.type} ${args.id} to favourites`);
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(args.type, args.id);
142
- console.log(`\u2713 removed ${args.type} ${args.id} from favourites`);
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, args.type, args.id);
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(args.id));
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: args.name,
390
- isPublic: args.public
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(args.playlist), [
408
- Number(args.track)
444
+ await client.playlists.addTracks(Number(args2.playlist), [
445
+ Number(args2.track)
409
446
  ]);
410
- console.log(`\u2713 added track ${args.track} to playlist ${args.playlist}`);
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(args.id));
421
- console.log(`\u2713 deleted playlist ${args.id}`);
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(args.query, {
447
- limit: Number(args.limit)
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,23 +517,81 @@ 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(args.id));
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
  });
489
526
 
490
- // src/commands/track.ts
527
+ // src/commands/stats.ts
491
528
  import { defineCommand as defineCommand11 } from "citty";
492
- var track = defineCommand11({
529
+ import { readLibraryStats } from "@kud/qobuz";
530
+ var pct = (count, total) => total ? `${Math.round(1e3 * count / total) / 10}%` : "";
531
+ var section = (title, rows) => {
532
+ if (!rows.length) return;
533
+ const width = Math.max(...rows.map(([label]) => label.length));
534
+ console.log(`
535
+ ${title}`);
536
+ for (const [label, value] of rows)
537
+ console.log(` ${label.padEnd(width)} ${value}`);
538
+ };
539
+ var stats = defineCommand11({
540
+ meta: {
541
+ name: "stats",
542
+ description: "Show collection analytics from your Qobuz desktop library"
543
+ },
544
+ args: {
545
+ limit: { type: "string", description: "Rows per breakdown", default: "10" }
546
+ },
547
+ run: async ({ args: args2 }) => {
548
+ const data = await readLibraryStats({ limit: Number(args2.limit) });
549
+ if (!data) {
550
+ console.error(
551
+ "No Qobuz library found \u2014 is the desktop app installed (macOS)?"
552
+ );
553
+ process.exit(1);
554
+ }
555
+ const { totals, quality, topGenres, topLabels, topArtists, recentlyAdded } = data;
556
+ console.log(
557
+ `Collection: ${totals.offlineAlbums} albums \xB7 ${totals.offlineArtists} artists \xB7 ${totals.offlineTracks} offline tracks \xB7 ${totals.savedTracks} saved tracks`
558
+ );
559
+ section(
560
+ "Quality (offline tracks)",
561
+ quality.map((q) => [
562
+ `${q.bitDepth}-bit`,
563
+ `${q.count} ${pct(q.count, totals.offlineTracks)}`
564
+ ])
565
+ );
566
+ section(
567
+ "Top genres",
568
+ topGenres.map((g) => [g.name, String(g.count)])
569
+ );
570
+ section(
571
+ "Top artists (by albums)",
572
+ topArtists.map((a) => [a.name, String(a.count)])
573
+ );
574
+ section(
575
+ "Top labels",
576
+ topLabels.map((l) => [l.name, String(l.count)])
577
+ );
578
+ section(
579
+ "Added recently",
580
+ recentlyAdded.map((m) => [m.month, String(m.count)])
581
+ );
582
+ }
583
+ });
584
+
585
+ // src/commands/track.ts
586
+ import { defineCommand as defineCommand12 } from "citty";
587
+ var track = defineCommand12({
493
588
  meta: { name: "track", description: "Show track details" },
494
589
  args: {
495
590
  id: { type: "positional", description: "Track ID", required: true }
496
591
  },
497
- run: async ({ args }) => {
592
+ run: async ({ args: args2 }) => {
498
593
  const client = await connect();
499
- const track2 = await client.tracks.get(Number(args.id));
594
+ const track2 = await client.tracks.get(Number(args2.id));
500
595
  console.log(track2.title);
501
596
  console.log(
502
597
  `by ${track2.artist?.name ?? "?"}${track2.album ? ` \xB7 ${track2.album.title}` : ""}`
@@ -509,33 +604,66 @@ var track = defineCommand11({
509
604
  });
510
605
 
511
606
  // src/commands/url.ts
512
- import { defineCommand as defineCommand12 } from "citty";
513
- var url = defineCommand12({
607
+ import { defineCommand as defineCommand13 } from "citty";
608
+ import { readNowPlayingTrackId } from "@kud/qobuz";
609
+ var currentTrackLink = async (client) => {
610
+ const trackId = await readNowPlayingTrackId();
611
+ if (!trackId) {
612
+ console.error(
613
+ "Nothing playing \u2014 couldn't read Qobuz's current track. Is the Qobuz app open and playing?"
614
+ );
615
+ process.exit(1);
616
+ }
617
+ return client.deepLink.track(trackId);
618
+ };
619
+ var specificLink = (client, type, id) => {
620
+ if (!id) {
621
+ console.error("usage: qobuz url <album|track|playlist|artist> <id>");
622
+ process.exit(1);
623
+ }
624
+ const link = deepLinkFor(client, type, id);
625
+ if (!link) {
626
+ console.error("type must be one of: album, track, playlist, artist");
627
+ process.exit(1);
628
+ }
629
+ return link;
630
+ };
631
+ var url = defineCommand13({
514
632
  meta: {
515
633
  name: "url",
516
- description: "Print the open.qobuz.com deep-link for an item (without opening it)"
634
+ description: "Copy a deep-link to the clipboard \u2014 the playing track, or a given item"
517
635
  },
518
636
  args: {
519
637
  type: {
520
638
  type: "positional",
521
- description: "album | track | playlist | artist",
522
- required: true
639
+ description: "album | track | playlist | artist (omit for the current track)",
640
+ required: false
523
641
  },
524
- id: { type: "positional", description: "ID", required: true }
642
+ id: {
643
+ type: "positional",
644
+ description: "ID (omit for the current track)",
645
+ required: false
646
+ },
647
+ plain: {
648
+ type: "boolean",
649
+ description: "Print the bare URL to stdout (no clipboard) \u2014 for scripting",
650
+ default: false
651
+ }
525
652
  },
526
- run: async ({ args }) => {
653
+ run: async ({ args: args2 }) => {
527
654
  const client = await connect();
528
- const link = deepLinkFor(client, args.type, args.id);
529
- if (!link) {
530
- console.error("type must be one of: album, track, playlist, artist");
531
- process.exit(1);
655
+ const link = args2.type ? specificLink(client, args2.type, args2.id) : await currentTrackLink(client);
656
+ if (args2.plain) {
657
+ console.log(link);
658
+ return;
532
659
  }
533
- console.log(link);
660
+ const copied = await copyToClipboard(link);
661
+ console.log(copied ? `\u2713 copied ${link}` : link);
534
662
  }
535
663
  });
536
664
 
537
665
  // src/index.ts
538
- var main = defineCommand13({
666
+ var main = defineCommand14({
539
667
  meta: {
540
668
  name: "qobuz",
541
669
  description: "Qobuz from the command line \u2014 search, library, and quick-open in the app"
@@ -550,12 +678,28 @@ var main = defineCommand13({
550
678
  similar,
551
679
  fav,
552
680
  playlist,
681
+ stats,
553
682
  url,
554
683
  open,
555
684
  play,
556
685
  next,
557
686
  previous,
558
- prev: previous
687
+ forward,
688
+ rewind
559
689
  }
560
690
  });
561
- runMain(main);
691
+ var aliases = {
692
+ "copy-url": "url",
693
+ prev: "previous",
694
+ ff: "forward",
695
+ rew: "rewind"
696
+ };
697
+ var args = process.argv.slice(2);
698
+ var [command, ...rest] = args;
699
+ var rawArgs = command && aliases[command] ? [aliases[command], ...rest] : args;
700
+ var isTopLevelHelp = rawArgs.length === 0 || rawArgs[0] === "--help" || rawArgs[0] === "-h";
701
+ if (isTopLevelHelp) {
702
+ console.log(await renderGenericUsage(main));
703
+ } else {
704
+ runMain(main, { rawArgs });
705
+ }
@@ -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.1.0",
3
+ "version": "0.3.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.1.0",
28
+ "@kud/qobuz": "0.4.0",
25
29
  "citty": "0.2.2"
26
30
  },
27
31
  "devDependencies": {