plx-converter 0.1.4 → 0.1.5
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/browser.js +15 -0
- package/dist/cli.js +58 -21
- package/dist/config.js +7 -5
- package/dist/registry.js +3 -0
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -243,3 +243,18 @@ export function fetchBrowserCredentials() {
|
|
|
243
243
|
}
|
|
244
244
|
return credentials;
|
|
245
245
|
}
|
|
246
|
+
// Why auto-fetch came back empty, said in the terms of the platform the user is actually on. macOS
|
|
247
|
+
// is the only place a denied Keychain prompt can be the answer; everywhere else Firefox is the only
|
|
248
|
+
// backend, so the useful thing to report is which half of that is missing. This says *why* only —
|
|
249
|
+
// the caller owns pointing at the manual paste, so that instruction lives in one place. Both inputs
|
|
250
|
+
// are injected so the branches are testable without a browser or a second OS.
|
|
251
|
+
export function autoFetchHint(os = platform(), firefoxFound = firefoxProfiles().length > 0) {
|
|
252
|
+
if (os === 'darwin')
|
|
253
|
+
return 'No browser was logged in, or the macOS Keychain prompt was denied.';
|
|
254
|
+
if (firefoxFound)
|
|
255
|
+
return 'A Firefox profile was found but held none of the cookies — log in at the provider in Firefox and retry.';
|
|
256
|
+
const why = os === 'win32'
|
|
257
|
+
? 'Chrome/Edge cookies are sealed by App-Bound Encryption that only a SYSTEM process can unwrap'
|
|
258
|
+
: 'the Chromium keyring backends are not implemented here';
|
|
259
|
+
return `Auto-fetch supports Firefox only on this OS and no Firefox profile was found — ${why}.`;
|
|
260
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -1,36 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { confirm, intro, isCancel, outro, password, select, text } from '@clack/prompts';
|
|
3
|
+
import { autoFetchHint } from './browser.js';
|
|
3
4
|
import { credential, loadConfig, saveCredential, saveRecentUrl, tryAutoFillCredentials } from './config.js';
|
|
4
5
|
import { Conversion } from './conversion.js';
|
|
5
6
|
import { PROVIDERS, inferSource, providerFor, targetKeys } from './registry.js';
|
|
6
7
|
import { HELP_TEXT, parseArgs } from './args.js';
|
|
7
8
|
function args() { return process.argv.slice(2); }
|
|
8
9
|
// --- Credentials -----------------------------------------------------------
|
|
9
|
-
//
|
|
10
|
-
//
|
|
10
|
+
// Why the browser read came back with nothing for this provider, and what to do instead. Every
|
|
11
|
+
// auto-fetch failure says this, so the user never sees a bare "could not be fetched".
|
|
12
|
+
function explainAutoFetchFailure(spec) {
|
|
13
|
+
const what = spec ? `${spec.label} cookies` : 'No credentials';
|
|
14
|
+
console.log(`✗ ${what} could not be read from your browser. ${autoFetchHint()}`);
|
|
15
|
+
}
|
|
16
|
+
// One manual paste, with where to find the value and what a correct one looks like.
|
|
17
|
+
async function promptCredential(cfg, spec) {
|
|
18
|
+
console.log(`ℹ️ Where to find it: ${spec.credentialHint}`);
|
|
19
|
+
console.log(` Looks like: ${spec.credentialExample}`);
|
|
20
|
+
const entered = await password({ message: `Paste ${spec.credentialLabel}` });
|
|
21
|
+
if (isCancel(entered) || !entered)
|
|
22
|
+
return false;
|
|
23
|
+
await saveCredential(cfg, spec.key, String(entered).trim()); // pasted values carry stray whitespace
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
// Fill one provider's credential mid-conversion: browser auto-fill first, then a manual paste.
|
|
27
|
+
// Persists what it gets. Returns the credential, or null when the user cancels.
|
|
11
28
|
async function ensureCredential(cfg, spec) {
|
|
12
29
|
if (credential(cfg, spec.key))
|
|
13
30
|
return credential(cfg, spec.key);
|
|
14
31
|
const filled = await tryAutoFillCredentials(cfg);
|
|
15
32
|
if (filled.includes(spec.key))
|
|
16
33
|
return credential(cfg, spec.key);
|
|
17
|
-
|
|
18
|
-
if (
|
|
34
|
+
explainAutoFetchFailure(spec);
|
|
35
|
+
if (!(await promptCredential(cfg, spec)))
|
|
19
36
|
return null;
|
|
20
|
-
await saveCredential(cfg, spec.key, String(entered));
|
|
21
37
|
return credential(cfg, spec.key);
|
|
22
38
|
}
|
|
23
|
-
// Settings entry for one provider's credential
|
|
24
|
-
//
|
|
39
|
+
// Settings entry for one provider's credential. The two ways in are offered as a choice rather than
|
|
40
|
+
// auto-first-then-manual, so someone who knows the browser read will fail (or who wants to replace a
|
|
41
|
+
// saved-but-expired value with a cookie of their own) can go straight to the paste. Auto-fetch here
|
|
42
|
+
// overwrites, scoped to this provider, so an expired credential is actually replaced.
|
|
43
|
+
// Proves whatever lands against the live service before saying it worked.
|
|
25
44
|
async function reenterCredential(cfg, spec) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
const how = await select({
|
|
46
|
+
message: `${spec.credentialLabel}`,
|
|
47
|
+
options: [
|
|
48
|
+
{ value: 'auto', label: 'Auto-fetch from browser' },
|
|
49
|
+
{ value: 'manual', label: 'Paste cookies manually' },
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
if (isCancel(how))
|
|
53
|
+
return;
|
|
54
|
+
if (how === 'auto') {
|
|
55
|
+
warnLogin(spec.loginSite);
|
|
56
|
+
if ((await tryAutoFillCredentials(cfg, true, spec.key)).includes(spec.key)) {
|
|
57
|
+
await report(cfg, spec);
|
|
31
58
|
return;
|
|
32
|
-
|
|
59
|
+
}
|
|
60
|
+
explainAutoFetchFailure(spec);
|
|
61
|
+
console.log(' Paste it manually instead:');
|
|
33
62
|
}
|
|
63
|
+
if (!(await promptCredential(cfg, spec)))
|
|
64
|
+
return;
|
|
34
65
|
await report(cfg, spec);
|
|
35
66
|
}
|
|
36
67
|
// Check one provider's stored credential against the live service and say what happened.
|
|
@@ -241,16 +272,22 @@ async function runInteractive(options) {
|
|
|
241
272
|
if (choice === 'autofetch') {
|
|
242
273
|
warnLogin(PROVIDERS.map((p) => p.label).join(' & '));
|
|
243
274
|
const filled = await tryAutoFillCredentials(cfg, true);
|
|
244
|
-
if (
|
|
245
|
-
console.log(
|
|
246
|
-
|
|
275
|
+
if (filled.length) {
|
|
276
|
+
console.log(`Fetched from browser: ${filled.join(', ')}. Checking…`);
|
|
277
|
+
for (const key of filled) {
|
|
278
|
+
const spec = providerFor(key);
|
|
279
|
+
if (spec)
|
|
280
|
+
await report(cfg, spec);
|
|
281
|
+
}
|
|
247
282
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
const spec = providerFor(key);
|
|
251
|
-
if (spec)
|
|
252
|
-
await report(cfg, spec);
|
|
283
|
+
else {
|
|
284
|
+
explainAutoFetchFailure();
|
|
253
285
|
}
|
|
286
|
+
// Whatever auto-fetch managed, the manual path is what closes the gap — name it and the menu
|
|
287
|
+
// entry that leads to it, rather than leaving the user at a dead end.
|
|
288
|
+
const missing = PROVIDERS.filter((p) => !credential(cfg, p.key));
|
|
289
|
+
if (missing.length)
|
|
290
|
+
console.log(`→ Still missing: ${missing.map((p) => p.label).join(', ')}. Add them from "Credentials: ${saved}/${PROVIDERS.length} saved" → pick the provider → "Paste cookies manually".`);
|
|
254
291
|
continue;
|
|
255
292
|
}
|
|
256
293
|
if (choice === 'output') {
|
package/dist/config.js
CHANGED
|
@@ -63,14 +63,16 @@ async function write(patch) {
|
|
|
63
63
|
// Semi-auto: fill credentials from a logged-in browser (pops the macOS Keychain "Allow" dialog on
|
|
64
64
|
// first use), persist what's found, and return the provider names filled. By default only fills
|
|
65
65
|
// providers with no credential yet (env vars and stored credentials win); pass overwrite=true to
|
|
66
|
-
// refetch and replace
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
// refetch and replace, and `only` to confine that to one provider — the Credentials menu refetches
|
|
67
|
+
// the provider being edited without quietly replacing the other two. Never throws — a denied
|
|
68
|
+
// keychain / TCC block just fills nothing, and the caller falls back to the manual paste prompt.
|
|
69
|
+
export async function tryAutoFillCredentials(cfg, overwrite = false, only) {
|
|
70
|
+
const wanted = only ? [only] : Object.keys(ENV_VAR);
|
|
71
|
+
if (!overwrite && wanted.every((provider) => cfg.credentials[provider]))
|
|
70
72
|
return [];
|
|
71
73
|
const filled = [];
|
|
72
74
|
for (const [provider, value] of Object.entries(fetchBrowserCredentials())) {
|
|
73
|
-
if (!value || (!overwrite && cfg.credentials[provider]))
|
|
75
|
+
if (!value || !wanted.includes(provider) || (!overwrite && cfg.credentials[provider]))
|
|
74
76
|
continue;
|
|
75
77
|
cfg.credentials[provider] = value;
|
|
76
78
|
filled.push(provider);
|
package/dist/registry.js
CHANGED
|
@@ -8,6 +8,7 @@ const spotify = {
|
|
|
8
8
|
matches: ['open.spotify.com', 'spotify:playlist:'],
|
|
9
9
|
credentialLabel: 'Spotify sp_dc',
|
|
10
10
|
credentialHint: 'login open.spotify.com → F12 → Application → Cookies → sp_dc → copy value',
|
|
11
|
+
credentialExample: 'AQBv7pC3...9Kk (the value only, ~150 chars, no "sp_dc=" prefix)',
|
|
11
12
|
loginSite: 'Spotify (open.spotify.com)',
|
|
12
13
|
anonymousRead: true,
|
|
13
14
|
parseRef: async (ref) => parsePlaylistId(ref),
|
|
@@ -23,6 +24,7 @@ const deezer = {
|
|
|
23
24
|
matches: ['deezer.com', 'link.deezer.com'],
|
|
24
25
|
credentialLabel: 'Deezer ARL',
|
|
25
26
|
credentialHint: 'login deezer.com → F12 → Application → Cookies → arl → copy value',
|
|
27
|
+
credentialExample: '3f9a1c...e7b2 (the value only, 192 hex chars, no "arl=" prefix)',
|
|
26
28
|
loginSite: 'Deezer (deezer.com)',
|
|
27
29
|
// Deezer's search is public, but reading a *playlist* goes through the authenticated GraphQL API.
|
|
28
30
|
anonymousRead: false,
|
|
@@ -45,6 +47,7 @@ const ytmusic = {
|
|
|
45
47
|
matches: ['music.youtube.com', 'youtube.com'],
|
|
46
48
|
credentialLabel: 'YouTube Music cookies',
|
|
47
49
|
credentialHint: 'login music.youtube.com → F12 → Network → any request → Request Headers → copy the whole "cookie:" value',
|
|
50
|
+
credentialExample: 'SAPISID=xxx; __Secure-3PAPISID=xxx; SID=xxx; __Secure-3PSID=xxx; __Secure-3PSIDTS=xxx; HSID=xxx; SSID=xxx; APISID=xxx (one line, every cookie, SAPISID is required)',
|
|
48
51
|
loginSite: 'YouTube Music (music.youtube.com)',
|
|
49
52
|
anonymousRead: false,
|
|
50
53
|
parseRef: async (ref) => parsePlaylistRef(ref),
|