plx-converter 0.1.3 → 0.1.4

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
@@ -66,13 +66,24 @@ dozen-odd cookies, so copy the entire `cookie:` value: on [music.youtube.com](ht
66
66
  DevTools → **Network** → any request → **Request Headers** → `cookie:`. Google sessions also expire
67
67
  faster than the other two, so expect to redo this occasionally.
68
68
 
69
- ### Auto-fetch from your browser (macOS)
69
+ ### Auto-fetch from your browser
70
70
 
71
- Rather than copying cookies by hand, plx can read them straight from a logged-in browser — you only
72
- accept the macOS Keychain prompt. Pick **"Auto-fetch credentials (from browser)"** from the menu, or
73
- let it run automatically when a credential is missing. Works with the Chromium family (Brave, Chrome,
74
- Edge, Chromium, Vivaldi, Opera) and Safari (needs Full Disk Access). Manual paste stays the fallback
75
- everywhere else.
71
+ Rather than copying cookies by hand, plx can read them straight from a logged-in browser. Pick
72
+ **"Auto-fetch credentials (from browser)"** from the menu, or let it run automatically when a
73
+ credential is missing. Manual paste stays the fallback everywhere.
74
+
75
+ | Browser | macOS | Windows | Linux |
76
+ |---|---|---|---|
77
+ | Firefox | ✅ | ✅ | ✅ |
78
+ | Chromium family (Brave, Chrome, Edge, Chromium, Vivaldi, Opera) | ✅ | — | — |
79
+ | Safari | ✅ — needs Full Disk Access | — | — |
80
+
81
+ On macOS the Chromium and Safari backends ask you to accept the Keychain prompt once. Firefox needs
82
+ no prompt on any OS, since it stores cookie values unencrypted.
83
+
84
+ Chromium on Windows isn't a gap waiting to be filled: since Chrome 127 the cookie key is sealed
85
+ behind App-Bound Encryption that only a SYSTEM-level process can unwrap, and every published
86
+ workaround is the sort of thing malware does. On Windows, use Firefox or paste manually.
76
87
 
77
88
  Set credentials in `.env`, export them in your shell, or paste when prompted. Full setup:
78
89
  [`docs/CONFIG.md`](docs/CONFIG.md).
package/dist/browser.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createDecipheriv, pbkdf2Sync } from 'node:crypto';
2
2
  import { execFileSync } from 'node:child_process';
3
- import { existsSync, readFileSync } from 'node:fs';
4
- import { homedir, platform } from 'node:os';
3
+ import { copyFileSync, existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
4
+ import { homedir, platform, tmpdir } from 'node:os';
5
5
  import { join } from 'node:path';
6
6
  import { DatabaseSync } from 'node:sqlite';
7
7
  import { YTMUSIC_COOKIES, cookieHeader } from './ytmusic.js';
@@ -156,17 +156,77 @@ function readSafari() {
156
156
  }
157
157
  return {};
158
158
  }
159
+ // Firefox — the one backend that is not macOS-only. `cookies.sqlite` stores values in **plaintext**:
160
+ // no keychain, no DPAPI, and none of the App-Bound Encryption that closed the Chromium family off on
161
+ // Windows (Chrome 127+ wraps the cookie key in SYSTEM-DPAPI, so only a SYSTEM process can unwrap it,
162
+ // and every published bypass is malware behaviour). `key4.db` is commonly assumed to encrypt these
163
+ // too — it does not; it protects saved *logins*.
164
+ const FIREFOX_ROOTS = {
165
+ win32: join(process.env.APPDATA ?? join(homedir(), 'AppData', 'Roaming'), 'Mozilla', 'Firefox'),
166
+ darwin: join(homedir(), 'Library', 'Application Support', 'Firefox'),
167
+ linux: join(homedir(), '.mozilla', 'firefox'),
168
+ };
169
+ // Every profile holding a cookie DB, most-recently-written first. `profiles.ini` names the default
170
+ // one, but reading it needs an INI parser to answer worse than an mtime sort already does: someone
171
+ // with several profiles is logged in on the one they actually use, which is the one just written to.
172
+ export function firefoxProfiles(root = FIREFOX_ROOTS[platform()] ?? FIREFOX_ROOTS.linux) {
173
+ const nested = join(root, 'Profiles');
174
+ const base = existsSync(nested) ? nested : root; // some Linux packagings drop the Profiles/ level
175
+ try {
176
+ return readdirSync(base, { withFileTypes: true })
177
+ .filter((entry) => entry.isDirectory())
178
+ .map((entry) => join(base, entry.name, 'cookies.sqlite'))
179
+ .filter(existsSync)
180
+ .sort((a, b) => statSync(b).mtimeMs - statSync(a).mtimeMs);
181
+ }
182
+ catch {
183
+ return []; // no Firefox installed, or an unreadable profile root
184
+ }
185
+ }
186
+ // Firefox keeps the DB in WAL mode and holds it open while running — on Windows that lock is
187
+ // enforced, so reading the file in place fails outright. Copy it to a temp dir and read the copy.
188
+ // The `-wal` sidecar comes along because a cookie set this session may not be checkpointed into the
189
+ // main file yet, and the copy is opened writable precisely so SQLite is allowed to replay it.
190
+ export function readFirefox(dbPath) {
191
+ let dir = null;
192
+ try {
193
+ dir = mkdtempSync(join(tmpdir(), 'plx-ff-'));
194
+ const copy = join(dir, 'cookies.sqlite');
195
+ copyFileSync(dbPath, copy);
196
+ if (existsSync(`${dbPath}-wal`))
197
+ copyFileSync(`${dbPath}-wal`, `${copy}-wal`);
198
+ const db = new DatabaseSync(copy);
199
+ try {
200
+ const query = `SELECT name, host, value FROM moz_cookies WHERE name IN (${COOKIE_NAMES.map(() => '?').join(',')})`;
201
+ // `host` is stored dot-prefixed for domain cookies (`.youtube.com`); hostRank's endsWith arm
202
+ // already accepts that, so it is passed through as-is.
203
+ return collect(db.prepare(query).all(...COOKIE_NAMES));
204
+ }
205
+ finally {
206
+ db.close();
207
+ }
208
+ }
209
+ catch {
210
+ return {}; // unreadable profile / changed schema — skip it
211
+ }
212
+ finally {
213
+ if (dir)
214
+ rmSync(dir, { recursive: true, force: true });
215
+ }
216
+ }
159
217
  // Auto-retrieve credentials from the first logged-in browser that has them, keyed by provider —
160
218
  // the parsers above speak in cookie names, and this is where that becomes one opaque string per
161
219
  // provider for the config layer to store. Never throws: a missing browser, locked DB, denied
162
220
  // keychain, or TCC block just yields {}. Manual paste stays the fallback.
163
221
  export function fetchBrowserCredentials() {
164
- if (platform() !== 'darwin')
165
- return {};
222
+ // The keychain-backed backends stay gated on macOS; Firefox runs everywhere and is all that
223
+ // Windows and Linux get. macOS keeps its original order, so nothing changes for anyone who
224
+ // already relied on this — Firefox only fills what the others left empty.
225
+ const keychainBacked = platform() === 'darwin' ? [...CHROMIUM_BROWSERS.map(readChromium), readSafari()] : [];
166
226
  const credentials = {};
167
227
  // Every backend is read rather than stopping at the first: a user may be logged into Deezer in one
168
228
  // browser and YouTube Music in another.
169
- for (const found of [...CHROMIUM_BROWSERS.map(readChromium), readSafari()]) {
229
+ for (const found of [...keychainBacked, ...firefoxProfiles().map(readFirefox)]) {
170
230
  if (!credentials.deezer && found.arl)
171
231
  credentials.deezer = found.arl;
172
232
  if (!credentials.spotify && found.sp_dc)
package/dist/config.js CHANGED
@@ -10,10 +10,15 @@ const ENV_VAR = { deezer: 'DEEZER_ARL', spotify: 'SPOTIFY_DC', ytmusic: 'YTMUSIC
10
10
  // migrated (see #1): they are ignored, dropped on the next write, and the user re-fetches or
11
11
  // re-pastes — which costs one browser dialog.
12
12
  const LEGACY_KEYS = ['deezerArl', 'spotifyDc'];
13
+ // XDG_CONFIG_HOME wins on every platform, Windows included: it is the explicit override, and a
14
+ // Windows-only branch that ignored it left the tests sharing one real %APPDATA% dir instead of a
15
+ // temp dir each, so state leaked between them.
13
16
  export function configDir() {
17
+ if (process.env.XDG_CONFIG_HOME)
18
+ return join(process.env.XDG_CONFIG_HOME, 'plx');
14
19
  if (platform() === 'win32')
15
20
  return join(process.env.APPDATA ?? join(homedir(), 'AppData', 'Roaming'), 'plx');
16
- return join(process.env.XDG_CONFIG_HOME ?? join(homedir(), '.config'), 'plx');
21
+ return join(homedir(), '.config', 'plx');
17
22
  }
18
23
  const file = () => join(configDir(), 'credentials.json');
19
24
  async function loadStored() { try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plx-converter",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Convert playlists between Spotify, Deezer, and YouTube Music using your own browser session",
5
5
  "license": "MIT",
6
6
  "repository": {