@trippnology/mixshell 0.0.0-stage → 0.7.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 +294 -2
- package/assets/mixshell-screenshot.png +0 -0
- package/package.json +73 -5
- package/src/alsa-pulse.conf +20 -0
- package/src/alsa-setup.js +15 -0
- package/src/components/browser.js +193 -0
- package/src/components/config.js +168 -0
- package/src/components/durations.js +151 -0
- package/src/components/library.js +679 -0
- package/src/components/mediakeys.js +222 -0
- package/src/components/mpris.js +309 -0
- package/src/components/player.js +412 -0
- package/src/components/playlist.js +335 -0
- package/src/components/session.js +96 -0
- package/src/constants.js +164 -0
- package/src/engines/ffmpeg.js +601 -0
- package/src/engines/index.js +14 -0
- package/src/engines/webaudio.js +317 -0
- package/src/index.js +188 -0
- package/src/mediakeys/macos-nowplaying.js +227 -0
- package/src/ui/app.js +56 -0
- package/src/ui/artPane.js +314 -0
- package/src/ui/confirmPrompt.js +34 -0
- package/src/ui/constants.js +133 -0
- package/src/ui/controller.js +1641 -0
- package/src/ui/dom.js +9 -0
- package/src/ui/goToPrompt.js +105 -0
- package/src/ui/index.html +78 -0
- package/src/ui/libraryPanel.js +415 -0
- package/src/ui/listView.js +209 -0
- package/src/ui/onboarding.js +353 -0
- package/src/ui/playlistPanel.js +207 -0
- package/src/ui/settingsPanel.js +473 -0
- package/src/ui/shortcuts.js +30 -0
- package/src/ui/splash.js +302 -0
- package/src/ui/style.css +532 -0
- package/src/ui/subtabs.js +31 -0
- package/src/ui/visualizer/bars.js +74 -0
- package/src/ui/visualizer/circles.js +64 -0
- package/src/ui/visualizer/color.js +61 -0
- package/src/ui/visualizer/cube.js +105 -0
- package/src/ui/visualizer/grid.js +68 -0
- package/src/ui/visualizer/index.js +65 -0
- package/src/ui/visualizer/onset.js +130 -0
- package/src/ui/visualizer/spectrum.js +34 -0
- package/src/ui/visualizer/vu.js +71 -0
- package/src/ui/visualizer/waveform.js +58 -0
- package/src/utils/audioAnalyzer.js +362 -0
- package/src/utils/audioDevices.js +222 -0
- package/src/utils/cellart.js +75 -0
- package/src/utils/debug.js +7 -0
- package/src/utils/durationProbe.js +48 -0
- package/src/utils/folderArt.js +46 -0
- package/src/utils/format.js +20 -0
- package/src/utils/id3.js +84 -0
- package/src/utils/pathInput.js +76 -0
- package/src/utils/playlistIO.js +176 -0
- package/src/utils/terminalGraphics.js +47 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
|
|
4
|
+
import ffmpeg from '@ffmpeg-installer/ffmpeg';
|
|
5
|
+
|
|
6
|
+
// Duration prober (issues/046). The project ships the ffmpeg static
|
|
7
|
+
// binary (no ffprobe), but `ffmpeg -i <file>` prints the input header —
|
|
8
|
+
// including the `Duration:` line — to stderr before failing on the
|
|
9
|
+
// missing output file, which is exactly a header-length read. Never
|
|
10
|
+
// decodes: the process exits as soon as the header is printed.
|
|
11
|
+
|
|
12
|
+
const PROBE_TIMEOUT_MS = 10000;
|
|
13
|
+
|
|
14
|
+
// `Duration: 00:03:05.12`, the only stable marker in the banner. Locale
|
|
15
|
+
// independent (digits, not words).
|
|
16
|
+
const DURATION_LINE = /Duration:\s*(\d+):(\d{2}):(\d{2}(?:\.\d+)?)/;
|
|
17
|
+
|
|
18
|
+
const execFileP = promisify(execFile);
|
|
19
|
+
const defaultRun = (cmd, args) =>
|
|
20
|
+
execFileP(cmd, args, { timeout: PROBE_TIMEOUT_MS });
|
|
21
|
+
|
|
22
|
+
// stderr text → seconds, or null when no usable Duration line. Exported
|
|
23
|
+
// for tests.
|
|
24
|
+
export function parseFfmpegDuration(stderr) {
|
|
25
|
+
const match = String(stderr ?? '').match(DURATION_LINE);
|
|
26
|
+
if (!match) return null;
|
|
27
|
+
const seconds =
|
|
28
|
+
Number(match[1]) * 3600 + Number(match[2]) * 60 + Number(match[3]);
|
|
29
|
+
return seconds > 0 ? seconds : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// One file → duration in seconds, or null (unreadable / no header).
|
|
33
|
+
// Never throws; `run` is injectable for tests (same contract as
|
|
34
|
+
// audioDevices.js probeDevice: resolves or rejects with `{ stderr }`).
|
|
35
|
+
// `-nostdin` is load-bearing (engines/ffmpeg.js precedent): without it
|
|
36
|
+
// ffmpeg consumes stdin and eats TUI keystrokes. No output file follows,
|
|
37
|
+
// so ffmpeg exits nonzero right after printing the header — the exec
|
|
38
|
+
// rejection is the expected path and carries the stderr we parse.
|
|
39
|
+
export async function probeDuration(filePath, { run = defaultRun } = {}) {
|
|
40
|
+
let stderr = '';
|
|
41
|
+
try {
|
|
42
|
+
const result = await run(ffmpeg.path, ['-nostdin', '-i', filePath]);
|
|
43
|
+
stderr = result?.stderr ?? '';
|
|
44
|
+
} catch (err) {
|
|
45
|
+
stderr = err?.stderr ?? '';
|
|
46
|
+
}
|
|
47
|
+
return parseFfmpegDuration(stderr);
|
|
48
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { DBG } from './debug.js';
|
|
4
|
+
|
|
5
|
+
// Folder-art fallback (display only): when a track carries no embedded
|
|
6
|
+
// picture, the art pane can use the album art file sitting next to the
|
|
7
|
+
// audio files (Kodi/foobar2000 convention). Lookup is one readdir pass,
|
|
8
|
+
// case-insensitive on the whole filename, priority = array order (cover
|
|
9
|
+
// before folder, jpg > jpeg > png). Results are cached per directory for
|
|
10
|
+
// the session — a miss is cached too, so a dir without art costs exactly
|
|
11
|
+
// one readdir.
|
|
12
|
+
|
|
13
|
+
const NAMES = [
|
|
14
|
+
'cover.jpg',
|
|
15
|
+
'cover.jpeg',
|
|
16
|
+
'cover.png',
|
|
17
|
+
'folder.jpg',
|
|
18
|
+
'folder.jpeg',
|
|
19
|
+
'folder.png',
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const cache = new Map(); // dir → { data: Buffer } | null
|
|
23
|
+
|
|
24
|
+
export async function findFolderArt(dir) {
|
|
25
|
+
if (cache.has(dir)) return cache.get(dir);
|
|
26
|
+
let result = null;
|
|
27
|
+
try {
|
|
28
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
29
|
+
let best = null;
|
|
30
|
+
for (const entry of entries) {
|
|
31
|
+
if (!entry.isFile()) continue;
|
|
32
|
+
const order = NAMES.indexOf(entry.name.toLowerCase());
|
|
33
|
+
if (order !== -1 && (best === null || order < best.order)) {
|
|
34
|
+
best = { order, name: entry.name };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (best) {
|
|
38
|
+
const data = await fs.promises.readFile(path.join(dir, best.name));
|
|
39
|
+
result = { data };
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
DBG(`folder art: ${dir}: ${error?.message ?? error}`);
|
|
43
|
+
}
|
|
44
|
+
cache.set(dir, result);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function formatTime(seconds) {
|
|
2
|
+
const mins = Math.floor(seconds / 60);
|
|
3
|
+
const secs = Math.floor(seconds % 60);
|
|
4
|
+
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Aggregate displays (issues/046 playlist totals): m:ss under an hour,
|
|
8
|
+
// h:mm:ss from an hour up — `12:43:11 total`, not `763:31`.
|
|
9
|
+
export function formatLongTime(seconds) {
|
|
10
|
+
const total = Math.max(0, Math.round(seconds));
|
|
11
|
+
const hours = Math.floor(total / 3600);
|
|
12
|
+
const mins = Math.floor((total % 3600) / 60);
|
|
13
|
+
const secs = total % 60;
|
|
14
|
+
if (hours > 0) {
|
|
15
|
+
return `${hours}:${mins.toString().padStart(2, '0')}:${secs
|
|
16
|
+
.toString()
|
|
17
|
+
.padStart(2, '0')}`;
|
|
18
|
+
}
|
|
19
|
+
return `${mins}:${secs.toString().padStart(2, '0')}`;
|
|
20
|
+
}
|
package/src/utils/id3.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseFile } from 'music-metadata';
|
|
4
|
+
import { DBG } from './debug.js';
|
|
5
|
+
|
|
6
|
+
// "03. Jstar - (Still) Passin' Me By.aiff" → track 03, artist Jstar, title "(Still) Passin' Me By".
|
|
7
|
+
function bootstrapFromFilename(filePath) {
|
|
8
|
+
const stem = path
|
|
9
|
+
.basename(filePath)
|
|
10
|
+
.replace(/\.[^.]*$/, '')
|
|
11
|
+
.trim();
|
|
12
|
+
let rest = stem;
|
|
13
|
+
let trackNumber = '';
|
|
14
|
+
// Requires a separator after leading digits so plain "99 Luftballons"
|
|
15
|
+
// keeps its number in the title.
|
|
16
|
+
const num = stem.match(/^(\d{1,3})\s*[.)-]\s*(.+)$/);
|
|
17
|
+
if (num) {
|
|
18
|
+
trackNumber = num[1];
|
|
19
|
+
rest = num[2];
|
|
20
|
+
}
|
|
21
|
+
const dash = rest.match(/^(.+?)\s+[-–—]\s+(.+)$/);
|
|
22
|
+
const artist = dash ? dash[1] : 'Unknown Artist';
|
|
23
|
+
const title = dash ? dash[2] : rest;
|
|
24
|
+
return { title, artist, trackNumber };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function fallbackMetadata(filePath) {
|
|
28
|
+
const boot = bootstrapFromFilename(filePath);
|
|
29
|
+
return {
|
|
30
|
+
title: boot.title || 'Unknown Title',
|
|
31
|
+
artist: boot.artist,
|
|
32
|
+
// Compilations group under the album artist; see readMetadata.
|
|
33
|
+
albumArtist: boot.artist,
|
|
34
|
+
album: 'Unknown Album',
|
|
35
|
+
year: '',
|
|
36
|
+
trackNumber: boot.trackNumber,
|
|
37
|
+
genre: '',
|
|
38
|
+
duration: 0,
|
|
39
|
+
images: null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function readMetadata(filePath) {
|
|
44
|
+
try {
|
|
45
|
+
// Check if the file exists and is accessible
|
|
46
|
+
await fs.promises.access(filePath, fs.constants.R_OK);
|
|
47
|
+
|
|
48
|
+
const metadata = await parseFile(filePath);
|
|
49
|
+
const common = metadata.common;
|
|
50
|
+
const format = metadata.format;
|
|
51
|
+
|
|
52
|
+
// Extract track number - supports both simple and object formats
|
|
53
|
+
let trackNumber = '';
|
|
54
|
+
if (common.track) {
|
|
55
|
+
if (typeof common.track === 'object') {
|
|
56
|
+
trackNumber = `${common.track.no || ''}${common.track.of ? `/${common.track.of}` : ''}`;
|
|
57
|
+
} else {
|
|
58
|
+
trackNumber = common.track.toString();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Clean up track number: remove extra whitespace
|
|
63
|
+
trackNumber = trackNumber.replace(/\s+/g, ' ').trim();
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
title: common.title || 'Unknown Title',
|
|
67
|
+
artist: common.artist || 'Unknown Artist',
|
|
68
|
+
// Compilations group under the album artist; fall back to track
|
|
69
|
+
// artist so a missing tag doesn't fragment albums.
|
|
70
|
+
albumArtist: common.albumartist || common.artist || 'Unknown Artist',
|
|
71
|
+
album: common.album || 'Unknown Album',
|
|
72
|
+
year: common.year || '',
|
|
73
|
+
trackNumber: trackNumber || '',
|
|
74
|
+
genre: Array.isArray(common.genre)
|
|
75
|
+
? common.genre.join(', ')
|
|
76
|
+
: common.genre || '',
|
|
77
|
+
duration: format.duration || 0, // Accurate duration from audio headers!
|
|
78
|
+
images: common.picture || null, // Keep music-metadata native format
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
DBG(`metadata error: ${filePath}: ${error?.message ?? error}`);
|
|
82
|
+
return fallbackMetadata(filePath);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
// One `~` rule for every path prompt: `~` and `~/…` mean the home dir.
|
|
6
|
+
// `home` is injectable for tests (DEVELOPMENT.md §Testing).
|
|
7
|
+
export function expandHome(input, { home = homedir() } = {}) {
|
|
8
|
+
const text = String(input ?? '').trim();
|
|
9
|
+
return text === '~'
|
|
10
|
+
? home
|
|
11
|
+
: text.startsWith('~/') || text.startsWith('~\\')
|
|
12
|
+
? path.join(home, text.slice(2))
|
|
13
|
+
: text;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Shared resolver for `-d` and the three "Go to" prompts. Returns an
|
|
17
|
+
// absolute path plus an optional rejection message; validation follows
|
|
18
|
+
// symlinks (statSync), which is what lets a linked music folder be chosen.
|
|
19
|
+
// `home`/`base` are injectable for tests (DEVELOPMENT.md §Testing).
|
|
20
|
+
export function resolveDirectoryInput(
|
|
21
|
+
input,
|
|
22
|
+
{ base = process.cwd(), home = homedir() } = {},
|
|
23
|
+
) {
|
|
24
|
+
const text = String(input ?? '').trim();
|
|
25
|
+
if (!text) return { path: '', error: 'Enter a directory' };
|
|
26
|
+
|
|
27
|
+
const resolved = path.resolve(base, expandHome(text, { home }));
|
|
28
|
+
|
|
29
|
+
let stat;
|
|
30
|
+
try {
|
|
31
|
+
stat = fs.statSync(resolved);
|
|
32
|
+
} catch {
|
|
33
|
+
return { path: resolved, error: `${text} does not exist` };
|
|
34
|
+
}
|
|
35
|
+
if (!stat.isDirectory())
|
|
36
|
+
return { path: resolved, error: `${text} is not a directory` };
|
|
37
|
+
try {
|
|
38
|
+
fs.accessSync(resolved, fs.constants.R_OK);
|
|
39
|
+
} catch {
|
|
40
|
+
return { path: resolved, error: `${text} is not readable` };
|
|
41
|
+
}
|
|
42
|
+
return { path: resolved };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Playlist save target (issues/057): same `~` and labelled-base rules as
|
|
46
|
+
// go-to, plus a typed extension is replaced with `format` (one appended
|
|
47
|
+
// when absent). Pure — `home`/`base` are injectable for tests.
|
|
48
|
+
export function resolveSavePath(
|
|
49
|
+
input,
|
|
50
|
+
{ format, base = process.cwd(), home = homedir() } = {},
|
|
51
|
+
) {
|
|
52
|
+
const expanded = expandHome(input, { home });
|
|
53
|
+
const ext = path.extname(expanded);
|
|
54
|
+
const target = ext
|
|
55
|
+
? `${expanded.slice(0, -ext.length)}.${format}`
|
|
56
|
+
: `${expanded}.${format}`;
|
|
57
|
+
return path.resolve(base, target);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Startup fallback (issues/054): nearest readable ancestor of an unusable
|
|
61
|
+
// directory, with home as the last candidate. Pure — `resolve`/`home` are
|
|
62
|
+
// injectable so the walk is testable without touching disk.
|
|
63
|
+
export function fallbackDirectory(
|
|
64
|
+
input,
|
|
65
|
+
{ home = homedir(), resolve = resolveDirectoryInput } = {},
|
|
66
|
+
) {
|
|
67
|
+
let candidate = String(input ?? '');
|
|
68
|
+
for (;;) {
|
|
69
|
+
const result = resolve(candidate, { home });
|
|
70
|
+
if (!result.error) return result.path;
|
|
71
|
+
const parent = path.dirname(candidate);
|
|
72
|
+
if (parent === candidate) break;
|
|
73
|
+
candidate = parent;
|
|
74
|
+
}
|
|
75
|
+
return home;
|
|
76
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// Playlist container I/O (issues/028): EXM3U and PLS v2 on both sides.
|
|
2
|
+
// Parsers emit raw entries ({path, ...}); callers funnel them through
|
|
3
|
+
// filterLoadable() so missing files and non-audio entries degrade to a
|
|
4
|
+
// skip count instead of a hard failure. `baseDir` (required) is the
|
|
5
|
+
// directory of the playlist file itself — relative entries resolve
|
|
6
|
+
// against it.
|
|
7
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
import { extensionOf, isAudioFile } from '../constants.js';
|
|
12
|
+
|
|
13
|
+
// Entry-point resolution shared by both parsers: `file://` URLs convert,
|
|
14
|
+
// absolute paths pass through, anything else lands relative to the
|
|
15
|
+
// playlist's own directory.
|
|
16
|
+
function resolveEntry(rawPath, baseDir) {
|
|
17
|
+
let candidate = rawPath.trim();
|
|
18
|
+
if (candidate.startsWith('file://')) {
|
|
19
|
+
try {
|
|
20
|
+
candidate = fileURLToPath(candidate);
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (path.isAbsolute(candidate)) return candidate;
|
|
26
|
+
return path.resolve(baseDir, candidate);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function parseM3u(text, { baseDir }) {
|
|
30
|
+
const lines = text.replace(/^\uFEFF/, '').split(/\r?\n/);
|
|
31
|
+
const entries = [];
|
|
32
|
+
for (const line of lines) {
|
|
33
|
+
const trimmed = line.trim();
|
|
34
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
35
|
+
const resolved = resolveEntry(trimmed, baseDir);
|
|
36
|
+
if (resolved) entries.push({ path: resolved });
|
|
37
|
+
}
|
|
38
|
+
return entries;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// PLS is INI-flavoured: File1=/Title1=/Length1= under [playlist]. Keys are
|
|
42
|
+
// matched case-insensitively (writers vary), NumberOfEntries is advisory
|
|
43
|
+
// (missing/lying tolerated), gaps in numbering are fine — order follows
|
|
44
|
+
// the numeric suffix.
|
|
45
|
+
export function parsePls(text, { baseDir }) {
|
|
46
|
+
const files = new Map();
|
|
47
|
+
const titles = new Map();
|
|
48
|
+
const lengths = new Map();
|
|
49
|
+
|
|
50
|
+
for (const line of text.replace(/^\uFEFF/, '').split(/\r?\n/)) {
|
|
51
|
+
const trimmed = line.trim();
|
|
52
|
+
if (!trimmed || trimmed.startsWith('[') || trimmed.startsWith(';')) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const eq = trimmed.indexOf('=');
|
|
56
|
+
if (eq === -1) continue;
|
|
57
|
+
const key = trimmed.slice(0, eq).trim();
|
|
58
|
+
const value = trimmed.slice(eq + 1).trim();
|
|
59
|
+
const match = key.match(/^(file|title|length)(\d+)$/i);
|
|
60
|
+
if (!match) continue;
|
|
61
|
+
const kind = match[1].toLowerCase();
|
|
62
|
+
const index = Number(match[2]);
|
|
63
|
+
if (kind === 'file') files.set(index, value);
|
|
64
|
+
else if (kind === 'title') titles.set(index, value);
|
|
65
|
+
else lengths.set(index, Number(value));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const entries = [];
|
|
69
|
+
for (const index of [...files.keys()].sort((a, b) => a - b)) {
|
|
70
|
+
const resolved = files.get(index)
|
|
71
|
+
? resolveEntry(files.get(index), baseDir)
|
|
72
|
+
: null;
|
|
73
|
+
if (!resolved) continue;
|
|
74
|
+
entries.push({
|
|
75
|
+
path: resolved,
|
|
76
|
+
title: titles.get(index) || '',
|
|
77
|
+
duration: Number.isFinite(lengths.get(index)) ? lengths.get(index) : -1,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return entries;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// External label for a track: the library index when scanned, filename
|
|
84
|
+
// bootstrap otherwise (sync, no I/O — issues/028).
|
|
85
|
+
function trackLabel(track, lookup) {
|
|
86
|
+
const row = lookup?.get(track.path);
|
|
87
|
+
if (row) {
|
|
88
|
+
const artist =
|
|
89
|
+
row.artist && row.artist !== 'Unknown Artist' ? row.artist : '';
|
|
90
|
+
if (artist && row.title) return `${artist} - ${row.title}`;
|
|
91
|
+
if (row.title) return row.title;
|
|
92
|
+
}
|
|
93
|
+
if (track.name) return track.name;
|
|
94
|
+
return path.basename(track.path);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function trackDuration(track, lookup) {
|
|
98
|
+
const row = lookup?.get(track.path);
|
|
99
|
+
const duration = row?.duration ?? -1;
|
|
100
|
+
return Number.isFinite(duration) && duration > 0 ? Math.round(duration) : -1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Relative when the track lives under baseDir (portable), absolute
|
|
104
|
+
// otherwise. The '..' guard keeps escapes out; cross-drive on Windows
|
|
105
|
+
// yields an absolute from path.relative, which also passes through.
|
|
106
|
+
function storedPath(trackPath, baseDir) {
|
|
107
|
+
if (!baseDir) return trackPath;
|
|
108
|
+
const relative = path.relative(baseDir, trackPath);
|
|
109
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
|
|
110
|
+
return trackPath;
|
|
111
|
+
}
|
|
112
|
+
return relative;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function serializeM3u(tracks, { baseDir, lookup } = {}) {
|
|
116
|
+
const lines = ['#EXTM3U'];
|
|
117
|
+
for (const track of tracks) {
|
|
118
|
+
lines.push(
|
|
119
|
+
`#EXTINF:${trackDuration(track, lookup)},${trackLabel(track, lookup)}`,
|
|
120
|
+
);
|
|
121
|
+
lines.push(storedPath(track.path, baseDir));
|
|
122
|
+
}
|
|
123
|
+
return `${lines.join('\n')}\n`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function serializePls(tracks, { baseDir, lookup } = {}) {
|
|
127
|
+
const lines = ['[playlist]'];
|
|
128
|
+
tracks.forEach((track, index) => {
|
|
129
|
+
const n = index + 1;
|
|
130
|
+
lines.push(`File${n}=${storedPath(track.path, baseDir)}`);
|
|
131
|
+
lines.push(`Title${n}=${trackLabel(track, lookup)}`);
|
|
132
|
+
lines.push(`Length${n}=${trackDuration(track, lookup)}`);
|
|
133
|
+
});
|
|
134
|
+
lines.push(`NumberOfEntries=${tracks.length}`);
|
|
135
|
+
lines.push('Version=2');
|
|
136
|
+
return `${lines.join('\n')}\n`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// One reader for the picker and -p: sniff by extension, return raw
|
|
140
|
+
// entries. Unknown extensions throw; missing files surface in
|
|
141
|
+
// filterLoadable, not here.
|
|
142
|
+
export function readPlaylistFile(filePath) {
|
|
143
|
+
const ext = extensionOf(filePath);
|
|
144
|
+
if (ext === 'm3u' || ext === 'm3u8') {
|
|
145
|
+
return parseM3u(readFileSync(filePath, 'utf8'), {
|
|
146
|
+
baseDir: path.dirname(filePath),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (ext === 'pls') {
|
|
150
|
+
return parsePls(readFileSync(filePath, 'utf8'), {
|
|
151
|
+
baseDir: path.dirname(filePath),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
if (ext === 'json') {
|
|
155
|
+
const data = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
156
|
+
return (Array.isArray(data.tracks) ? data.tracks : [])
|
|
157
|
+
.filter((track) => track && typeof track.path === 'string')
|
|
158
|
+
.map((track) => ({ path: track.path }));
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`Unsupported playlist format: .${ext}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Drop entries that are gone or not decodeable audio; count the rejects.
|
|
164
|
+
// Loading is "open, not merge" and never hard-fails on a dead line.
|
|
165
|
+
export function filterLoadable(entries) {
|
|
166
|
+
const tracks = [];
|
|
167
|
+
let skipped = 0;
|
|
168
|
+
for (const entry of entries) {
|
|
169
|
+
if (existsSync(entry.path) && isAudioFile(entry.path)) {
|
|
170
|
+
tracks.push({ path: entry.path, name: path.basename(entry.path) });
|
|
171
|
+
} else {
|
|
172
|
+
skipped++;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return { tracks, skipped };
|
|
176
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal graphics-capability hints for the debug panel.
|
|
3
|
+
*
|
|
4
|
+
* termdom 0.2.6 negotiates kitty graphics (real pixels in kitty/Ghostty)
|
|
5
|
+
* during attach, but exposes no public API for the negotiated result —
|
|
6
|
+
* the resolved state lives in the framebuffer's internal slots. This
|
|
7
|
+
* heuristic reads the environment instead: it can say which terminal we
|
|
8
|
+
* are likely under, never whether the negotiation actually succeeded.
|
|
9
|
+
* A definitive indicator needs an upstream getter (issues/035).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Detect which kitty-graphics-capable terminal we are running under.
|
|
14
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
15
|
+
* @returns {{ env: string|null, note: string|null }}
|
|
16
|
+
*/
|
|
17
|
+
export function detectGraphicsEnv(env = process.env) {
|
|
18
|
+
if (env.TMUX) {
|
|
19
|
+
return {
|
|
20
|
+
env: 'tmux',
|
|
21
|
+
note: 'kitty graphics needs allow-passthrough',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (
|
|
25
|
+
env.KITTY_WINDOW_ID ||
|
|
26
|
+
env.KITTY_PID ||
|
|
27
|
+
env.TERM?.startsWith('xterm-kitty')
|
|
28
|
+
) {
|
|
29
|
+
return { env: 'kitty', note: null };
|
|
30
|
+
}
|
|
31
|
+
if (env.GHOSTTY_RESOURCES_DIR || env.TERM === 'xterm-ghostty') {
|
|
32
|
+
return { env: 'ghostty', note: null };
|
|
33
|
+
}
|
|
34
|
+
return { env: null, note: null };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Debug-panel label for the graphics row: the requested engine mode
|
|
39
|
+
* (we pass none, so both default to auto) plus the environment hint.
|
|
40
|
+
* @param {NodeJS.ProcessEnv} [env]
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
export function graphicsLabel(env = process.env) {
|
|
44
|
+
const { env: name, note } = detectGraphicsEnv(env);
|
|
45
|
+
if (!name) return 'auto (env: none detected)';
|
|
46
|
+
return `auto (env: ${name}${note ? ` — ${note}` : ''})`;
|
|
47
|
+
}
|