@kud/qobuz-cli 1.0.0 → 1.1.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/LICENSE +21 -0
- package/README.md +8 -0
- package/dist/index.js +248 -9
- package/package.json +11 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Erwann Mest
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -65,6 +65,7 @@ Run `qobuz` (no arguments) or `qobuz tui` to open the interactive full-screen in
|
|
|
65
65
|
$ qobuz # open interactive TUI
|
|
66
66
|
$ qobuz tui # same — explicit subcommand
|
|
67
67
|
$ qobuz login # connect (opens browser, paste app_id + token)
|
|
68
|
+
$ qobuz login --browser # connect by signing in; token captured automatically
|
|
68
69
|
$ qobuz search "radiohead"
|
|
69
70
|
$ qobuz album 0634904032432
|
|
70
71
|
$ qobuz fav list
|
|
@@ -84,6 +85,10 @@ Full command set: `tui`, `login`, `logout`, `search`, `album`, `artist`, `track`
|
|
|
84
85
|
|
|
85
86
|
> **macOS note** — playback commands (`play`, `next`, `previous`, `forward`, `rewind`) and TUI playback keys (`space`, `n`, `p`) use real media keys and require Accessibility permission granted to your terminal. The first playback command compiles a small Swift helper via `swiftc`.
|
|
86
87
|
|
|
88
|
+
### Assisted login (`--browser`)
|
|
89
|
+
|
|
90
|
+
`qobuz login --browser` opens a real, visible Chromium window on play.qobuz.com/login and lets you sign in there exactly as you would normally. Once you are in, the CLI captures the session token the web player sends (the `X-User-Auth-Token` request header, with the player's localStorage as a fallback), validates it and saves it to the Keychain just like the paste flow, then closes the window. Your password is typed into Qobuz's own page and never passes through, or is stored by, the CLI. Playwright is an optional peer dependency and is not installed by default; `--browser` prints the install command (`npm install -g playwright && npx playwright install chromium`) if it is missing. If no token appears within five minutes, plain `qobuz login` remains available.
|
|
91
|
+
|
|
87
92
|
## Development
|
|
88
93
|
|
|
89
94
|
```sh
|
|
@@ -97,3 +102,6 @@ npm run typecheck
|
|
|
97
102
|
```
|
|
98
103
|
|
|
99
104
|
📚 **Full documentation → [qobuz-cli/docs](https://kud.io/projects/qobuz-cli/docs)**
|
|
105
|
+
## Disclaimer
|
|
106
|
+
|
|
107
|
+
This is an independent, unofficial project — not affiliated with, endorsed by, or sponsored by Qobuz. "Qobuz", the Qobuz logo, and any icons derived from it are trademarks of Qobuz Music, used here only to indicate compatibility.
|
package/dist/index.js
CHANGED
|
@@ -222,6 +222,191 @@ var init_prompts = __esm({
|
|
|
222
222
|
}
|
|
223
223
|
});
|
|
224
224
|
|
|
225
|
+
// src/auth/browser-login.ts
|
|
226
|
+
var browser_login_exports = {};
|
|
227
|
+
__export(browser_login_exports, {
|
|
228
|
+
CaptureTimeoutError: () => CaptureTimeoutError,
|
|
229
|
+
DEFAULT_TIMEOUT_MS: () => DEFAULT_TIMEOUT_MS,
|
|
230
|
+
LOGIN_URL: () => LOGIN_URL,
|
|
231
|
+
PLAYWRIGHT_INSTALL_COMMAND: () => PLAYWRIGHT_INSTALL_COMMAND,
|
|
232
|
+
PlaywrightMissingError: () => PlaywrightMissingError,
|
|
233
|
+
captureToken: () => captureToken,
|
|
234
|
+
loadPlaywright: () => loadPlaywright,
|
|
235
|
+
runBrowserCapture: () => runBrowserCapture,
|
|
236
|
+
tokenFromHeaders: () => tokenFromHeaders,
|
|
237
|
+
tokenFromStorage: () => tokenFromStorage
|
|
238
|
+
});
|
|
239
|
+
var LOGIN_URL, DEFAULT_TIMEOUT_MS, PLAYWRIGHT_INSTALL_COMMAND, PlaywrightMissingError, CaptureTimeoutError, isModuleNotFound, PLAYWRIGHT_MODULE, defaultImporter, loadPlaywright, header, tokenFromHeaders, findToken, tokenFromStorage, readLocalStorage, captureToken, runBrowserCapture;
|
|
240
|
+
var init_browser_login = __esm({
|
|
241
|
+
"src/auth/browser-login.ts"() {
|
|
242
|
+
"use strict";
|
|
243
|
+
LOGIN_URL = "https://play.qobuz.com/login";
|
|
244
|
+
DEFAULT_TIMEOUT_MS = 5 * 6e4;
|
|
245
|
+
PLAYWRIGHT_INSTALL_COMMAND = "npm install -g playwright && npx playwright install chromium";
|
|
246
|
+
PlaywrightMissingError = class extends Error {
|
|
247
|
+
constructor() {
|
|
248
|
+
super(
|
|
249
|
+
`--browser needs Playwright, which is not installed.
|
|
250
|
+
Install it with: ${PLAYWRIGHT_INSTALL_COMMAND}`
|
|
251
|
+
);
|
|
252
|
+
this.name = "PlaywrightMissingError";
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
CaptureTimeoutError = class extends Error {
|
|
256
|
+
constructor(timeoutMs) {
|
|
257
|
+
super(
|
|
258
|
+
`No Qobuz session token seen within ${Math.round(timeoutMs / 1e3)}s.
|
|
259
|
+
Run \`qobuz login\` without --browser to paste the token manually.`
|
|
260
|
+
);
|
|
261
|
+
this.name = "CaptureTimeoutError";
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
isModuleNotFound = (error) => {
|
|
265
|
+
const code = error?.code;
|
|
266
|
+
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND";
|
|
267
|
+
};
|
|
268
|
+
PLAYWRIGHT_MODULE = "playwright";
|
|
269
|
+
defaultImporter = (specifier) => import(specifier);
|
|
270
|
+
loadPlaywright = async (importer = defaultImporter) => {
|
|
271
|
+
try {
|
|
272
|
+
const mod = await importer(PLAYWRIGHT_MODULE);
|
|
273
|
+
const playwright = mod?.chromium ? mod : mod?.default;
|
|
274
|
+
if (!playwright?.chromium) throw new PlaywrightMissingError();
|
|
275
|
+
return playwright;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error instanceof PlaywrightMissingError || isModuleNotFound(error))
|
|
278
|
+
throw new PlaywrightMissingError();
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
header = (headers, name) => {
|
|
283
|
+
const wanted = name.toLowerCase();
|
|
284
|
+
const entry = Object.entries(headers).find(
|
|
285
|
+
([key]) => key.toLowerCase() === wanted
|
|
286
|
+
);
|
|
287
|
+
const value = entry?.[1]?.trim();
|
|
288
|
+
return value ? value : void 0;
|
|
289
|
+
};
|
|
290
|
+
tokenFromHeaders = (headers) => {
|
|
291
|
+
const token = header(headers, "x-user-auth-token");
|
|
292
|
+
if (!token) return void 0;
|
|
293
|
+
const appId = header(headers, "x-app-id");
|
|
294
|
+
return { token, ...appId ? { appId } : {}, source: "request" };
|
|
295
|
+
};
|
|
296
|
+
findToken = (value, depth = 0) => {
|
|
297
|
+
if (depth > 6 || value === null || typeof value !== "object") return void 0;
|
|
298
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
299
|
+
if (key === "user_auth_token" && typeof inner === "string" && inner.trim())
|
|
300
|
+
return inner.trim();
|
|
301
|
+
const nested = findToken(inner, depth + 1);
|
|
302
|
+
if (nested) return nested;
|
|
303
|
+
}
|
|
304
|
+
return void 0;
|
|
305
|
+
};
|
|
306
|
+
tokenFromStorage = (entries2) => {
|
|
307
|
+
for (const raw of Object.values(entries2)) {
|
|
308
|
+
if (!raw) continue;
|
|
309
|
+
try {
|
|
310
|
+
const token = findToken(JSON.parse(raw));
|
|
311
|
+
if (token) return { token, source: "localStorage" };
|
|
312
|
+
} catch {
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return void 0;
|
|
316
|
+
};
|
|
317
|
+
readLocalStorage = () => {
|
|
318
|
+
const out = {};
|
|
319
|
+
const storage = globalThis.localStorage;
|
|
320
|
+
for (let i = 0; i < storage.length; i++) {
|
|
321
|
+
const key = storage.key(i);
|
|
322
|
+
if (key !== null) out[key] = storage.getItem(key);
|
|
323
|
+
}
|
|
324
|
+
return out;
|
|
325
|
+
};
|
|
326
|
+
captureToken = ({
|
|
327
|
+
context,
|
|
328
|
+
page,
|
|
329
|
+
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
330
|
+
pollIntervalMs = 1e3,
|
|
331
|
+
signal
|
|
332
|
+
}) => new Promise((resolve, reject) => {
|
|
333
|
+
let settled = false;
|
|
334
|
+
let polling = false;
|
|
335
|
+
const finish = (outcome) => {
|
|
336
|
+
if (settled) return;
|
|
337
|
+
settled = true;
|
|
338
|
+
clearTimeout(timer);
|
|
339
|
+
clearInterval(poller);
|
|
340
|
+
context.off("request", onRequest);
|
|
341
|
+
signal?.removeEventListener("abort", onAbort);
|
|
342
|
+
outcome();
|
|
343
|
+
};
|
|
344
|
+
const onRequest = (request) => {
|
|
345
|
+
const captured = tokenFromHeaders(request.headers());
|
|
346
|
+
if (captured) finish(() => resolve(captured));
|
|
347
|
+
};
|
|
348
|
+
const poll = async () => {
|
|
349
|
+
if (settled || polling) return;
|
|
350
|
+
polling = true;
|
|
351
|
+
try {
|
|
352
|
+
const captured = tokenFromStorage(await page.evaluate(readLocalStorage));
|
|
353
|
+
if (captured) finish(() => resolve(captured));
|
|
354
|
+
} catch {
|
|
355
|
+
} finally {
|
|
356
|
+
polling = false;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const onAbort = () => finish(() => reject(signal?.reason ?? new Error("capture aborted")));
|
|
360
|
+
context.on("request", onRequest);
|
|
361
|
+
signal?.addEventListener("abort", onAbort);
|
|
362
|
+
const poller = setInterval(() => void poll(), pollIntervalMs);
|
|
363
|
+
const timer = setTimeout(
|
|
364
|
+
() => finish(() => reject(new CaptureTimeoutError(timeoutMs))),
|
|
365
|
+
timeoutMs
|
|
366
|
+
);
|
|
367
|
+
if (signal?.aborted) onAbort();
|
|
368
|
+
});
|
|
369
|
+
runBrowserCapture = async ({
|
|
370
|
+
timeoutMs,
|
|
371
|
+
importer
|
|
372
|
+
} = {}) => {
|
|
373
|
+
const playwright = await loadPlaywright(importer);
|
|
374
|
+
const browser = await playwright.chromium.launch({ headless: false });
|
|
375
|
+
try {
|
|
376
|
+
const context = await browser.newContext();
|
|
377
|
+
const page = await context.newPage();
|
|
378
|
+
const abort = new AbortController();
|
|
379
|
+
const capture = captureToken({
|
|
380
|
+
context,
|
|
381
|
+
page,
|
|
382
|
+
timeoutMs,
|
|
383
|
+
signal: abort.signal
|
|
384
|
+
});
|
|
385
|
+
capture.catch(() => {
|
|
386
|
+
});
|
|
387
|
+
browser.on?.(
|
|
388
|
+
"disconnected",
|
|
389
|
+
() => abort.abort(
|
|
390
|
+
new Error(
|
|
391
|
+
"The browser was closed before sign-in completed.\n Run `qobuz login --browser` again, or `qobuz login` to paste the token."
|
|
392
|
+
)
|
|
393
|
+
)
|
|
394
|
+
);
|
|
395
|
+
try {
|
|
396
|
+
await page.goto(LOGIN_URL);
|
|
397
|
+
} catch (error) {
|
|
398
|
+
abort.abort(error);
|
|
399
|
+
throw error;
|
|
400
|
+
}
|
|
401
|
+
return await capture;
|
|
402
|
+
} finally {
|
|
403
|
+
await browser.close().catch(() => {
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
225
410
|
// src/tui/lib/context.tsx
|
|
226
411
|
import { createContext, useContext } from "react";
|
|
227
412
|
var ClientContext, useClient, NavContext, useNav, InputFocusContext, useInputFocus;
|
|
@@ -1569,7 +1754,40 @@ import { defineCommand as defineCommand5 } from "citty";
|
|
|
1569
1754
|
// src/connect.ts
|
|
1570
1755
|
init_lib();
|
|
1571
1756
|
init_prompts();
|
|
1572
|
-
import {
|
|
1757
|
+
import { connect as connect2, fetchAppId } from "@kud/qobuz";
|
|
1758
|
+
var scrapeAppId = () => fetchAppId().then((result) => result.appId).catch(() => "");
|
|
1759
|
+
var validateAndSave = async ({
|
|
1760
|
+
appId,
|
|
1761
|
+
token
|
|
1762
|
+
}) => {
|
|
1763
|
+
let saved = false;
|
|
1764
|
+
const recordingStore = {
|
|
1765
|
+
load: () => store.load(),
|
|
1766
|
+
clear: () => store.clear(),
|
|
1767
|
+
save: async (credentials) => {
|
|
1768
|
+
await store.save(credentials);
|
|
1769
|
+
saved = true;
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
process.stdout.write("\n Validating\u2026 ");
|
|
1773
|
+
try {
|
|
1774
|
+
await connect2({ token, appId, store: recordingStore });
|
|
1775
|
+
} catch (error) {
|
|
1776
|
+
const reason = error.message;
|
|
1777
|
+
if (!saved) {
|
|
1778
|
+
console.error(`
|
|
1779
|
+
\u2717 ${reason}`);
|
|
1780
|
+
process.exit(1);
|
|
1781
|
+
}
|
|
1782
|
+
console.log('\u2713 saved to the Keychain (service "qobuz").');
|
|
1783
|
+
console.warn(
|
|
1784
|
+
`\u26A0 Connecting with the saved session failed: ${reason}
|
|
1785
|
+
Try a command such as \`qobuz search <query>\`; if it fails the same way, run \`qobuz login\` again.`
|
|
1786
|
+
);
|
|
1787
|
+
return;
|
|
1788
|
+
}
|
|
1789
|
+
console.log('\u2713 connected. Session saved to the Keychain (service "qobuz").');
|
|
1790
|
+
};
|
|
1573
1791
|
var runConnect = async () => {
|
|
1574
1792
|
console.log("Connect your Qobuz account.");
|
|
1575
1793
|
console.log(
|
|
@@ -1578,7 +1796,7 @@ var runConnect = async () => {
|
|
|
1578
1796
|
console.log(
|
|
1579
1797
|
"request to www.qobuz.com/api.json and copy these from its headers:\n"
|
|
1580
1798
|
);
|
|
1581
|
-
const scraped = await
|
|
1799
|
+
const scraped = await scrapeAppId();
|
|
1582
1800
|
await countdownAndOpen("https://play.qobuz.com/login");
|
|
1583
1801
|
const prompts = createPrompts();
|
|
1584
1802
|
const appIdInput = await prompts.ask(
|
|
@@ -1591,16 +1809,30 @@ var runConnect = async () => {
|
|
|
1591
1809
|
console.error("\nBoth X-App-Id and X-User-Auth-Token are required.");
|
|
1592
1810
|
process.exit(1);
|
|
1593
1811
|
}
|
|
1594
|
-
|
|
1812
|
+
await validateAndSave({ appId, token });
|
|
1813
|
+
};
|
|
1814
|
+
var runBrowserConnect = async () => {
|
|
1815
|
+
const { runBrowserCapture: runBrowserCapture2 } = await Promise.resolve().then(() => (init_browser_login(), browser_login_exports));
|
|
1816
|
+
console.log("Connect your Qobuz account in a browser window.");
|
|
1817
|
+
console.log(
|
|
1818
|
+
"Sign in as usual; the CLI only reads the session token once you are in.\n"
|
|
1819
|
+
);
|
|
1820
|
+
let captured;
|
|
1595
1821
|
try {
|
|
1596
|
-
await
|
|
1822
|
+
captured = await runBrowserCapture2();
|
|
1597
1823
|
} catch (error) {
|
|
1598
|
-
console.error(`
|
|
1599
|
-
\u2717 ${error.message}`);
|
|
1824
|
+
console.error(`\u2717 ${error.message}`);
|
|
1600
1825
|
process.exit(1);
|
|
1601
1826
|
}
|
|
1602
|
-
|
|
1603
|
-
|
|
1827
|
+
console.log(` Session token captured (from ${captured.source}).`);
|
|
1828
|
+
const appId = captured.appId || await scrapeAppId();
|
|
1829
|
+
if (!appId) {
|
|
1830
|
+
console.error(
|
|
1831
|
+
"\n\u2717 Could not determine X-App-Id. Run `qobuz login` to enter it manually."
|
|
1832
|
+
);
|
|
1833
|
+
process.exit(1);
|
|
1834
|
+
}
|
|
1835
|
+
await validateAndSave({ appId, token: captured.token });
|
|
1604
1836
|
};
|
|
1605
1837
|
|
|
1606
1838
|
// src/commands/login.ts
|
|
@@ -1609,7 +1841,14 @@ var login = defineCommand5({
|
|
|
1609
1841
|
name: "login",
|
|
1610
1842
|
description: "Connect your Qobuz account (stores a token in the Keychain)"
|
|
1611
1843
|
},
|
|
1612
|
-
|
|
1844
|
+
args: {
|
|
1845
|
+
browser: {
|
|
1846
|
+
type: "boolean",
|
|
1847
|
+
description: "Sign in through a real browser window and capture the token automatically (needs Playwright)",
|
|
1848
|
+
default: false
|
|
1849
|
+
}
|
|
1850
|
+
},
|
|
1851
|
+
run: ({ args: args2 }) => args2.browser ? runBrowserConnect() : runConnect()
|
|
1613
1852
|
});
|
|
1614
1853
|
|
|
1615
1854
|
// src/commands/logout.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kud/qobuz-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/kud/qobuz-cli.git"
|
|
10
10
|
},
|
|
11
|
+
"homepage": "https://kud.io/projects/qobuz-cli",
|
|
11
12
|
"bin": {
|
|
12
13
|
"qobuz": "./dist/index.js"
|
|
13
14
|
},
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"node": ">=20"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@kud/qobuz": "0.
|
|
29
|
+
"@kud/qobuz": "^0.6.0",
|
|
29
30
|
"citty": "0.2.2",
|
|
30
31
|
"ink": "7.1.0",
|
|
31
32
|
"ink-text-input": "6.0.0",
|
|
@@ -34,6 +35,14 @@
|
|
|
34
35
|
"optionalDependencies": {
|
|
35
36
|
"@kud/macos-media-keys": "0.1.0"
|
|
36
37
|
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"playwright": ">=1.40.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"playwright": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
37
46
|
"devDependencies": {
|
|
38
47
|
"@types/node": "26.0.0",
|
|
39
48
|
"@types/react": "19.2.17",
|