@kud/qobuz-cli 0.4.0 → 0.5.1
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 +9 -43
- package/package.json +5 -6
- package/native/media-key.swift +0 -53
package/dist/index.js
CHANGED
|
@@ -48,15 +48,17 @@ var formatDuration = (seconds) => {
|
|
|
48
48
|
const remainder = String(seconds % 60).padStart(2, "0");
|
|
49
49
|
return `${minutes}:${remainder}`;
|
|
50
50
|
};
|
|
51
|
-
var
|
|
51
|
+
var linkFor = (links, type, id) => {
|
|
52
52
|
const builders = {
|
|
53
|
-
album: (value) =>
|
|
54
|
-
track: (value) =>
|
|
55
|
-
playlist: (value) =>
|
|
56
|
-
artist: (value) =>
|
|
53
|
+
album: (value) => links.album(value),
|
|
54
|
+
track: (value) => links.track(Number(value)),
|
|
55
|
+
playlist: (value) => links.playlist(Number(value)),
|
|
56
|
+
artist: (value) => links.artist(Number(value))
|
|
57
57
|
};
|
|
58
58
|
return builders[type]?.(id);
|
|
59
59
|
};
|
|
60
|
+
var deepLinkFor = (client, type, id) => linkFor(client.deepLink, type, id);
|
|
61
|
+
var appLinkFor = (client, type, id) => linkFor(client.appLink, type, id);
|
|
60
62
|
|
|
61
63
|
// src/ui.ts
|
|
62
64
|
var ESC2 = String.fromCharCode(27);
|
|
@@ -366,7 +368,7 @@ var open = defineCommand6({
|
|
|
366
368
|
},
|
|
367
369
|
run: async ({ args: args2 }) => {
|
|
368
370
|
const client = await connect();
|
|
369
|
-
const link2 =
|
|
371
|
+
const link2 = appLinkFor(client, args2.type, args2.id);
|
|
370
372
|
if (!link2) {
|
|
371
373
|
console.error("type must be one of: album, track, playlist, artist");
|
|
372
374
|
process.exit(1);
|
|
@@ -378,43 +380,7 @@ var open = defineCommand6({
|
|
|
378
380
|
|
|
379
381
|
// src/commands/playback.ts
|
|
380
382
|
import { defineCommand as defineCommand7 } from "citty";
|
|
381
|
-
|
|
382
|
-
// src/media-key.ts
|
|
383
|
-
import { execFile as execFile2 } from "child_process";
|
|
384
|
-
import { existsSync } from "fs";
|
|
385
|
-
import { dirname, join } from "path";
|
|
386
|
-
import { fileURLToPath } from "url";
|
|
387
|
-
import { promisify as promisify2 } from "util";
|
|
388
|
-
var exec2 = promisify2(execFile2);
|
|
389
|
-
var findPackageRoot = () => {
|
|
390
|
-
let dir = dirname(fileURLToPath(import.meta.url));
|
|
391
|
-
while (!existsSync(join(dir, "package.json"))) {
|
|
392
|
-
const parent = dirname(dir);
|
|
393
|
-
if (parent === dir)
|
|
394
|
-
throw new Error("could not locate the qobuz-cli package root");
|
|
395
|
-
dir = parent;
|
|
396
|
-
}
|
|
397
|
-
return dir;
|
|
398
|
-
};
|
|
399
|
-
var root = findPackageRoot();
|
|
400
|
-
var source = join(root, "native", "media-key.swift");
|
|
401
|
-
var binary = join(root, "native", "media-key");
|
|
402
|
-
var ensureBinary = async () => {
|
|
403
|
-
if (!existsSync(binary)) await exec2("swiftc", ["-O", source, "-o", binary]);
|
|
404
|
-
return binary;
|
|
405
|
-
};
|
|
406
|
-
var sendMediaKey = async (key) => {
|
|
407
|
-
const bin = await ensureBinary();
|
|
408
|
-
try {
|
|
409
|
-
await exec2(bin, [key]);
|
|
410
|
-
} catch (error) {
|
|
411
|
-
throw new Error(
|
|
412
|
-
(error.stderr ?? String(error)).trim()
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
// src/commands/playback.ts
|
|
383
|
+
import { sendMediaKey } from "@kud/macos-media-keys";
|
|
418
384
|
var playbackCommand = (name, description, key) => defineCommand7({
|
|
419
385
|
meta: { name, description },
|
|
420
386
|
run: async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kud/qobuz-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Command-line interface for Qobuz — search, library, and quick-open in the app",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,12 +12,10 @@
|
|
|
12
12
|
"qobuz": "./dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
-
"dist"
|
|
16
|
-
"native/media-key.swift"
|
|
15
|
+
"dist"
|
|
17
16
|
],
|
|
18
17
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
-
"build:native": "swiftc -O native/media-key.swift -o native/media-key",
|
|
18
|
+
"build": "tsup",
|
|
21
19
|
"dev": "tsx src/index.ts",
|
|
22
20
|
"typecheck": "tsc --noEmit"
|
|
23
21
|
},
|
|
@@ -25,7 +23,8 @@
|
|
|
25
23
|
"node": ">=20"
|
|
26
24
|
},
|
|
27
25
|
"dependencies": {
|
|
28
|
-
"@kud/
|
|
26
|
+
"@kud/macos-media-keys": "0.1.0",
|
|
27
|
+
"@kud/qobuz": "0.5.0",
|
|
29
28
|
"citty": "0.2.2"
|
|
30
29
|
},
|
|
31
30
|
"devDependencies": {
|
package/native/media-key.swift
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import ApplicationServices
|
|
2
|
-
import Cocoa
|
|
3
|
-
|
|
4
|
-
// IOKit ev_keymap.h media key codes.
|
|
5
|
-
let keyCodes: [String: Int32] = [
|
|
6
|
-
"play": 16, // NX_KEYTYPE_PLAY — play/pause toggle
|
|
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
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
func postMediaKey(_ key: Int32) {
|
|
14
|
-
func send(down: Bool) {
|
|
15
|
-
let flags = NSEvent.ModifierFlags(rawValue: down ? 0xA00 : 0xB00)
|
|
16
|
-
let data1 = Int((key << 16) | (down ? 0xA00 : 0xB00))
|
|
17
|
-
let event = NSEvent.otherEvent(
|
|
18
|
-
with: .systemDefined,
|
|
19
|
-
location: .zero,
|
|
20
|
-
modifierFlags: flags,
|
|
21
|
-
timestamp: 0,
|
|
22
|
-
windowNumber: 0,
|
|
23
|
-
context: nil,
|
|
24
|
-
subtype: 8,
|
|
25
|
-
data1: data1,
|
|
26
|
-
data2: -1
|
|
27
|
-
)
|
|
28
|
-
event?.cgEvent?.post(tap: .cghidEventTap)
|
|
29
|
-
}
|
|
30
|
-
send(down: true)
|
|
31
|
-
usleep(1000)
|
|
32
|
-
send(down: false)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let fail = { (message: String, code: Int32) in
|
|
36
|
-
FileHandle.standardError.write(Data("\(message)\n".utf8))
|
|
37
|
-
exit(code)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
guard let name = CommandLine.arguments.dropFirst().first, let key = keyCodes[name] else {
|
|
41
|
-
fail("usage: media-key <play|next|previous|forward|rewind>", 64)
|
|
42
|
-
exit(64)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
guard AXIsProcessTrusted() else {
|
|
46
|
-
fail(
|
|
47
|
-
"not authorized — grant your terminal Accessibility access in System Settings → Privacy & Security → Accessibility",
|
|
48
|
-
77
|
|
49
|
-
)
|
|
50
|
-
exit(77)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
postMediaKey(key)
|