0.12.0-3 Plugin Integration

This commit is contained in:
2026-03-21 15:58:57 +00:00
parent d9969dfbe5
commit e99cdf1895
20 changed files with 928 additions and 115 deletions
+48 -12
View File
@@ -576,7 +576,8 @@ function mapPresetEntriesToOptions(entries) {
* Parses the drive_devices JSON setting into a normalized array of {path, makemkvIndex}.
* Supports both the legacy string format ["/dev/sr0"] and the object format
* [{"path": "/dev/sr0", "makemkvIndex": 0}].
* When makemkvIndex is missing, it is auto-derived from the device name (sr0→0, sr1→1).
* When makemkvIndex is missing, it is assigned by list order (0,1,2,...) so
* sparse kernel names like /dev/sr2 still map to contiguous MakeMKV indices.
*/
function parseDriveDeviceEntries(raw) {
try {
@@ -584,28 +585,49 @@ function parseDriveDeviceEntries(raw) {
if (!Array.isArray(arr)) {
return [];
}
return arr.map((entry) => {
const normalized = arr.map((entry) => {
if (typeof entry === 'string') {
const p = entry.trim();
if (!p) {
return null;
}
const m = p.match(/sr(\d+)$/);
return { path: p, makemkvIndex: m ? Number(m[1]) : 0 };
return { path: p, makemkvIndex: null };
}
if (entry && typeof entry === 'object' && entry.path) {
const p = String(entry.path || '').trim();
if (!p) {
return null;
}
const idxRaw = entry.makemkvIndex != null ? Number(entry.makemkvIndex) : null;
const m = p.match(/sr(\d+)$/);
const derived = m ? Number(m[1]) : 0;
const idx = Number.isFinite(idxRaw) && idxRaw >= 0 ? Math.trunc(idxRaw) : derived;
return { path: p, makemkvIndex: idx };
const idxRaw = Number(entry.makemkvIndex);
return {
path: p,
makemkvIndex: Number.isFinite(idxRaw) && idxRaw >= 0 ? Math.trunc(idxRaw) : null
};
}
return null;
}).filter(Boolean);
const used = new Set();
let nextAutoIndex = 0;
return normalized.map((entry) => {
if (entry.makemkvIndex != null) {
used.add(entry.makemkvIndex);
if (entry.makemkvIndex >= nextAutoIndex) {
nextAutoIndex = entry.makemkvIndex + 1;
}
return entry;
}
while (used.has(nextAutoIndex)) {
nextAutoIndex += 1;
}
const resolved = {
path: entry.path,
makemkvIndex: nextAutoIndex
};
used.add(nextAutoIndex);
nextAutoIndex += 1;
return resolved;
});
} catch (_error) {
return [];
}
@@ -1413,17 +1435,31 @@ class SettingsService {
resolveSourceArg(map, deviceInfo = null) {
const devicePath = String(deviceInfo?.path || '').trim();
const deviceIndex = Number(deviceInfo?.makemkvIndex ?? deviceInfo?.index);
const configuredEntries = parseDriveDeviceEntries(map.drive_devices);
// In explicit mode: look up per-drive makemkvIndex from drive_devices
if (devicePath && map.drive_mode === 'explicit') {
const entries = parseDriveDeviceEntries(map.drive_devices);
const entry = entries.find((e) => e.path === devicePath);
const entry = configuredEntries.find((e) => e.path === devicePath);
if (entry) {
return `disc:${entry.makemkvIndex}`;
}
}
// Auto-derive from device name (/dev/sr0 → disc:0, /dev/sr1 → disc:1)
// Prefer configured per-drive index when a path match exists (also in auto mode).
if (devicePath) {
const configured = configuredEntries.find((e) => e.path === devicePath);
if (configured) {
return `disc:${configured.makemkvIndex}`;
}
}
// Prefer device-provided MakeMKV index from disk detection service.
if (Number.isFinite(deviceIndex) && deviceIndex >= 0) {
return `disc:${Math.trunc(deviceIndex)}`;
}
// Last automatic fallback: derive from device name (/dev/sr0 → disc:0).
if (devicePath) {
const match = devicePath.match(/sr(\d+)$/);
if (match) {