@dominevo/addon-media-library 0.1.13 → 0.1.14
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/CHANGELOG.md +6 -0
- package/dist/media-library.addon.js +1172 -1331
- package/dist/media-library.addon.mjs +1172 -1331
- package/package.json +2 -2
|
@@ -637,8 +637,7 @@ var $ZodCheckLessThan = /*@__PURE__*/ $constructor("$ZodCheckLessThan", (inst, d
|
|
|
637
637
|
const origin = numericOriginMap[typeof def.value];
|
|
638
638
|
inst._zod.onattach.push((inst) => {
|
|
639
639
|
const bag = inst._zod.bag;
|
|
640
|
-
|
|
641
|
-
if (def.value < curr) if (def.inclusive) bag.maximum = def.value;
|
|
640
|
+
if (def.value < ((def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY)) if (def.inclusive) bag.maximum = def.value;
|
|
642
641
|
else bag.exclusiveMaximum = def.value;
|
|
643
642
|
});
|
|
644
643
|
inst._zod.check = (payload) => {
|
|
@@ -659,8 +658,7 @@ var $ZodCheckGreaterThan = /*@__PURE__*/ $constructor("$ZodCheckGreaterThan", (i
|
|
|
659
658
|
const origin = numericOriginMap[typeof def.value];
|
|
660
659
|
inst._zod.onattach.push((inst) => {
|
|
661
660
|
const bag = inst._zod.bag;
|
|
662
|
-
|
|
663
|
-
if (def.value > curr) if (def.inclusive) bag.minimum = def.value;
|
|
661
|
+
if (def.value > ((def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY)) if (def.inclusive) bag.minimum = def.value;
|
|
664
662
|
else bag.exclusiveMinimum = def.value;
|
|
665
663
|
});
|
|
666
664
|
inst._zod.check = (payload) => {
|
|
@@ -774,8 +772,7 @@ var $ZodCheckMaxLength = /*@__PURE__*/ $constructor("$ZodCheckMaxLength", (inst,
|
|
|
774
772
|
return !nullish(val) && val.length !== void 0;
|
|
775
773
|
});
|
|
776
774
|
inst._zod.onattach.push((inst) => {
|
|
777
|
-
|
|
778
|
-
if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
|
|
775
|
+
if (def.maximum < (inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY)) inst._zod.bag.maximum = def.maximum;
|
|
779
776
|
});
|
|
780
777
|
inst._zod.check = (payload) => {
|
|
781
778
|
const input = payload.value;
|
|
@@ -800,8 +797,7 @@ var $ZodCheckMinLength = /*@__PURE__*/ $constructor("$ZodCheckMinLength", (inst,
|
|
|
800
797
|
return !nullish(val) && val.length !== void 0;
|
|
801
798
|
});
|
|
802
799
|
inst._zod.onattach.push((inst) => {
|
|
803
|
-
|
|
804
|
-
if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
|
|
800
|
+
if (def.minimum > (inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY)) inst._zod.bag.minimum = def.minimum;
|
|
805
801
|
});
|
|
806
802
|
inst._zod.check = (payload) => {
|
|
807
803
|
const input = payload.value;
|
|
@@ -836,10 +832,9 @@ var $ZodCheckLengthEquals = /*@__PURE__*/ $constructor("$ZodCheckLengthEquals",
|
|
|
836
832
|
const length = input.length;
|
|
837
833
|
if (length === def.length) return;
|
|
838
834
|
const origin = getLengthableOrigin(input);
|
|
839
|
-
const tooBig = length > def.length;
|
|
840
835
|
payload.issues.push({
|
|
841
836
|
origin,
|
|
842
|
-
...
|
|
837
|
+
...length > def.length ? {
|
|
843
838
|
code: "too_big",
|
|
844
839
|
maximum: def.length
|
|
845
840
|
} : {
|
|
@@ -1479,9 +1474,8 @@ var $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
|
|
|
1479
1474
|
payload.value = Array(input.length);
|
|
1480
1475
|
const proms = [];
|
|
1481
1476
|
for (let i = 0; i < input.length; i++) {
|
|
1482
|
-
const item = input[i];
|
|
1483
1477
|
const result = def.element._zod.run({
|
|
1484
|
-
value:
|
|
1478
|
+
value: input[i],
|
|
1485
1479
|
issues: []
|
|
1486
1480
|
}, ctx);
|
|
1487
1481
|
if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
|
|
@@ -5604,7 +5598,6 @@ function createEvent(category, source, data) {
|
|
|
5604
5598
|
* coordinate.
|
|
5605
5599
|
*/
|
|
5606
5600
|
function emitReadiness(bus, params) {
|
|
5607
|
-
const ts = params.ts ?? Date.now();
|
|
5608
5601
|
bus.emit(createEvent("system.ready-state", {
|
|
5609
5602
|
type: "capability",
|
|
5610
5603
|
id: params.capName,
|
|
@@ -5615,7 +5608,7 @@ function emitReadiness(bus, params) {
|
|
|
5615
5608
|
state: params.state,
|
|
5616
5609
|
generation: params.generation,
|
|
5617
5610
|
sourceNodeId: params.sourceNodeId,
|
|
5618
|
-
ts
|
|
5611
|
+
ts: params.ts ?? Date.now()
|
|
5619
5612
|
}));
|
|
5620
5613
|
}
|
|
5621
5614
|
//#endregion
|
|
@@ -8717,22 +8710,21 @@ var AppReachSchema = /* @__PURE__ */ discriminatedUnion("kind", [
|
|
|
8717
8710
|
]);
|
|
8718
8711
|
/** The role an app is offered to. */
|
|
8719
8712
|
var AppRoleSchema = /* @__PURE__ */ _enum(["admin", "user"]);
|
|
8720
|
-
var AppNavItemSchema = /* @__PURE__ */ object({
|
|
8721
|
-
id: /* @__PURE__ */ string(),
|
|
8722
|
-
label: AppLabelSchema,
|
|
8723
|
-
/** A lucide icon name. */
|
|
8724
|
-
icon: /* @__PURE__ */ string(),
|
|
8725
|
-
path: /* @__PURE__ */ string(),
|
|
8726
|
-
adminOnly: /* @__PURE__ */ boolean().optional(),
|
|
8727
|
-
keywords: /* @__PURE__ */ array(/* @__PURE__ */ string()).optional(),
|
|
8728
|
-
badgeKey: /* @__PURE__ */ string().optional(),
|
|
8729
|
-
/** Interpreted by the shell (phase 4): the item is hidden while the capability is absent. */
|
|
8730
|
-
requiresCapability: /* @__PURE__ */ string().optional()
|
|
8731
|
-
});
|
|
8732
8713
|
var AppNavSectionSchema = /* @__PURE__ */ object({
|
|
8733
8714
|
id: /* @__PURE__ */ string(),
|
|
8734
8715
|
label: /* @__PURE__ */ AppLabelSchema.nullable(),
|
|
8735
|
-
items: /* @__PURE__ */ array(
|
|
8716
|
+
items: /* @__PURE__ */ array(/* @__PURE__ */ object({
|
|
8717
|
+
id: /* @__PURE__ */ string(),
|
|
8718
|
+
label: AppLabelSchema,
|
|
8719
|
+
/** A lucide icon name. */
|
|
8720
|
+
icon: /* @__PURE__ */ string(),
|
|
8721
|
+
path: /* @__PURE__ */ string(),
|
|
8722
|
+
adminOnly: /* @__PURE__ */ boolean().optional(),
|
|
8723
|
+
keywords: /* @__PURE__ */ array(/* @__PURE__ */ string()).optional(),
|
|
8724
|
+
badgeKey: /* @__PURE__ */ string().optional(),
|
|
8725
|
+
/** Interpreted by the shell (phase 4): the item is hidden while the capability is absent. */
|
|
8726
|
+
requiresCapability: /* @__PURE__ */ string().optional()
|
|
8727
|
+
}))
|
|
8736
8728
|
});
|
|
8737
8729
|
var appSourceCapability = {
|
|
8738
8730
|
name: "app-source",
|
|
@@ -9346,629 +9338,119 @@ function withOptionalId(record) {
|
|
|
9346
9338
|
};
|
|
9347
9339
|
}
|
|
9348
9340
|
//#endregion
|
|
9349
|
-
//#region src/
|
|
9350
|
-
/**
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
|
|
9341
|
+
//#region src/servable.ts
|
|
9342
|
+
/**
|
|
9343
|
+
* A file is servable only when its REAL path (symlinks resolved) is inside a configured root.
|
|
9344
|
+
* The path itself comes from the catalogue by item id; this is the second lock on the same door,
|
|
9345
|
+
* so a catalogue row that names `/etc/passwd`, or a symlink that points out of the library, serves nothing.
|
|
9346
|
+
*/
|
|
9347
|
+
async function resolveServable(path, roots) {
|
|
9348
|
+
if (!(0, node_path.isAbsolute)(path) || path.includes("\0")) return null;
|
|
9349
|
+
let real;
|
|
9357
9350
|
try {
|
|
9358
|
-
|
|
9351
|
+
real = await (0, node_fs_promises.realpath)(path);
|
|
9359
9352
|
} catch {
|
|
9360
9353
|
return null;
|
|
9361
9354
|
}
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
});
|
|
9373
|
-
return NEVER;
|
|
9355
|
+
for (const root of roots) {
|
|
9356
|
+
if (root === "") continue;
|
|
9357
|
+
let realRoot;
|
|
9358
|
+
try {
|
|
9359
|
+
realRoot = await (0, node_fs_promises.realpath)(root);
|
|
9360
|
+
} catch {
|
|
9361
|
+
continue;
|
|
9362
|
+
}
|
|
9363
|
+
const prefix = realRoot.endsWith(node_path.sep) ? realRoot : `${realRoot}${node_path.sep}`;
|
|
9364
|
+
if (real.startsWith(prefix)) return real;
|
|
9374
9365
|
}
|
|
9375
|
-
return
|
|
9376
|
-
});
|
|
9377
|
-
/** The metadata steps, in the order they answer by default: files, the arr app, then online (each needs its key or switch), pictures last. */
|
|
9378
|
-
var METADATA_STEPS = [
|
|
9379
|
-
"local",
|
|
9380
|
-
"arr",
|
|
9381
|
-
"tmdb",
|
|
9382
|
-
"tvmaze",
|
|
9383
|
-
"tvdb",
|
|
9384
|
-
"omdb",
|
|
9385
|
-
"anilist",
|
|
9386
|
-
"fanart"
|
|
9387
|
-
];
|
|
9388
|
-
var DEFAULT_METADATA_ORDER = METADATA_STEPS;
|
|
9389
|
-
/** The steps that cannot answer without the installation's own key. */
|
|
9390
|
-
var KEYED_STEPS = [
|
|
9391
|
-
"tmdb",
|
|
9392
|
-
"tvdb",
|
|
9393
|
-
"omdb",
|
|
9394
|
-
"fanart"
|
|
9395
|
-
];
|
|
9396
|
-
function isStep(value) {
|
|
9397
|
-
return METADATA_STEPS.some((step) => step === value);
|
|
9366
|
+
return null;
|
|
9398
9367
|
}
|
|
9399
|
-
|
|
9400
|
-
|
|
9368
|
+
//#endregion
|
|
9369
|
+
//#region src/naming.ts
|
|
9370
|
+
/** Case- and accent-insensitive form of a title, for search and ordering. */
|
|
9371
|
+
function foldTitle(title) {
|
|
9372
|
+
return title.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim();
|
|
9401
9373
|
}
|
|
9402
|
-
/**
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
arr: "Sonarr and Radarr",
|
|
9406
|
-
tmdb: "TMDB",
|
|
9407
|
-
tvmaze: "TVmaze",
|
|
9408
|
-
tvdb: "TheTVDB",
|
|
9409
|
-
omdb: "OMDb",
|
|
9410
|
-
anilist: "AniList",
|
|
9411
|
-
fanart: "Fanart.tv"
|
|
9412
|
-
};
|
|
9413
|
-
/** One row of the metadata chain: the row order is the order the steps answer in (D1125). */
|
|
9414
|
-
var MetadataProviderRowSchema = object({
|
|
9415
|
-
/** The step this row is; stable, it addresses the row's secret. */
|
|
9416
|
-
id: string(),
|
|
9417
|
-
/** The step's display name, stamped by the addon for the row title. */
|
|
9418
|
-
name: string().default(""),
|
|
9419
|
-
enabled: boolean().default(true),
|
|
9420
|
-
/** The installation's own key or token, for a keyed step; unused by the others. */
|
|
9421
|
-
apiKey: string().meta({ secret: true }).default("")
|
|
9422
|
-
});
|
|
9423
|
-
/** A row for `step`; AniList needs no account but sends titles out, so it starts off. */
|
|
9424
|
-
function providerRow(step, patch = {}) {
|
|
9425
|
-
return {
|
|
9426
|
-
id: step,
|
|
9427
|
-
name: STEP_NAMES[step],
|
|
9428
|
-
enabled: step !== "anilist",
|
|
9429
|
-
apiKey: "",
|
|
9430
|
-
...patch
|
|
9431
|
-
};
|
|
9374
|
+
/** The ordering key: the folded title without a leading article. */
|
|
9375
|
+
function sortKey(title) {
|
|
9376
|
+
return foldTitle(title).replace(/^(the|a|an|il|lo|la|le|i|gli|un|una)\s+/, "");
|
|
9432
9377
|
}
|
|
9433
|
-
/**
|
|
9434
|
-
function
|
|
9435
|
-
return
|
|
9378
|
+
/** A stable short id for a thing that has no id of its own (a folder-found file or show). */
|
|
9379
|
+
function hashKey(text) {
|
|
9380
|
+
return (0, node_crypto.createHash)("sha1").update(text).digest("hex").slice(0, 16);
|
|
9436
9381
|
}
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
return row.enabled && (!isKeyedStep(step) || row.apiKey.trim() !== "");
|
|
9382
|
+
function itemId(sourceId, letter, key) {
|
|
9383
|
+
return `${sourceId}:${letter}:${key}`;
|
|
9440
9384
|
}
|
|
9441
|
-
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
const step = row.id.toLowerCase();
|
|
9446
|
-
if (isStep(step) && rowAnswers(row, step) && !out.includes(step)) out.push(step);
|
|
9447
|
-
}
|
|
9448
|
-
return out;
|
|
9385
|
+
var ID_PATTERN = /^[a-z-]+:[sme]:[A-Za-z0-9]+$/;
|
|
9386
|
+
/** An item id as a client may send it: the shape this module mints, nothing else. */
|
|
9387
|
+
function isItemId(candidate) {
|
|
9388
|
+
return ID_PATTERN.test(candidate);
|
|
9449
9389
|
}
|
|
9450
|
-
/**
|
|
9451
|
-
function
|
|
9452
|
-
if (
|
|
9453
|
-
|
|
9390
|
+
/** Apply a path-prefix mapping (arr path → local path). A path outside the prefix is returned unchanged. */
|
|
9391
|
+
function mapPath(path, from, to) {
|
|
9392
|
+
if (from === "" || to === "") return path;
|
|
9393
|
+
const prefix = from.replace(/\/+$/, "");
|
|
9394
|
+
if (path === prefix) return to.replace(/\/+$/, "");
|
|
9395
|
+
if (path.startsWith(`${prefix}/`)) return `${to.replace(/\/+$/, "")}${path.slice(prefix.length)}`;
|
|
9396
|
+
return path;
|
|
9454
9397
|
}
|
|
9455
|
-
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
|
|
9460
|
-
|
|
9461
|
-
|
|
9462
|
-
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
plexUrl: BaseUrlSchema.default(""),
|
|
9475
|
-
plexToken: string().meta({ secret: true }).default(""),
|
|
9476
|
-
plexPathFrom: string().default(""),
|
|
9477
|
-
plexPathTo: string().default(""),
|
|
9478
|
-
plexUserMap: string().default("")
|
|
9479
|
-
});
|
|
9480
|
-
/** A source is on only when both its URL and key are set; a half-filled one is off, not guessed. */
|
|
9481
|
-
function resolveSources(settings) {
|
|
9482
|
-
const pick = (baseUrl, apiKey, pathFrom, pathTo) => baseUrl === "" || apiKey === "" ? null : {
|
|
9483
|
-
baseUrl,
|
|
9484
|
-
apiKey,
|
|
9485
|
-
pathFrom: pathFrom.trim(),
|
|
9486
|
-
pathTo: pathTo.trim()
|
|
9487
|
-
};
|
|
9398
|
+
function cleanName(raw) {
|
|
9399
|
+
return raw.replace(/[._]+/g, " ").replace(/\s+/g, " ").replace(/[\s-]+$/, "").trim();
|
|
9400
|
+
}
|
|
9401
|
+
/** Guess what a file nobody catalogued is, from its name: `Show.S01E02…` is an episode, anything else a movie. */
|
|
9402
|
+
function guessFromFilename(fileName, parentDir) {
|
|
9403
|
+
const base = fileName.replace(/\.[A-Za-z0-9]+$/, "");
|
|
9404
|
+
const episode = /^(.*?)[\s._-]*S(\d{1,2})E(\d{1,3})/i.exec(base);
|
|
9405
|
+
if (episode?.[2] !== void 0 && episode[3] !== void 0) {
|
|
9406
|
+
const named = cleanName(episode[1] ?? "");
|
|
9407
|
+
return {
|
|
9408
|
+
kind: "episode",
|
|
9409
|
+
title: named === "" ? cleanName(parentDir) : named,
|
|
9410
|
+
year: null,
|
|
9411
|
+
seasonNumber: Number(episode[2]),
|
|
9412
|
+
episodeNumber: Number(episode[3])
|
|
9413
|
+
};
|
|
9414
|
+
}
|
|
9415
|
+
const year = /[([.\s_-]((?:19|20)\d{2})[)\].\s_-]/.exec(`${base} `);
|
|
9416
|
+
const title = cleanName(year ? base.slice(0, year.index) : base);
|
|
9488
9417
|
return {
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
tvdbApiKey: keyOf(settings, "tvdb"),
|
|
9495
|
-
fanartApiKey: keyOf(settings, "fanart"),
|
|
9496
|
-
omdbApiKey: keyOf(settings, "omdb")
|
|
9418
|
+
kind: "movie",
|
|
9419
|
+
title: title === "" ? cleanName(base) : title,
|
|
9420
|
+
year: year?.[1] !== void 0 ? Number(year[1]) : null,
|
|
9421
|
+
seasonNumber: null,
|
|
9422
|
+
episodeNumber: null
|
|
9497
9423
|
};
|
|
9498
9424
|
}
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9425
|
+
//#endregion
|
|
9426
|
+
//#region src/file-plane.ts
|
|
9427
|
+
/**
|
|
9428
|
+
* Parse one `Range: bytes=…` header against a file of `size` bytes. A header this server does not
|
|
9429
|
+
* understand, and a multi-range one, is served as the whole file (200), which RFC 9110 allows.
|
|
9430
|
+
*/
|
|
9431
|
+
function parseRange(header, size) {
|
|
9432
|
+
if (header === void 0) return { kind: "full" };
|
|
9433
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
9434
|
+
if (match === null) return { kind: "full" };
|
|
9435
|
+
const [, first = "", last = ""] = match;
|
|
9436
|
+
if (first === "" && last === "") return { kind: "full" };
|
|
9437
|
+
if (first === "") {
|
|
9438
|
+
const suffix = Number(last);
|
|
9439
|
+
if (suffix === 0 || size === 0) return { kind: "unsatisfiable" };
|
|
9440
|
+
return {
|
|
9441
|
+
kind: "range",
|
|
9442
|
+
start: Math.max(0, size - suffix),
|
|
9443
|
+
end: size - 1
|
|
9444
|
+
};
|
|
9445
|
+
}
|
|
9446
|
+
const start = Number(first);
|
|
9447
|
+
if (start >= size) return { kind: "unsatisfiable" };
|
|
9448
|
+
const end = last === "" ? size - 1 : Math.min(Number(last), size - 1);
|
|
9449
|
+
if (end < start) return { kind: "full" };
|
|
9502
9450
|
return {
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
pathTo: settings.plexPathTo.trim(),
|
|
9507
|
-
userMap: settings.plexUserMap
|
|
9508
|
-
};
|
|
9509
|
-
}
|
|
9510
|
-
var MEDIA_LIBRARY_CLUSTER_SCHEMA = { sections: [
|
|
9511
|
-
{
|
|
9512
|
-
id: "series",
|
|
9513
|
-
title: "Series source",
|
|
9514
|
-
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.title",
|
|
9515
|
-
fields: [
|
|
9516
|
-
{
|
|
9517
|
-
type: "text",
|
|
9518
|
-
key: "seriesArrUrl",
|
|
9519
|
-
label: "Sonarr URL",
|
|
9520
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrUrl.label",
|
|
9521
|
-
description: "Address of the series app, for example http://192.168.1.20:8989. Empty turns the source off.",
|
|
9522
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrUrl.description"
|
|
9523
|
-
},
|
|
9524
|
-
{
|
|
9525
|
-
type: "password",
|
|
9526
|
-
key: "seriesArrKey",
|
|
9527
|
-
label: "Sonarr API key",
|
|
9528
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrKey.label"
|
|
9529
|
-
},
|
|
9530
|
-
{
|
|
9531
|
-
type: "text",
|
|
9532
|
-
key: "seriesPathFrom",
|
|
9533
|
-
label: "Path in Sonarr",
|
|
9534
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathFrom.label",
|
|
9535
|
-
description: "The library folder as the series app sees it, for example /tv.",
|
|
9536
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathFrom.description"
|
|
9537
|
-
},
|
|
9538
|
-
{
|
|
9539
|
-
type: "text",
|
|
9540
|
-
key: "seriesPathTo",
|
|
9541
|
-
label: "Path on this hub",
|
|
9542
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathTo.label",
|
|
9543
|
-
description: "Where the same folder is mounted on this hub.",
|
|
9544
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathTo.description"
|
|
9545
|
-
}
|
|
9546
|
-
]
|
|
9547
|
-
},
|
|
9548
|
-
{
|
|
9549
|
-
id: "movies",
|
|
9550
|
-
title: "Movies source",
|
|
9551
|
-
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.title",
|
|
9552
|
-
fields: [
|
|
9553
|
-
{
|
|
9554
|
-
type: "text",
|
|
9555
|
-
key: "moviesArrUrl",
|
|
9556
|
-
label: "Radarr URL",
|
|
9557
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrUrl.label",
|
|
9558
|
-
description: "Address of the movies app, for example http://192.168.1.20:7878. Empty turns the source off.",
|
|
9559
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrUrl.description"
|
|
9560
|
-
},
|
|
9561
|
-
{
|
|
9562
|
-
type: "password",
|
|
9563
|
-
key: "moviesArrKey",
|
|
9564
|
-
label: "Radarr API key",
|
|
9565
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrKey.label"
|
|
9566
|
-
},
|
|
9567
|
-
{
|
|
9568
|
-
type: "text",
|
|
9569
|
-
key: "moviesPathFrom",
|
|
9570
|
-
label: "Path in Radarr",
|
|
9571
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathFrom.label",
|
|
9572
|
-
description: "The library folder as the movies app sees it, for example /movies.",
|
|
9573
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathFrom.description"
|
|
9574
|
-
},
|
|
9575
|
-
{
|
|
9576
|
-
type: "text",
|
|
9577
|
-
key: "moviesPathTo",
|
|
9578
|
-
label: "Path on this hub",
|
|
9579
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathTo.label",
|
|
9580
|
-
description: "Where the same folder is mounted on this hub.",
|
|
9581
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathTo.description"
|
|
9582
|
-
}
|
|
9583
|
-
]
|
|
9584
|
-
},
|
|
9585
|
-
{
|
|
9586
|
-
id: "folders",
|
|
9587
|
-
title: "Folders",
|
|
9588
|
-
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.title",
|
|
9589
|
-
fields: [
|
|
9590
|
-
{
|
|
9591
|
-
type: "textarea",
|
|
9592
|
-
key: "folderRoots",
|
|
9593
|
-
label: "Folders to walk",
|
|
9594
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.folderRoots.label",
|
|
9595
|
-
description: "One absolute path per line. Files the arr apps do not know are added from here.",
|
|
9596
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.folderRoots.description"
|
|
9597
|
-
},
|
|
9598
|
-
{
|
|
9599
|
-
type: "number",
|
|
9600
|
-
key: "rescanMinutes",
|
|
9601
|
-
label: "Rescan every (minutes)",
|
|
9602
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.rescanMinutes.label",
|
|
9603
|
-
description: "0 scans only when asked.",
|
|
9604
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.rescanMinutes.description",
|
|
9605
|
-
min: 0
|
|
9606
|
-
},
|
|
9607
|
-
{
|
|
9608
|
-
type: "boolean",
|
|
9609
|
-
key: "trickplay",
|
|
9610
|
-
label: "Scrub thumbnails",
|
|
9611
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.trickplay.label",
|
|
9612
|
-
description: "Generate preview pictures for the seek bar in the background, one ffmpeg at a time at low priority.",
|
|
9613
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.trickplay.description"
|
|
9614
|
-
}
|
|
9615
|
-
]
|
|
9616
|
-
},
|
|
9617
|
-
{
|
|
9618
|
-
id: "metadata",
|
|
9619
|
-
title: "Metadata",
|
|
9620
|
-
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.title",
|
|
9621
|
-
fields: [{
|
|
9622
|
-
type: "info",
|
|
9623
|
-
key: "providersGuide",
|
|
9624
|
-
label: "How to get the keys",
|
|
9625
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.providersGuide.label",
|
|
9626
|
-
format: "html",
|
|
9627
|
-
content: PROVIDERS_GUIDE_EN,
|
|
9628
|
-
contentKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.providersGuide.content"
|
|
9629
|
-
}, {
|
|
9630
|
-
type: "editable-array",
|
|
9631
|
-
key: "metadataProviders",
|
|
9632
|
-
label: "Metadata providers",
|
|
9633
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.label",
|
|
9634
|
-
description: "Asked from the top down: the first answer to a field wins. Move a row to change the order. A provider that needs a key and has none is skipped.",
|
|
9635
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.description",
|
|
9636
|
-
default: defaultProviderRows(),
|
|
9637
|
-
reorderable: true,
|
|
9638
|
-
fixedRows: true,
|
|
9639
|
-
itemIdKey: "id",
|
|
9640
|
-
rowTitleTemplate: "{name}",
|
|
9641
|
-
itemFields: [
|
|
9642
|
-
{
|
|
9643
|
-
type: "text",
|
|
9644
|
-
key: "id",
|
|
9645
|
-
label: "Provider",
|
|
9646
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.id.label",
|
|
9647
|
-
showWhen: {
|
|
9648
|
-
field: "id",
|
|
9649
|
-
equals: ""
|
|
9650
|
-
}
|
|
9651
|
-
},
|
|
9652
|
-
{
|
|
9653
|
-
type: "text",
|
|
9654
|
-
key: "name",
|
|
9655
|
-
label: "Name",
|
|
9656
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.name.label",
|
|
9657
|
-
showWhen: {
|
|
9658
|
-
field: "id",
|
|
9659
|
-
equals: ""
|
|
9660
|
-
}
|
|
9661
|
-
},
|
|
9662
|
-
{
|
|
9663
|
-
type: "boolean",
|
|
9664
|
-
key: "enabled",
|
|
9665
|
-
label: "Use this provider",
|
|
9666
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.enabled.label"
|
|
9667
|
-
},
|
|
9668
|
-
{
|
|
9669
|
-
type: "password",
|
|
9670
|
-
key: "apiKey",
|
|
9671
|
-
label: "API key or token",
|
|
9672
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.apiKey.label",
|
|
9673
|
-
description: "The key of your own account, stored in the keychain. Without it this provider is skipped.",
|
|
9674
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.apiKey.description",
|
|
9675
|
-
showWhen: {
|
|
9676
|
-
field: "id",
|
|
9677
|
-
in: [...KEYED_STEPS]
|
|
9678
|
-
}
|
|
9679
|
-
}
|
|
9680
|
-
]
|
|
9681
|
-
}]
|
|
9682
|
-
},
|
|
9683
|
-
{
|
|
9684
|
-
id: "plex",
|
|
9685
|
-
title: "Import from Plex",
|
|
9686
|
-
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.title",
|
|
9687
|
-
fields: [
|
|
9688
|
-
{
|
|
9689
|
-
type: "text",
|
|
9690
|
-
key: "plexUrl",
|
|
9691
|
-
label: "Plex server URL",
|
|
9692
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUrl.label",
|
|
9693
|
-
description: "Address of the Plex Media Server, for example http://192.168.1.20:32400. Used only when you press Preview or Import: nothing is linked or kept in sync.",
|
|
9694
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUrl.description"
|
|
9695
|
-
},
|
|
9696
|
-
{
|
|
9697
|
-
type: "password",
|
|
9698
|
-
key: "plexToken",
|
|
9699
|
-
label: "Plex token",
|
|
9700
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexToken.label",
|
|
9701
|
-
description: "The server owner's X-Plex-Token. Stored in the keychain.",
|
|
9702
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexToken.description"
|
|
9703
|
-
},
|
|
9704
|
-
{
|
|
9705
|
-
type: "text",
|
|
9706
|
-
key: "plexPathFrom",
|
|
9707
|
-
label: "Path in Plex",
|
|
9708
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathFrom.label",
|
|
9709
|
-
description: "The library folder as Plex sees it, for example /data/movies. Used to match files by path when the ids do not match.",
|
|
9710
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathFrom.description"
|
|
9711
|
-
},
|
|
9712
|
-
{
|
|
9713
|
-
type: "text",
|
|
9714
|
-
key: "plexPathTo",
|
|
9715
|
-
label: "Path on this hub",
|
|
9716
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathTo.label",
|
|
9717
|
-
description: "Where the same folder is mounted on this hub.",
|
|
9718
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathTo.description"
|
|
9719
|
-
},
|
|
9720
|
-
{
|
|
9721
|
-
type: "textarea",
|
|
9722
|
-
key: "plexUserMap",
|
|
9723
|
-
label: "Plex user to Dominevo user",
|
|
9724
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUserMap.label",
|
|
9725
|
-
description: "One \"plexName = dominevoUsername\" per line. Without a line a Plex user is matched by username, title or email.",
|
|
9726
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUserMap.description"
|
|
9727
|
-
},
|
|
9728
|
-
{
|
|
9729
|
-
type: "addon-action-button",
|
|
9730
|
-
addonId: "media-library",
|
|
9731
|
-
key: "__plex-import-preview",
|
|
9732
|
-
label: "Preview the Plex import",
|
|
9733
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-preview.label",
|
|
9734
|
-
description: "Reads Plex and works out what would be imported per user. Writes nothing. Save the settings first.",
|
|
9735
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-preview.description",
|
|
9736
|
-
buttonLabel: "Preview",
|
|
9737
|
-
action: "plexImportPreview",
|
|
9738
|
-
successMessage: "{message}"
|
|
9739
|
-
},
|
|
9740
|
-
{
|
|
9741
|
-
type: "addon-action-button",
|
|
9742
|
-
addonId: "media-library",
|
|
9743
|
-
key: "__plex-import-run",
|
|
9744
|
-
label: "Import from Plex",
|
|
9745
|
-
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-run.label",
|
|
9746
|
-
description: "Imports watched state, resume positions and Plex's TMDB/TVDB/IMDb ids. Safe to run again: a newer Dominevo position is never overwritten.",
|
|
9747
|
-
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-run.description",
|
|
9748
|
-
buttonLabel: "Import",
|
|
9749
|
-
action: "plexImportRun",
|
|
9750
|
-
variant: "primary",
|
|
9751
|
-
confirmMessage: "Import watch history and ids from Plex now?",
|
|
9752
|
-
successMessage: "{message}"
|
|
9753
|
-
}
|
|
9754
|
-
]
|
|
9755
|
-
}
|
|
9756
|
-
] };
|
|
9757
|
-
//#endregion
|
|
9758
|
-
//#region src/settings-migration.ts
|
|
9759
|
-
/** The settings the provider list replaced; stored by installations that saved before it. */
|
|
9760
|
-
var LEGACY_PROVIDER_KEYS = [
|
|
9761
|
-
"metadataOrder",
|
|
9762
|
-
"metadataLocalEnabled",
|
|
9763
|
-
"metadataArrEnabled",
|
|
9764
|
-
"metadataTvmazeEnabled",
|
|
9765
|
-
"metadataAnilistEnabled",
|
|
9766
|
-
"tmdbToken",
|
|
9767
|
-
"tvdbApiKey",
|
|
9768
|
-
"omdbApiKey",
|
|
9769
|
-
"fanartApiKey"
|
|
9770
|
-
];
|
|
9771
|
-
/** The old keys that held a credential. */
|
|
9772
|
-
var LEGACY_SECRET_KEYS = [
|
|
9773
|
-
"tmdbToken",
|
|
9774
|
-
"tvdbApiKey",
|
|
9775
|
-
"omdbApiKey",
|
|
9776
|
-
"fanartApiKey"
|
|
9777
|
-
];
|
|
9778
|
-
var LEGACY_KEY_OF_STEP = {
|
|
9779
|
-
tmdb: "tmdbToken",
|
|
9780
|
-
tvdb: "tvdbApiKey",
|
|
9781
|
-
omdb: "omdbApiKey",
|
|
9782
|
-
fanart: "fanartApiKey"
|
|
9783
|
-
};
|
|
9784
|
-
/** Orders saved by the defaults of earlier versions (TVmaze first, with or without TMDB): they mean "the default". */
|
|
9785
|
-
var LEGACY_DEFAULT_ORDER = /^local[\s,]+arr[\s,]+tvmaze(?:[\s,]+tmdb)?$/i;
|
|
9786
|
-
function text$4(value) {
|
|
9787
|
-
return typeof value === "string" ? value : "";
|
|
9788
|
-
}
|
|
9789
|
-
function flag(value, fallback) {
|
|
9790
|
-
return typeof value === "boolean" ? value : fallback;
|
|
9791
|
-
}
|
|
9792
|
-
/** The old order, then every step it left out (those were off). */
|
|
9793
|
-
function legacyOrder(raw) {
|
|
9794
|
-
const trimmed = raw.trim();
|
|
9795
|
-
if (trimmed === "" || LEGACY_DEFAULT_ORDER.test(trimmed)) return {
|
|
9796
|
-
order: [...DEFAULT_METADATA_ORDER],
|
|
9797
|
-
named: new Set(DEFAULT_METADATA_ORDER)
|
|
9798
|
-
};
|
|
9799
|
-
const named = /* @__PURE__ */ new Set();
|
|
9800
|
-
const order = [];
|
|
9801
|
-
for (const name of trimmed.split(/[\s,]+/)) {
|
|
9802
|
-
const step = name.toLowerCase();
|
|
9803
|
-
if (isStep(step) && !named.has(step)) {
|
|
9804
|
-
named.add(step);
|
|
9805
|
-
order.push(step);
|
|
9806
|
-
}
|
|
9807
|
-
}
|
|
9808
|
-
for (const step of DEFAULT_METADATA_ORDER) if (!named.has(step)) order.push(step);
|
|
9809
|
-
return {
|
|
9810
|
-
order,
|
|
9811
|
-
named
|
|
9812
|
-
};
|
|
9813
|
-
}
|
|
9814
|
-
function hasLegacyProviderKeys(stored) {
|
|
9815
|
-
return LEGACY_PROVIDER_KEYS.some((key) => stored[key] !== void 0);
|
|
9816
|
-
}
|
|
9817
|
-
/**
|
|
9818
|
-
* The provider list the old settings meant. `stored` holds RESOLVED values (the keys are plain
|
|
9819
|
-
* strings here, moved on into the keychain by the write that stores the rows). A step the old
|
|
9820
|
-
* order did not name is off, as it was; a keyed step is on when its key was set.
|
|
9821
|
-
*/
|
|
9822
|
-
function providerRowsFromLegacy(stored) {
|
|
9823
|
-
const { order, named } = legacyOrder(text$4(stored["metadataOrder"]));
|
|
9824
|
-
const flags = {
|
|
9825
|
-
local: flag(stored["metadataLocalEnabled"], true),
|
|
9826
|
-
arr: flag(stored["metadataArrEnabled"], true),
|
|
9827
|
-
tvmaze: flag(stored["metadataTvmazeEnabled"], true),
|
|
9828
|
-
anilist: flag(stored["metadataAnilistEnabled"], false)
|
|
9829
|
-
};
|
|
9830
|
-
return order.map((step) => {
|
|
9831
|
-
if (step === "local" || step === "arr" || step === "tvmaze" || step === "anilist") return providerRow(step, { enabled: named.has(step) && flags[step] });
|
|
9832
|
-
const apiKey = text$4(stored[LEGACY_KEY_OF_STEP[step]]);
|
|
9833
|
-
return providerRow(step, {
|
|
9834
|
-
enabled: named.has(step) && apiKey !== "",
|
|
9835
|
-
apiKey
|
|
9836
|
-
});
|
|
9837
|
-
});
|
|
9838
|
-
}
|
|
9839
|
-
/** The old secret key a step's row replaced. */
|
|
9840
|
-
function legacyKeyOfStep(step) {
|
|
9841
|
-
return isStep(step) && isKeyedStep(step) ? LEGACY_KEY_OF_STEP[step] : void 0;
|
|
9842
|
-
}
|
|
9843
|
-
/** Whether the stored row of the step `legacyKey` belonged to holds a key (a marker counts). */
|
|
9844
|
-
function rowHoldsKey(rows, legacyKey) {
|
|
9845
|
-
return rows.some((row) => legacyKeyOfStep(row.id) === legacyKey && row.apiKey.trim() !== "");
|
|
9846
|
-
}
|
|
9847
|
-
/** A stored list whose keyed row is empty takes the old key of that step; nothing else changes. */
|
|
9848
|
-
function fillMissingKeys(rows, stored) {
|
|
9849
|
-
return rows.map((row) => {
|
|
9850
|
-
const legacy = legacyKeyOfStep(row.id);
|
|
9851
|
-
const key = legacy === void 0 ? "" : text$4(stored[legacy]);
|
|
9852
|
-
return row.apiKey.trim() === "" && key !== "" ? {
|
|
9853
|
-
...row,
|
|
9854
|
-
apiKey: key
|
|
9855
|
-
} : row;
|
|
9856
|
-
});
|
|
9857
|
-
}
|
|
9858
|
-
//#endregion
|
|
9859
|
-
//#region src/servable.ts
|
|
9860
|
-
/**
|
|
9861
|
-
* A file is servable only when its REAL path (symlinks resolved) is inside a configured root.
|
|
9862
|
-
* The path itself comes from the catalogue by item id; this is the second lock on the same door,
|
|
9863
|
-
* so a catalogue row that names `/etc/passwd`, or a symlink that points out of the library, serves nothing.
|
|
9864
|
-
*/
|
|
9865
|
-
async function resolveServable(path, roots) {
|
|
9866
|
-
if (!(0, node_path.isAbsolute)(path) || path.includes("\0")) return null;
|
|
9867
|
-
let real;
|
|
9868
|
-
try {
|
|
9869
|
-
real = await (0, node_fs_promises.realpath)(path);
|
|
9870
|
-
} catch {
|
|
9871
|
-
return null;
|
|
9872
|
-
}
|
|
9873
|
-
for (const root of roots) {
|
|
9874
|
-
if (root === "") continue;
|
|
9875
|
-
let realRoot;
|
|
9876
|
-
try {
|
|
9877
|
-
realRoot = await (0, node_fs_promises.realpath)(root);
|
|
9878
|
-
} catch {
|
|
9879
|
-
continue;
|
|
9880
|
-
}
|
|
9881
|
-
const prefix = realRoot.endsWith(node_path.sep) ? realRoot : `${realRoot}${node_path.sep}`;
|
|
9882
|
-
if (real.startsWith(prefix)) return real;
|
|
9883
|
-
}
|
|
9884
|
-
return null;
|
|
9885
|
-
}
|
|
9886
|
-
//#endregion
|
|
9887
|
-
//#region src/naming.ts
|
|
9888
|
-
/** Case- and accent-insensitive form of a title, for search and ordering. */
|
|
9889
|
-
function foldTitle(title) {
|
|
9890
|
-
return title.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim();
|
|
9891
|
-
}
|
|
9892
|
-
/** The ordering key: the folded title without a leading article. */
|
|
9893
|
-
function sortKey(title) {
|
|
9894
|
-
return foldTitle(title).replace(/^(the|a|an|il|lo|la|le|i|gli|un|una)\s+/, "");
|
|
9895
|
-
}
|
|
9896
|
-
/** A stable short id for a thing that has no id of its own (a folder-found file or show). */
|
|
9897
|
-
function hashKey(text) {
|
|
9898
|
-
return (0, node_crypto.createHash)("sha1").update(text).digest("hex").slice(0, 16);
|
|
9899
|
-
}
|
|
9900
|
-
function itemId(sourceId, letter, key) {
|
|
9901
|
-
return `${sourceId}:${letter}:${key}`;
|
|
9902
|
-
}
|
|
9903
|
-
var ID_PATTERN = /^[a-z-]+:[sme]:[A-Za-z0-9]+$/;
|
|
9904
|
-
/** An item id as a client may send it: the shape this module mints, nothing else. */
|
|
9905
|
-
function isItemId(candidate) {
|
|
9906
|
-
return ID_PATTERN.test(candidate);
|
|
9907
|
-
}
|
|
9908
|
-
/** Apply a path-prefix mapping (arr path → local path). A path outside the prefix is returned unchanged. */
|
|
9909
|
-
function mapPath(path, from, to) {
|
|
9910
|
-
if (from === "" || to === "") return path;
|
|
9911
|
-
const prefix = from.replace(/\/+$/, "");
|
|
9912
|
-
if (path === prefix) return to.replace(/\/+$/, "");
|
|
9913
|
-
if (path.startsWith(`${prefix}/`)) return `${to.replace(/\/+$/, "")}${path.slice(prefix.length)}`;
|
|
9914
|
-
return path;
|
|
9915
|
-
}
|
|
9916
|
-
function cleanName(raw) {
|
|
9917
|
-
return raw.replace(/[._]+/g, " ").replace(/\s+/g, " ").replace(/[\s-]+$/, "").trim();
|
|
9918
|
-
}
|
|
9919
|
-
/** Guess what a file nobody catalogued is, from its name: `Show.S01E02…` is an episode, anything else a movie. */
|
|
9920
|
-
function guessFromFilename(fileName, parentDir) {
|
|
9921
|
-
const base = fileName.replace(/\.[A-Za-z0-9]+$/, "");
|
|
9922
|
-
const episode = /^(.*?)[\s._-]*S(\d{1,2})E(\d{1,3})/i.exec(base);
|
|
9923
|
-
if (episode?.[2] !== void 0 && episode[3] !== void 0) {
|
|
9924
|
-
const named = cleanName(episode[1] ?? "");
|
|
9925
|
-
return {
|
|
9926
|
-
kind: "episode",
|
|
9927
|
-
title: named === "" ? cleanName(parentDir) : named,
|
|
9928
|
-
year: null,
|
|
9929
|
-
seasonNumber: Number(episode[2]),
|
|
9930
|
-
episodeNumber: Number(episode[3])
|
|
9931
|
-
};
|
|
9932
|
-
}
|
|
9933
|
-
const year = /[([.\s_-]((?:19|20)\d{2})[)\].\s_-]/.exec(`${base} `);
|
|
9934
|
-
const title = cleanName(year ? base.slice(0, year.index) : base);
|
|
9935
|
-
return {
|
|
9936
|
-
kind: "movie",
|
|
9937
|
-
title: title === "" ? cleanName(base) : title,
|
|
9938
|
-
year: year?.[1] !== void 0 ? Number(year[1]) : null,
|
|
9939
|
-
seasonNumber: null,
|
|
9940
|
-
episodeNumber: null
|
|
9941
|
-
};
|
|
9942
|
-
}
|
|
9943
|
-
//#endregion
|
|
9944
|
-
//#region src/file-plane.ts
|
|
9945
|
-
/**
|
|
9946
|
-
* Parse one `Range: bytes=…` header against a file of `size` bytes. A header this server does not
|
|
9947
|
-
* understand, and a multi-range one, is served as the whole file (200), which RFC 9110 allows.
|
|
9948
|
-
*/
|
|
9949
|
-
function parseRange(header, size) {
|
|
9950
|
-
if (header === void 0) return { kind: "full" };
|
|
9951
|
-
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
9952
|
-
if (match === null) return { kind: "full" };
|
|
9953
|
-
const [, first = "", last = ""] = match;
|
|
9954
|
-
if (first === "" && last === "") return { kind: "full" };
|
|
9955
|
-
if (first === "") {
|
|
9956
|
-
const suffix = Number(last);
|
|
9957
|
-
if (suffix === 0 || size === 0) return { kind: "unsatisfiable" };
|
|
9958
|
-
return {
|
|
9959
|
-
kind: "range",
|
|
9960
|
-
start: Math.max(0, size - suffix),
|
|
9961
|
-
end: size - 1
|
|
9962
|
-
};
|
|
9963
|
-
}
|
|
9964
|
-
const start = Number(first);
|
|
9965
|
-
if (start >= size) return { kind: "unsatisfiable" };
|
|
9966
|
-
const end = last === "" ? size - 1 : Math.min(Number(last), size - 1);
|
|
9967
|
-
if (end < start) return { kind: "full" };
|
|
9968
|
-
return {
|
|
9969
|
-
kind: "range",
|
|
9970
|
-
start,
|
|
9971
|
-
end
|
|
9451
|
+
kind: "range",
|
|
9452
|
+
start,
|
|
9453
|
+
end
|
|
9972
9454
|
};
|
|
9973
9455
|
}
|
|
9974
9456
|
var CONTENT_TYPES = new Map([
|
|
@@ -14025,702 +13507,1110 @@ function createTmdbProvider(deps) {
|
|
|
14025
13507
|
return hit === void 0 ? null : detailsOf(kind, hit.id);
|
|
14026
13508
|
},
|
|
14027
13509
|
async lookup(kind, ids) {
|
|
14028
|
-
if (ids.tmdbId !== null) return detailsOf(kind, ids.tmdbId);
|
|
14029
|
-
const external = ids.imdbId !== null ? {
|
|
14030
|
-
source: "imdb_id",
|
|
14031
|
-
value: ids.imdbId
|
|
14032
|
-
} : ids.tvdbId !== null ? {
|
|
14033
|
-
source: "tvdb_id",
|
|
14034
|
-
value: String(ids.tvdbId)
|
|
14035
|
-
} : null;
|
|
13510
|
+
if (ids.tmdbId !== null) return detailsOf(kind, ids.tmdbId);
|
|
13511
|
+
const external = ids.imdbId !== null ? {
|
|
13512
|
+
source: "imdb_id",
|
|
13513
|
+
value: ids.imdbId
|
|
13514
|
+
} : ids.tvdbId !== null ? {
|
|
13515
|
+
source: "tvdb_id",
|
|
13516
|
+
value: String(ids.tvdbId)
|
|
13517
|
+
} : null;
|
|
13518
|
+
if (external === null) return null;
|
|
13519
|
+
const found = FindSchema.parse(await call(`/find/${encodeURIComponent(external.value)}`, { external_source: external.source }));
|
|
13520
|
+
const id = (kind === "movie" ? found.movie_results : found.tv_results)[0]?.id;
|
|
13521
|
+
return id === void 0 ? null : detailsOf(kind, id);
|
|
13522
|
+
},
|
|
13523
|
+
async episodes(match) {
|
|
13524
|
+
const base = `/tv/${encodeURIComponent(match.remoteId)}`;
|
|
13525
|
+
const show = DetailsSchema.parse(await call(base));
|
|
13526
|
+
const out = [];
|
|
13527
|
+
for (const season of show.seasons ?? []) {
|
|
13528
|
+
const list = SeasonSchema.parse(await call(`${base}/season/${season.season_number}`));
|
|
13529
|
+
for (const entry of list.episodes) out.push({
|
|
13530
|
+
season: entry.season_number,
|
|
13531
|
+
episode: entry.episode_number,
|
|
13532
|
+
title: text(entry.name),
|
|
13533
|
+
overview: text(entry.overview),
|
|
13534
|
+
still: image("w300", entry.still_path),
|
|
13535
|
+
details: {
|
|
13536
|
+
genres: {},
|
|
13537
|
+
runtimeMinutes: positive(entry.runtime),
|
|
13538
|
+
certification: null,
|
|
13539
|
+
creators: [],
|
|
13540
|
+
directors: personsOf(entry.crew, DIRECTOR_JOBS),
|
|
13541
|
+
writers: personsOf(entry.crew, WRITER_JOBS),
|
|
13542
|
+
cast: [],
|
|
13543
|
+
guestStars: castOf(entry.guest_stars)
|
|
13544
|
+
}
|
|
13545
|
+
});
|
|
13546
|
+
}
|
|
13547
|
+
return out;
|
|
13548
|
+
}
|
|
13549
|
+
};
|
|
13550
|
+
}
|
|
13551
|
+
//#endregion
|
|
13552
|
+
//#region src/tvdb.ts
|
|
13553
|
+
var TVDB_ID = "tvdb";
|
|
13554
|
+
var API$1 = "https://api4.thetvdb.com/v4";
|
|
13555
|
+
/** Said once per scan, never with the key. */
|
|
13556
|
+
var TVDB_REJECTED = "TheTVDB key rejected: check the API key in the settings";
|
|
13557
|
+
/** Artwork type ids: series poster / background, movie poster / background. */
|
|
13558
|
+
var ARTWORK = {
|
|
13559
|
+
series: {
|
|
13560
|
+
poster: 2,
|
|
13561
|
+
fanart: 3
|
|
13562
|
+
},
|
|
13563
|
+
movie: {
|
|
13564
|
+
poster: 14,
|
|
13565
|
+
fanart: 15
|
|
13566
|
+
}
|
|
13567
|
+
};
|
|
13568
|
+
var MAX_EPISODE_PAGES = 50;
|
|
13569
|
+
/** The login answer; the bearer is read by name below, it is a response, not a setting. */
|
|
13570
|
+
var LoginSchema = object({ data: record(string(), string()) });
|
|
13571
|
+
var SearchSchema$1 = object({ data: array(object({
|
|
13572
|
+
tvdb_id: union([string(), number()]),
|
|
13573
|
+
name: string().nullish(),
|
|
13574
|
+
year: union([string(), number()]).nullish()
|
|
13575
|
+
})).nullish() });
|
|
13576
|
+
var RemoteIdSchema = object({
|
|
13577
|
+
id: union([string(), number()]),
|
|
13578
|
+
sourceName: string()
|
|
13579
|
+
});
|
|
13580
|
+
var ExtendedSchema = object({ data: object({
|
|
13581
|
+
id: number().int(),
|
|
13582
|
+
name: string().nullish(),
|
|
13583
|
+
year: union([string(), number()]).nullish(),
|
|
13584
|
+
firstAired: string().nullish(),
|
|
13585
|
+
overview: string().nullish(),
|
|
13586
|
+
image: string().nullish(),
|
|
13587
|
+
remoteIds: array(RemoteIdSchema).nullish(),
|
|
13588
|
+
artworks: array(object({
|
|
13589
|
+
image: string(),
|
|
13590
|
+
type: number().int(),
|
|
13591
|
+
score: number().nullish()
|
|
13592
|
+
})).nullish()
|
|
13593
|
+
}) });
|
|
13594
|
+
var RemoteSearchSchema = object({ data: array(object({
|
|
13595
|
+
series: object({ id: number().int() }).nullish(),
|
|
13596
|
+
movie: object({ id: number().int() }).nullish()
|
|
13597
|
+
})).nullish() });
|
|
13598
|
+
var EpisodesSchema = object({
|
|
13599
|
+
data: object({ episodes: array(object({
|
|
13600
|
+
seasonNumber: number().int(),
|
|
13601
|
+
number: number().int(),
|
|
13602
|
+
name: string().nullish(),
|
|
13603
|
+
overview: string().nullish(),
|
|
13604
|
+
image: string().nullish()
|
|
13605
|
+
})) }),
|
|
13606
|
+
links: object({ next: number().int().nullish() }).nullish()
|
|
13607
|
+
});
|
|
13608
|
+
function bestArtwork(extended, type) {
|
|
13609
|
+
return (extended.artworks ?? []).filter((art) => art.type === type).sort((a, b) => (b.score ?? 0) - (a.score ?? 0))[0]?.image ?? null;
|
|
13610
|
+
}
|
|
13611
|
+
function remoteId(extended, source) {
|
|
13612
|
+
return extended.remoteIds?.find((entry) => source.test(entry.sourceName))?.id.toString() ?? null;
|
|
13613
|
+
}
|
|
13614
|
+
/** TheTVDB v4: series and movies; a bearer token from the key is held for the provider's lifetime. */
|
|
13615
|
+
function createTvdbProvider(deps) {
|
|
13616
|
+
let token = null;
|
|
13617
|
+
const login = async () => {
|
|
13618
|
+
try {
|
|
13619
|
+
const bytes = await deps.fetch(`${API$1}/login`, {
|
|
13620
|
+
headers: {
|
|
13621
|
+
"Content-Type": "application/json",
|
|
13622
|
+
Accept: "application/json"
|
|
13623
|
+
},
|
|
13624
|
+
body: JSON.stringify({ apikey: deps.apiKey })
|
|
13625
|
+
});
|
|
13626
|
+
const bearer = LoginSchema.parse(JSON.parse(bytes.toString("utf8"))).data["token"];
|
|
13627
|
+
if (bearer === void 0) throw new Error("TheTVDB login answered without a bearer");
|
|
13628
|
+
token = bearer;
|
|
13629
|
+
return bearer;
|
|
13630
|
+
} catch (error) {
|
|
13631
|
+
if (isHttp(error, 401)) throw new ProviderAuthError(TVDB_REJECTED);
|
|
13632
|
+
throw error;
|
|
13633
|
+
}
|
|
13634
|
+
};
|
|
13635
|
+
const call = async (path, query = {}) => {
|
|
13636
|
+
const params = new URLSearchParams(query).toString();
|
|
13637
|
+
const url = `${API$1}${path}${params === "" ? "" : `?${params}`}`;
|
|
13638
|
+
const send = async (bearer) => JSON.parse((await deps.fetch(url, { headers: {
|
|
13639
|
+
Authorization: `Bearer ${bearer}`,
|
|
13640
|
+
Accept: "application/json"
|
|
13641
|
+
} })).toString("utf8"));
|
|
13642
|
+
try {
|
|
13643
|
+
return await send(token ?? await login());
|
|
13644
|
+
} catch (error) {
|
|
13645
|
+
if (!isHttp(error, 401)) throw error;
|
|
13646
|
+
}
|
|
13647
|
+
try {
|
|
13648
|
+
return await send(await login());
|
|
13649
|
+
} catch (error) {
|
|
13650
|
+
if (isHttp(error, 401)) throw new ProviderAuthError(TVDB_REJECTED);
|
|
13651
|
+
throw error;
|
|
13652
|
+
}
|
|
13653
|
+
};
|
|
13654
|
+
const extendedPath = (kind, id) => `/${kind === "movie" ? "movies" : "series"}/${id}/extended`;
|
|
13655
|
+
const detailsOf = async (kind, id) => {
|
|
13656
|
+
try {
|
|
13657
|
+
const { data } = ExtendedSchema.parse(await call(extendedPath(kind, id)));
|
|
13658
|
+
const imdb = remoteId(data, /imdb/i);
|
|
13659
|
+
const tmdb = remoteId(data, /themoviedb|tmdb/i);
|
|
13660
|
+
return {
|
|
13661
|
+
providerId: TVDB_ID,
|
|
13662
|
+
remoteId: String(data.id),
|
|
13663
|
+
title: data.name ?? "",
|
|
13664
|
+
year: yearOf$2(data.year) ?? yearOf$2(data.firstAired),
|
|
13665
|
+
overview: text$1(data.overview),
|
|
13666
|
+
tvdbId: data.id,
|
|
13667
|
+
tmdbId: tmdb === null || !/^\d+$/.test(tmdb) ? null : Number(tmdb),
|
|
13668
|
+
imdbId: imdb,
|
|
13669
|
+
poster: bestArtwork(data, ARTWORK[kind].poster) ?? text$1(data.image),
|
|
13670
|
+
fanart: bestArtwork(data, ARTWORK[kind].fanart)
|
|
13671
|
+
};
|
|
13672
|
+
} catch (error) {
|
|
13673
|
+
if (isHttp(error, 404)) return null;
|
|
13674
|
+
throw error;
|
|
13675
|
+
}
|
|
13676
|
+
};
|
|
13677
|
+
return {
|
|
13678
|
+
id: TVDB_ID,
|
|
13679
|
+
kinds: ["movie", "series"],
|
|
13680
|
+
lookupBy: [
|
|
13681
|
+
"tvdbId",
|
|
13682
|
+
"imdbId",
|
|
13683
|
+
"tmdbId"
|
|
13684
|
+
],
|
|
13685
|
+
async identify(kind, title, year) {
|
|
13686
|
+
const exact = (SearchSchema$1.parse(await call("/search", {
|
|
13687
|
+
query: title,
|
|
13688
|
+
type: kind,
|
|
13689
|
+
...year === null ? {} : { year: String(year) }
|
|
13690
|
+
})).data ?? []).filter((entry) => foldTitle(entry.name ?? "") === foldTitle(title));
|
|
13691
|
+
const sameYear = year === null ? [] : exact.filter((entry) => yearOf$2(entry.year) === year);
|
|
13692
|
+
const ids = new Set((sameYear.length > 0 ? sameYear : exact).map((entry) => Number(entry.tvdb_id)));
|
|
13693
|
+
const [id] = [...ids];
|
|
13694
|
+
return ids.size === 1 && id !== void 0 && Number.isInteger(id) ? detailsOf(kind, id) : null;
|
|
13695
|
+
},
|
|
13696
|
+
async lookup(kind, ids) {
|
|
13697
|
+
if (ids.tvdbId !== null) return detailsOf(kind, ids.tvdbId);
|
|
13698
|
+
const external = ids.imdbId ?? (ids.tmdbId === null ? null : String(ids.tmdbId));
|
|
14036
13699
|
if (external === null) return null;
|
|
14037
|
-
|
|
14038
|
-
|
|
14039
|
-
|
|
13700
|
+
let found;
|
|
13701
|
+
try {
|
|
13702
|
+
found = RemoteSearchSchema.parse(await call(`/search/remoteid/${encodeURIComponent(external)}`));
|
|
13703
|
+
} catch (error) {
|
|
13704
|
+
if (isHttp(error, 404)) return null;
|
|
13705
|
+
throw error;
|
|
13706
|
+
}
|
|
13707
|
+
const hit = (found.data ?? []).map((entry) => kind === "movie" ? entry.movie : entry.series).find((entry) => entry !== null && entry !== void 0);
|
|
13708
|
+
return hit === void 0 || hit === null ? null : detailsOf(kind, hit.id);
|
|
14040
13709
|
},
|
|
14041
13710
|
async episodes(match) {
|
|
14042
|
-
const base = `/tv/${encodeURIComponent(match.remoteId)}`;
|
|
14043
|
-
const show = DetailsSchema.parse(await call(base));
|
|
14044
13711
|
const out = [];
|
|
14045
|
-
|
|
14046
|
-
|
|
14047
|
-
|
|
14048
|
-
|
|
14049
|
-
|
|
14050
|
-
|
|
14051
|
-
|
|
14052
|
-
|
|
14053
|
-
|
|
14054
|
-
genres: {},
|
|
14055
|
-
runtimeMinutes: positive(entry.runtime),
|
|
14056
|
-
certification: null,
|
|
14057
|
-
creators: [],
|
|
14058
|
-
directors: personsOf(entry.crew, DIRECTOR_JOBS),
|
|
14059
|
-
writers: personsOf(entry.crew, WRITER_JOBS),
|
|
14060
|
-
cast: [],
|
|
14061
|
-
guestStars: castOf(entry.guest_stars)
|
|
14062
|
-
}
|
|
13712
|
+
let page = 0;
|
|
13713
|
+
for (let guard = 0; page !== null && guard < MAX_EPISODE_PAGES; guard += 1) {
|
|
13714
|
+
const list = EpisodesSchema.parse(await call(`/series/${encodeURIComponent(match.remoteId)}/episodes/default`, { page: String(page) }));
|
|
13715
|
+
for (const entry of list.data.episodes) out.push({
|
|
13716
|
+
season: entry.seasonNumber,
|
|
13717
|
+
episode: entry.number,
|
|
13718
|
+
title: text$1(entry.name),
|
|
13719
|
+
overview: text$1(entry.overview),
|
|
13720
|
+
still: text$1(entry.image)
|
|
14063
13721
|
});
|
|
13722
|
+
page = list.links?.next ?? null;
|
|
14064
13723
|
}
|
|
14065
13724
|
return out;
|
|
14066
13725
|
}
|
|
14067
13726
|
};
|
|
14068
13727
|
}
|
|
14069
13728
|
//#endregion
|
|
14070
|
-
//#region src/
|
|
14071
|
-
var
|
|
14072
|
-
var API
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
poster: 2,
|
|
14079
|
-
fanart: 3
|
|
14080
|
-
},
|
|
14081
|
-
movie: {
|
|
14082
|
-
poster: 14,
|
|
14083
|
-
fanart: 15
|
|
14084
|
-
}
|
|
14085
|
-
};
|
|
14086
|
-
var MAX_EPISODE_PAGES = 50;
|
|
14087
|
-
/** The login answer; the bearer is read by name below, it is a response, not a setting. */
|
|
14088
|
-
var LoginSchema = object({ data: record(string(), string()) });
|
|
14089
|
-
var SearchSchema$1 = object({ data: array(object({
|
|
14090
|
-
tvdb_id: union([string(), number()]),
|
|
14091
|
-
name: string().nullish(),
|
|
14092
|
-
year: union([string(), number()]).nullish()
|
|
14093
|
-
})).nullish() });
|
|
14094
|
-
var RemoteIdSchema = object({
|
|
14095
|
-
id: union([string(), number()]),
|
|
14096
|
-
sourceName: string()
|
|
14097
|
-
});
|
|
14098
|
-
var ExtendedSchema = object({ data: object({
|
|
13729
|
+
//#region src/tvmaze.ts
|
|
13730
|
+
var TVMAZE_ID = "tvmaze";
|
|
13731
|
+
var API = "https://api.tvmaze.com";
|
|
13732
|
+
var ImageSchema = object({
|
|
13733
|
+
medium: string().nullish(),
|
|
13734
|
+
original: string().nullish()
|
|
13735
|
+
}).nullish();
|
|
13736
|
+
var ShowSchema = object({
|
|
14099
13737
|
id: number().int(),
|
|
13738
|
+
name: string(),
|
|
13739
|
+
premiered: string().nullish(),
|
|
13740
|
+
summary: string().nullish(),
|
|
13741
|
+
image: ImageSchema,
|
|
13742
|
+
externals: object({
|
|
13743
|
+
thetvdb: number().int().nullish(),
|
|
13744
|
+
imdb: string().nullish()
|
|
13745
|
+
}).nullish()
|
|
13746
|
+
});
|
|
13747
|
+
var SearchSchema = array(object({
|
|
13748
|
+
score: number(),
|
|
13749
|
+
show: ShowSchema
|
|
13750
|
+
}));
|
|
13751
|
+
var EpisodeSchema = object({
|
|
14100
13752
|
name: string().nullish(),
|
|
14101
|
-
|
|
14102
|
-
|
|
14103
|
-
|
|
14104
|
-
image:
|
|
14105
|
-
remoteIds: array(RemoteIdSchema).nullish(),
|
|
14106
|
-
artworks: array(object({
|
|
14107
|
-
image: string(),
|
|
14108
|
-
type: number().int(),
|
|
14109
|
-
score: number().nullish()
|
|
14110
|
-
})).nullish()
|
|
14111
|
-
}) });
|
|
14112
|
-
var RemoteSearchSchema = object({ data: array(object({
|
|
14113
|
-
series: object({ id: number().int() }).nullish(),
|
|
14114
|
-
movie: object({ id: number().int() }).nullish()
|
|
14115
|
-
})).nullish() });
|
|
14116
|
-
var EpisodesSchema = object({
|
|
14117
|
-
data: object({ episodes: array(object({
|
|
14118
|
-
seasonNumber: number().int(),
|
|
14119
|
-
number: number().int(),
|
|
14120
|
-
name: string().nullish(),
|
|
14121
|
-
overview: string().nullish(),
|
|
14122
|
-
image: string().nullish()
|
|
14123
|
-
})) }),
|
|
14124
|
-
links: object({ next: number().int().nullish() }).nullish()
|
|
13753
|
+
season: number().int(),
|
|
13754
|
+
number: number().int().nullish(),
|
|
13755
|
+
summary: string().nullish(),
|
|
13756
|
+
image: ImageSchema
|
|
14125
13757
|
});
|
|
14126
|
-
|
|
14127
|
-
|
|
13758
|
+
/** The summary field is HTML; keep the text. */
|
|
13759
|
+
function plain(html) {
|
|
13760
|
+
if (html === null || html === void 0) return null;
|
|
13761
|
+
const text = html.replace(/<[^>]*>/g, " ").replace(/&#(\d{1,6});|&#x([0-9a-f]{1,6});/gi, (_whole, dec, hex) => {
|
|
13762
|
+
const code = typeof dec === "string" ? Number(dec) : Number.parseInt(String(hex), 16);
|
|
13763
|
+
return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : "";
|
|
13764
|
+
}).replace(/'/g, "'").replace(/"/g, "\"").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/\s+/g, " ").trim();
|
|
13765
|
+
return text === "" ? null : text;
|
|
13766
|
+
}
|
|
13767
|
+
function imageOf(image) {
|
|
13768
|
+
const url = image?.original ?? image?.medium ?? null;
|
|
13769
|
+
return url !== null && url.startsWith("https://") ? url : null;
|
|
13770
|
+
}
|
|
13771
|
+
function yearOf(premiered) {
|
|
13772
|
+
const match = /^(\d{4})/.exec(premiered ?? "");
|
|
13773
|
+
return match?.[1] === void 0 ? null : Number(match[1]);
|
|
13774
|
+
}
|
|
13775
|
+
/** TVmaze: keyless, series only. Every call goes through the shared remote fetch and one spaced queue. */
|
|
13776
|
+
function createTvmazeProvider(deps) {
|
|
13777
|
+
const sleep = deps.sleep ?? ((ms) => new Promise((done) => setTimeout(done, ms)));
|
|
13778
|
+
const now = deps.now ?? Date.now;
|
|
13779
|
+
const gap = deps.minGapMs ?? 600;
|
|
13780
|
+
let tail = Promise.resolve();
|
|
13781
|
+
let lastCallAt = Number.NEGATIVE_INFINITY;
|
|
13782
|
+
const call = (path) => {
|
|
13783
|
+
const run = async () => {
|
|
13784
|
+
const wait = lastCallAt + gap - now();
|
|
13785
|
+
if (wait > 0) await sleep(wait);
|
|
13786
|
+
lastCallAt = now();
|
|
13787
|
+
const bytes = await deps.fetch(`${API}${path}`);
|
|
13788
|
+
return JSON.parse(bytes.toString("utf8"));
|
|
13789
|
+
};
|
|
13790
|
+
const result = tail.then(run, run);
|
|
13791
|
+
tail = result.catch(() => void 0);
|
|
13792
|
+
return result;
|
|
13793
|
+
};
|
|
13794
|
+
const matchOf = (show) => ({
|
|
13795
|
+
providerId: TVMAZE_ID,
|
|
13796
|
+
remoteId: String(show.id),
|
|
13797
|
+
title: show.name,
|
|
13798
|
+
year: yearOf(show.premiered),
|
|
13799
|
+
overview: plain(show.summary),
|
|
13800
|
+
tvdbId: show.externals?.thetvdb ?? null,
|
|
13801
|
+
tmdbId: null,
|
|
13802
|
+
imdbId: show.externals?.imdb ?? null,
|
|
13803
|
+
poster: imageOf(show.image),
|
|
13804
|
+
fanart: null
|
|
13805
|
+
});
|
|
13806
|
+
return {
|
|
13807
|
+
id: TVMAZE_ID,
|
|
13808
|
+
kinds: ["series"],
|
|
13809
|
+
async lookup(_kind, ids) {
|
|
13810
|
+
const query = ids.tvdbId !== null ? `thetvdb=${ids.tvdbId}` : ids.imdbId !== null ? `imdb=${encodeURIComponent(ids.imdbId)}` : null;
|
|
13811
|
+
if (query === null) return null;
|
|
13812
|
+
try {
|
|
13813
|
+
return matchOf(ShowSchema.parse(await call(`/lookup/shows?${query}`)));
|
|
13814
|
+
} catch (error) {
|
|
13815
|
+
if (error instanceof Error && /\b404\b/.test(error.message)) return null;
|
|
13816
|
+
throw error;
|
|
13817
|
+
}
|
|
13818
|
+
},
|
|
13819
|
+
async identify(_kind, title, year) {
|
|
13820
|
+
const found = SearchSchema.parse(await call(`/search/shows?q=${encodeURIComponent(title)}`));
|
|
13821
|
+
const sameYear = year === null ? void 0 : found.find((entry) => yearOf(entry.show.premiered) === year);
|
|
13822
|
+
const top = found[0];
|
|
13823
|
+
const hit = sameYear ?? (year === null || top !== void 0 && foldTitle(top.show.name) === foldTitle(title) ? top : void 0);
|
|
13824
|
+
if (hit === void 0) return null;
|
|
13825
|
+
const show = hit.show;
|
|
13826
|
+
return {
|
|
13827
|
+
providerId: TVMAZE_ID,
|
|
13828
|
+
remoteId: String(show.id),
|
|
13829
|
+
title: show.name,
|
|
13830
|
+
year: yearOf(show.premiered),
|
|
13831
|
+
overview: plain(show.summary),
|
|
13832
|
+
tvdbId: show.externals?.thetvdb ?? null,
|
|
13833
|
+
tmdbId: null,
|
|
13834
|
+
imdbId: show.externals?.imdb ?? null,
|
|
13835
|
+
poster: imageOf(show.image),
|
|
13836
|
+
fanart: null
|
|
13837
|
+
};
|
|
13838
|
+
},
|
|
13839
|
+
async episodes(match) {
|
|
13840
|
+
return array(EpisodeSchema).parse(await call(`/shows/${encodeURIComponent(match.remoteId)}/episodes?specials=1`)).flatMap((entry) => entry.number === null || entry.number === void 0 ? [] : [{
|
|
13841
|
+
season: entry.season,
|
|
13842
|
+
episode: entry.number,
|
|
13843
|
+
title: entry.name ?? null,
|
|
13844
|
+
overview: plain(entry.summary),
|
|
13845
|
+
still: imageOf(entry.image)
|
|
13846
|
+
}]);
|
|
13847
|
+
}
|
|
13848
|
+
};
|
|
13849
|
+
}
|
|
13850
|
+
//#endregion
|
|
13851
|
+
//#region src/img-plane.ts
|
|
13852
|
+
var FAILED_GRAB_TTL_MS = 30 * 6e4;
|
|
13853
|
+
var FAILED_GRAB_MAX = 500;
|
|
13854
|
+
/** The real fetch: the key travels in a header, a redirect is never followed, the body is size-capped as it streams. */
|
|
13855
|
+
var httpImageFetch = async (url, apiKey) => {
|
|
13856
|
+
const response = await fetch(url, {
|
|
13857
|
+
headers: { "X-Api-Key": apiKey },
|
|
13858
|
+
redirect: "manual",
|
|
13859
|
+
signal: AbortSignal.timeout(IMAGE_TIMEOUT_MS)
|
|
13860
|
+
});
|
|
13861
|
+
if (response.status >= 300 && response.status < 400) throw new Error(`redirect refused (HTTP ${response.status}): the key is never sent to another URL`);
|
|
13862
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
13863
|
+
return readCapped(response, MAX_IMAGE_BYTES);
|
|
13864
|
+
};
|
|
13865
|
+
function typeOf(bytes) {
|
|
13866
|
+
if (bytes.length > 3 && bytes[0] === 255 && bytes[1] === 216) return "image/jpeg";
|
|
13867
|
+
if (bytes.length > 8 && bytes.subarray(1, 4).toString("latin1") === "PNG") return "image/png";
|
|
13868
|
+
if (bytes.length > 12 && bytes.subarray(8, 12).toString("latin1") === "WEBP") return "image/webp";
|
|
13869
|
+
return null;
|
|
13870
|
+
}
|
|
13871
|
+
/**
|
|
13872
|
+
* The remote URL of an arr cover: a path on the arr's own origin, or an absolute URL that already
|
|
13873
|
+
* IS on that origin (the arr app answers plain http on a LAN). Never another host, port or scheme,
|
|
13874
|
+
* and never a URL that carries credentials.
|
|
13875
|
+
*/
|
|
13876
|
+
function coverUrl(source, path) {
|
|
13877
|
+
if (/^https?:\/\//i.test(path)) {
|
|
13878
|
+
const absolute = URL.canParse(path) ? new URL(path) : null;
|
|
13879
|
+
const own = new URL(source.baseUrl);
|
|
13880
|
+
return absolute !== null && absolute.origin === own.origin && absolute.username === "" && absolute.password === "" ? absolute.toString() : null;
|
|
13881
|
+
}
|
|
13882
|
+
if (!path.startsWith("/") || path.startsWith("//")) return null;
|
|
13883
|
+
const base = new URL(source.baseUrl);
|
|
13884
|
+
const url = new URL(`${source.baseUrl}${path}`);
|
|
13885
|
+
return url.origin === base.origin ? url.toString() : null;
|
|
14128
13886
|
}
|
|
14129
|
-
function
|
|
14130
|
-
|
|
13887
|
+
function end(res, status) {
|
|
13888
|
+
res.writeHead(status, { "Content-Length": 0 });
|
|
13889
|
+
res.end();
|
|
14131
13890
|
}
|
|
14132
|
-
/**
|
|
14133
|
-
function
|
|
14134
|
-
|
|
14135
|
-
const
|
|
14136
|
-
|
|
14137
|
-
|
|
14138
|
-
|
|
14139
|
-
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
|
|
13891
|
+
/** The `img` plane: `GET /<itemId>/poster|fanart`, fetched from the arr once and cached on disk. */
|
|
13892
|
+
function createImagePlaneHandler(deps) {
|
|
13893
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
13894
|
+
const now = deps.now ?? Date.now;
|
|
13895
|
+
/** key → when the failure is forgotten: a transient failure retries, and the set is bounded. */
|
|
13896
|
+
const failedGrabs = /* @__PURE__ */ new Map();
|
|
13897
|
+
const hasFailed = (key) => {
|
|
13898
|
+
const until = failedGrabs.get(key);
|
|
13899
|
+
if (until === void 0) return false;
|
|
13900
|
+
if (until > now()) return true;
|
|
13901
|
+
failedGrabs.delete(key);
|
|
13902
|
+
return false;
|
|
13903
|
+
};
|
|
13904
|
+
const rememberFailure = (key) => {
|
|
13905
|
+
failedGrabs.delete(key);
|
|
13906
|
+
failedGrabs.set(key, now() + FAILED_GRAB_TTL_MS);
|
|
13907
|
+
for (const oldest of failedGrabs.keys()) {
|
|
13908
|
+
if (failedGrabs.size <= FAILED_GRAB_MAX) break;
|
|
13909
|
+
failedGrabs.delete(oldest);
|
|
13910
|
+
}
|
|
13911
|
+
};
|
|
13912
|
+
const limitGrabs = createLimiter(deps.grabConcurrency ?? 2, deps.grabQueueLimit ?? 32);
|
|
13913
|
+
/** A sidecar image is read only from inside a configured root, symlinks resolved, and only up to the size cap. */
|
|
13914
|
+
const readLocal = async (path, tags) => {
|
|
13915
|
+
const real = await resolveServable(path, await deps.roots?.() ?? []);
|
|
13916
|
+
if (real === null) {
|
|
13917
|
+
deps.logger.warn("image refused: outside the configured folders", {
|
|
13918
|
+
tags,
|
|
13919
|
+
meta: { reason: "outside-roots" }
|
|
14143
13920
|
});
|
|
14144
|
-
|
|
14145
|
-
if (bearer === void 0) throw new Error("TheTVDB login answered without a bearer");
|
|
14146
|
-
token = bearer;
|
|
14147
|
-
return bearer;
|
|
14148
|
-
} catch (error) {
|
|
14149
|
-
if (isHttp(error, 401)) throw new ProviderAuthError(TVDB_REJECTED);
|
|
14150
|
-
throw error;
|
|
13921
|
+
return null;
|
|
14151
13922
|
}
|
|
13923
|
+
if ((await (0, node_fs_promises.stat)(real)).size > 10485760) throw new Error("image too large");
|
|
13924
|
+
return (0, node_fs_promises.readFile)(real);
|
|
14152
13925
|
};
|
|
14153
|
-
const
|
|
14154
|
-
|
|
14155
|
-
|
|
14156
|
-
const
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
|
|
14161
|
-
|
|
13926
|
+
const produce = async (found, tags) => {
|
|
13927
|
+
if (found.kind === "frame") return limitGrabs(() => deps.grabFrame(found.filePath, found.durationMs));
|
|
13928
|
+
if (found.kind === "remote") return deps.fetchRemote(found.url);
|
|
13929
|
+
const arr = await deps.arrSource(found.sourceId);
|
|
13930
|
+
const url = arr === null ? null : coverUrl(arr, found.path);
|
|
13931
|
+
if (arr === null || url === null) {
|
|
13932
|
+
deps.logger.warn("image skipped: no usable source", {
|
|
13933
|
+
tags,
|
|
13934
|
+
meta: { reason: arr === null ? "source-off" : "foreign-origin" }
|
|
13935
|
+
});
|
|
13936
|
+
return null;
|
|
13937
|
+
}
|
|
13938
|
+
return deps.fetchImage(url, arr.apiKey);
|
|
13939
|
+
};
|
|
13940
|
+
const load = async (itemId, which) => {
|
|
13941
|
+
for (const found of await deps.source(itemId, which)) {
|
|
13942
|
+
const bytes = await loadOne(itemId, which, found);
|
|
13943
|
+
if (bytes !== null) return bytes;
|
|
13944
|
+
}
|
|
13945
|
+
return null;
|
|
13946
|
+
};
|
|
13947
|
+
const loadOne = async (itemId, which, found) => {
|
|
13948
|
+
const tags = { itemId };
|
|
13949
|
+
const origin = found.kind === "arr" ? found.path : found.kind === "remote" ? found.url : found.kind === "local" ? found.path : `frame:${found.filePath}`;
|
|
13950
|
+
if (found.kind === "local") try {
|
|
13951
|
+
const bytes = await readLocal(found.path, tags);
|
|
13952
|
+
return bytes !== null && typeOf(bytes) !== null ? bytes : null;
|
|
14162
13953
|
} catch (error) {
|
|
14163
|
-
|
|
13954
|
+
deps.logger.warn("image fetch failed", {
|
|
13955
|
+
tags,
|
|
13956
|
+
meta: {
|
|
13957
|
+
reason: "read-failed",
|
|
13958
|
+
error: error instanceof Error ? error.message : String(error)
|
|
13959
|
+
}
|
|
13960
|
+
});
|
|
13961
|
+
return null;
|
|
14164
13962
|
}
|
|
13963
|
+
const key = hashKey(`${itemId}:${which}:${origin}`);
|
|
13964
|
+
if (hasFailed(key)) return null;
|
|
13965
|
+
const cached = (0, node_path.join)(deps.cacheDir, key);
|
|
14165
13966
|
try {
|
|
14166
|
-
|
|
13967
|
+
const onDisk = await (0, node_fs_promises.readFile)(cached);
|
|
13968
|
+
if (typeOf(onDisk) !== null) return onDisk;
|
|
13969
|
+
deps.logger.warn("cached image is not an image: dropped and fetched again", {
|
|
13970
|
+
tags,
|
|
13971
|
+
meta: { reason: "cache-corrupt" }
|
|
13972
|
+
});
|
|
13973
|
+
await (0, node_fs_promises.unlink)(cached);
|
|
13974
|
+
} catch {}
|
|
13975
|
+
try {
|
|
13976
|
+
const bytes = await produce(found, tags);
|
|
13977
|
+
if (bytes === null) return null;
|
|
13978
|
+
if (typeOf(bytes) === null) throw new Error("not an image");
|
|
13979
|
+
await (0, node_fs_promises.mkdir)(deps.cacheDir, { recursive: true });
|
|
13980
|
+
await (0, node_fs_promises.writeFile)(`${cached}.tmp`, bytes);
|
|
13981
|
+
await (0, node_fs_promises.rename)(`${cached}.tmp`, cached);
|
|
13982
|
+
return bytes;
|
|
14167
13983
|
} catch (error) {
|
|
14168
|
-
if (
|
|
14169
|
-
|
|
13984
|
+
if (error instanceof LimiterFullError) {
|
|
13985
|
+
deps.logger.warn("frame grab refused", {
|
|
13986
|
+
tags,
|
|
13987
|
+
meta: { reason: "queue-full" }
|
|
13988
|
+
});
|
|
13989
|
+
return null;
|
|
13990
|
+
}
|
|
13991
|
+
if (found.kind === "frame") rememberFailure(key);
|
|
13992
|
+
deps.logger.warn(found.kind === "frame" ? "frame grab failed" : "image fetch failed", {
|
|
13993
|
+
tags,
|
|
13994
|
+
meta: {
|
|
13995
|
+
reason: found.kind === "frame" ? "grab-failed" : "fetch-failed",
|
|
13996
|
+
error: error instanceof Error ? error.message : String(error)
|
|
13997
|
+
}
|
|
13998
|
+
});
|
|
13999
|
+
return null;
|
|
14170
14000
|
}
|
|
14171
14001
|
};
|
|
14172
|
-
|
|
14173
|
-
|
|
14002
|
+
return async (req, res) => {
|
|
14003
|
+
if (req.method !== "GET" && req.method !== "HEAD") return end(res, 405);
|
|
14004
|
+
const parts = ((req.url ?? "/").split("?")[0] ?? "/").replace(/^\//, "").split("/");
|
|
14005
|
+
const [rawId, which] = parts;
|
|
14006
|
+
let itemId = "";
|
|
14174
14007
|
try {
|
|
14175
|
-
|
|
14176
|
-
|
|
14177
|
-
|
|
14178
|
-
return {
|
|
14179
|
-
providerId: TVDB_ID,
|
|
14180
|
-
remoteId: String(data.id),
|
|
14181
|
-
title: data.name ?? "",
|
|
14182
|
-
year: yearOf$2(data.year) ?? yearOf$2(data.firstAired),
|
|
14183
|
-
overview: text$1(data.overview),
|
|
14184
|
-
tvdbId: data.id,
|
|
14185
|
-
tmdbId: tmdb === null || !/^\d+$/.test(tmdb) ? null : Number(tmdb),
|
|
14186
|
-
imdbId: imdb,
|
|
14187
|
-
poster: bestArtwork(data, ARTWORK[kind].poster) ?? text$1(data.image),
|
|
14188
|
-
fanart: bestArtwork(data, ARTWORK[kind].fanart)
|
|
14189
|
-
};
|
|
14190
|
-
} catch (error) {
|
|
14191
|
-
if (isHttp(error, 404)) return null;
|
|
14192
|
-
throw error;
|
|
14008
|
+
itemId = decodeURIComponent(rawId ?? "");
|
|
14009
|
+
} catch {
|
|
14010
|
+
return end(res, 404);
|
|
14193
14011
|
}
|
|
14194
|
-
|
|
14195
|
-
|
|
14196
|
-
|
|
14197
|
-
|
|
14198
|
-
|
|
14199
|
-
|
|
14200
|
-
|
|
14201
|
-
|
|
14202
|
-
|
|
14203
|
-
|
|
14204
|
-
|
|
14205
|
-
|
|
14206
|
-
type: kind,
|
|
14207
|
-
...year === null ? {} : { year: String(year) }
|
|
14208
|
-
})).data ?? []).filter((entry) => foldTitle(entry.name ?? "") === foldTitle(title));
|
|
14209
|
-
const sameYear = year === null ? [] : exact.filter((entry) => yearOf$2(entry.year) === year);
|
|
14210
|
-
const pool = sameYear.length > 0 ? sameYear : exact;
|
|
14211
|
-
const ids = new Set(pool.map((entry) => Number(entry.tvdb_id)));
|
|
14212
|
-
const [id] = [...ids];
|
|
14213
|
-
return ids.size === 1 && id !== void 0 && Number.isInteger(id) ? detailsOf(kind, id) : null;
|
|
14214
|
-
},
|
|
14215
|
-
async lookup(kind, ids) {
|
|
14216
|
-
if (ids.tvdbId !== null) return detailsOf(kind, ids.tvdbId);
|
|
14217
|
-
const external = ids.imdbId ?? (ids.tmdbId === null ? null : String(ids.tmdbId));
|
|
14218
|
-
if (external === null) return null;
|
|
14219
|
-
let found;
|
|
14220
|
-
try {
|
|
14221
|
-
found = RemoteSearchSchema.parse(await call(`/search/remoteid/${encodeURIComponent(external)}`));
|
|
14222
|
-
} catch (error) {
|
|
14223
|
-
if (isHttp(error, 404)) return null;
|
|
14224
|
-
throw error;
|
|
14225
|
-
}
|
|
14226
|
-
const hit = (found.data ?? []).map((entry) => kind === "movie" ? entry.movie : entry.series).find((entry) => entry !== null && entry !== void 0);
|
|
14227
|
-
return hit === void 0 || hit === null ? null : detailsOf(kind, hit.id);
|
|
14228
|
-
},
|
|
14229
|
-
async episodes(match) {
|
|
14230
|
-
const out = [];
|
|
14231
|
-
let page = 0;
|
|
14232
|
-
for (let guard = 0; page !== null && guard < MAX_EPISODE_PAGES; guard += 1) {
|
|
14233
|
-
const list = EpisodesSchema.parse(await call(`/series/${encodeURIComponent(match.remoteId)}/episodes/default`, { page: String(page) }));
|
|
14234
|
-
for (const entry of list.data.episodes) out.push({
|
|
14235
|
-
season: entry.seasonNumber,
|
|
14236
|
-
episode: entry.number,
|
|
14237
|
-
title: text$1(entry.name),
|
|
14238
|
-
overview: text$1(entry.overview),
|
|
14239
|
-
still: text$1(entry.image)
|
|
14240
|
-
});
|
|
14241
|
-
page = list.links?.next ?? null;
|
|
14242
|
-
}
|
|
14243
|
-
return out;
|
|
14012
|
+
if (parts.length !== 2 || !isItemId(itemId) || !isImageKind(which)) {
|
|
14013
|
+
deps.logger.warn("image request refused", { meta: { reason: "bad-request" } });
|
|
14014
|
+
return end(res, 404);
|
|
14015
|
+
}
|
|
14016
|
+
const flightKey = `${itemId}:${which}`;
|
|
14017
|
+
const pending = inFlight.get(flightKey) ?? load(itemId, which);
|
|
14018
|
+
inFlight.set(flightKey, pending);
|
|
14019
|
+
let bytes;
|
|
14020
|
+
try {
|
|
14021
|
+
bytes = await pending;
|
|
14022
|
+
} finally {
|
|
14023
|
+
inFlight.delete(flightKey);
|
|
14244
14024
|
}
|
|
14025
|
+
const contentType = bytes === null ? null : typeOf(bytes);
|
|
14026
|
+
if (bytes === null || contentType === null) return end(res, 404);
|
|
14027
|
+
res.writeHead(200, {
|
|
14028
|
+
"Content-Type": contentType,
|
|
14029
|
+
"Content-Length": bytes.length,
|
|
14030
|
+
"Cache-Control": "private, max-age=86400"
|
|
14031
|
+
});
|
|
14032
|
+
res.end(req.method === "HEAD" ? void 0 : bytes);
|
|
14245
14033
|
};
|
|
14246
14034
|
}
|
|
14247
|
-
//#endregion
|
|
14248
|
-
//#region src/
|
|
14249
|
-
var
|
|
14250
|
-
|
|
14251
|
-
|
|
14252
|
-
|
|
14253
|
-
|
|
14254
|
-
|
|
14255
|
-
|
|
14256
|
-
|
|
14257
|
-
|
|
14258
|
-
|
|
14259
|
-
|
|
14260
|
-
|
|
14261
|
-
|
|
14262
|
-
thetvdb: number().int().nullish(),
|
|
14263
|
-
imdb: string().nullish()
|
|
14264
|
-
}).nullish()
|
|
14265
|
-
});
|
|
14266
|
-
var SearchSchema = array(object({
|
|
14267
|
-
score: number(),
|
|
14268
|
-
show: ShowSchema
|
|
14269
|
-
}));
|
|
14270
|
-
var EpisodeSchema = object({
|
|
14271
|
-
name: string().nullish(),
|
|
14272
|
-
season: number().int(),
|
|
14273
|
-
number: number().int().nullish(),
|
|
14274
|
-
summary: string().nullish(),
|
|
14275
|
-
image: ImageSchema
|
|
14276
|
-
});
|
|
14277
|
-
/** The summary field is HTML; keep the text. */
|
|
14278
|
-
function plain(html) {
|
|
14279
|
-
if (html === null || html === void 0) return null;
|
|
14280
|
-
const text = html.replace(/<[^>]*>/g, " ").replace(/&#(\d{1,6});|&#x([0-9a-f]{1,6});/gi, (_whole, dec, hex) => {
|
|
14281
|
-
const code = typeof dec === "string" ? Number(dec) : Number.parseInt(String(hex), 16);
|
|
14282
|
-
return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : "";
|
|
14283
|
-
}).replace(/'/g, "'").replace(/"/g, "\"").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/\s+/g, " ").trim();
|
|
14284
|
-
return text === "" ? null : text;
|
|
14035
|
+
//#endregion
|
|
14036
|
+
//#region src/probe.ts
|
|
14037
|
+
var CONTAINER_NAMES = new Map([
|
|
14038
|
+
["matroska", "mkv"],
|
|
14039
|
+
["mov", "mp4"],
|
|
14040
|
+
["avi", "avi"],
|
|
14041
|
+
["mpegts", "ts"]
|
|
14042
|
+
]);
|
|
14043
|
+
function containerOf(formats) {
|
|
14044
|
+
const first = formats.split(",")[0]?.trim() ?? formats;
|
|
14045
|
+
return CONTAINER_NAMES.get(first) ?? first;
|
|
14046
|
+
}
|
|
14047
|
+
function languageOf(tag) {
|
|
14048
|
+
if (tag === void 0 || tag === "" || tag === "und") return null;
|
|
14049
|
+
return tag;
|
|
14285
14050
|
}
|
|
14286
|
-
function
|
|
14287
|
-
|
|
14288
|
-
|
|
14051
|
+
function bitDepthOf(pixFmt) {
|
|
14052
|
+
if (pixFmt === null) return null;
|
|
14053
|
+
const match = /(?:p|le|be)(9|10|12|14|16)(?:le|be)?$/.exec(pixFmt);
|
|
14054
|
+
if (match?.[1] !== void 0) return Number(match[1]);
|
|
14055
|
+
return /^(yuv|nv|gray|rgb|bgr)/.test(pixFmt) ? 8 : null;
|
|
14289
14056
|
}
|
|
14290
|
-
function
|
|
14291
|
-
|
|
14292
|
-
|
|
14057
|
+
function hdrOf(line, doviSeen) {
|
|
14058
|
+
if (doviSeen) return "dolby-vision";
|
|
14059
|
+
if (line.includes("smpte2084")) return "hdr10";
|
|
14060
|
+
if (line.includes("arib-std-b67")) return "hlg";
|
|
14061
|
+
return null;
|
|
14293
14062
|
}
|
|
14294
|
-
|
|
14295
|
-
|
|
14296
|
-
|
|
14297
|
-
const
|
|
14298
|
-
|
|
14299
|
-
|
|
14300
|
-
|
|
14301
|
-
|
|
14302
|
-
|
|
14303
|
-
|
|
14304
|
-
|
|
14305
|
-
|
|
14306
|
-
|
|
14307
|
-
|
|
14063
|
+
function channelsOf(line) {
|
|
14064
|
+
if (/\bmono\b/.test(line)) return 1;
|
|
14065
|
+
if (/\bstereo\b/.test(line)) return 2;
|
|
14066
|
+
const layout = /\b(\d)\.(\d)(?:\([a-z]+\))?/.exec(line);
|
|
14067
|
+
if (layout?.[1] !== void 0 && layout[2] !== void 0) return Number(layout[1]) + Number(layout[2]);
|
|
14068
|
+
const count = /\b(\d+) channels\b/.exec(line);
|
|
14069
|
+
return count?.[1] !== void 0 ? Number(count[1]) : null;
|
|
14070
|
+
}
|
|
14071
|
+
var STREAM_LINE = /^\s*Stream #\d+:(\d+)(?:\[[^\]]*\])?(?:\(([^)]*)\))?[^:]*: (Video|Audio|Subtitle): (.*)$/;
|
|
14072
|
+
var CHAPTER_LINE = /^\s*Chapter #\d+:\d+: start ([\d.]+), end ([\d.]+)/;
|
|
14073
|
+
var CHAPTER_TITLE = /^\s+title\s*:\s*(.*)$/;
|
|
14074
|
+
/** Parse the report `ffmpeg -i <file>` prints on stderr. A report that is not one yields no streams and no duration. */
|
|
14075
|
+
function parseFfmpegReport(report) {
|
|
14076
|
+
const lines = report.split("\n");
|
|
14077
|
+
let container = null;
|
|
14078
|
+
let durationMs = null;
|
|
14079
|
+
const streams = [];
|
|
14080
|
+
const chapters = [];
|
|
14081
|
+
let doviSeenFor = null;
|
|
14082
|
+
let inChapters = false;
|
|
14083
|
+
for (const line of lines) {
|
|
14084
|
+
const input = /^Input #\d+, ([^,]+(?:,[^,]+)*), from /.exec(line);
|
|
14085
|
+
if (input?.[1] !== void 0 && container === null) container = containerOf(input[1]);
|
|
14086
|
+
const duration = /^\s*Duration: (\d+):(\d{2}):(\d{2})\.(\d{2})/.exec(line);
|
|
14087
|
+
if (duration && durationMs === null) durationMs = (Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3])) * 1e3 + Number(duration[4]) * 10;
|
|
14088
|
+
const chapter = CHAPTER_LINE.exec(line);
|
|
14089
|
+
if (chapter?.[1] !== void 0 && chapter[2] !== void 0) {
|
|
14090
|
+
const startSec = Number(chapter[1]);
|
|
14091
|
+
const endSec = Number(chapter[2]);
|
|
14092
|
+
if (Number.isFinite(startSec) && Number.isFinite(endSec) && endSec > startSec) chapters.push({
|
|
14093
|
+
startSec,
|
|
14094
|
+
endSec,
|
|
14095
|
+
title: null
|
|
14096
|
+
});
|
|
14097
|
+
continue;
|
|
14098
|
+
}
|
|
14099
|
+
const titled = CHAPTER_TITLE.exec(line);
|
|
14100
|
+
const last = chapters[chapters.length - 1];
|
|
14101
|
+
if (titled?.[1] !== void 0 && last !== void 0 && last.title === null && inChapters) {
|
|
14102
|
+
if (titled[1].trim() !== "") chapters[chapters.length - 1] = {
|
|
14103
|
+
...last,
|
|
14104
|
+
title: titled[1].trim()
|
|
14105
|
+
};
|
|
14106
|
+
continue;
|
|
14107
|
+
}
|
|
14108
|
+
if (/^\s*Chapters:/.test(line)) inChapters = true;
|
|
14109
|
+
if (STREAM_LINE.test(line)) inChapters = false;
|
|
14110
|
+
if (/DOVI configuration record/.test(line) && streams.length > 0) {
|
|
14111
|
+
doviSeenFor = streams.length - 1;
|
|
14112
|
+
continue;
|
|
14113
|
+
}
|
|
14114
|
+
const match = STREAM_LINE.exec(line);
|
|
14115
|
+
if (!match) continue;
|
|
14116
|
+
const [, indexText, lang, kindText, rest] = match;
|
|
14117
|
+
if (indexText === void 0 || kindText === void 0 || rest === void 0) continue;
|
|
14118
|
+
const kind = kindText === "Video" ? "video" : kindText === "Audio" ? "audio" : "subtitle";
|
|
14119
|
+
const codecMatch = /^([A-Za-z0-9_]+)(?: \(([^)]*)\))?/.exec(rest);
|
|
14120
|
+
const codec = codecMatch?.[1] ?? "unknown";
|
|
14121
|
+
const rawProfile = codecMatch?.[2];
|
|
14122
|
+
const profile = kind !== "subtitle" && rawProfile !== void 0 && !/ 0x|^(default|forced)$/.test(rawProfile) ? rawProfile : null;
|
|
14123
|
+
const pixFmt = kind === "video" ? /\b(yuv[a-z0-9]*|nv\d+[a-z0-9]*|gray[a-z0-9]*|rgb[a-z0-9]*|bgr[a-z0-9]*)\b/.exec(rest)?.[1] ?? null : null;
|
|
14124
|
+
const size = kind === "video" ? /\b(\d{2,5})x(\d{2,5})\b/.exec(rest) : null;
|
|
14125
|
+
streams.push({
|
|
14126
|
+
index: Number(indexText),
|
|
14127
|
+
kind,
|
|
14128
|
+
codec,
|
|
14129
|
+
profile,
|
|
14130
|
+
language: languageOf(lang),
|
|
14131
|
+
channels: kind === "audio" ? channelsOf(rest) : null,
|
|
14132
|
+
bitDepth: kind === "video" ? bitDepthOf(pixFmt) : null,
|
|
14133
|
+
hdr: kind === "video" ? hdrOf(rest, false) : null,
|
|
14134
|
+
width: size?.[1] !== void 0 ? Number(size[1]) : null,
|
|
14135
|
+
height: size?.[2] !== void 0 ? Number(size[2]) : null,
|
|
14136
|
+
isDefault: /\(default\)/.test(rest),
|
|
14137
|
+
isForced: /\(forced\)/.test(rest)
|
|
14138
|
+
});
|
|
14139
|
+
}
|
|
14140
|
+
if (doviSeenFor !== null) {
|
|
14141
|
+
const target = streams[doviSeenFor];
|
|
14142
|
+
if (target?.kind === "video") streams[doviSeenFor] = {
|
|
14143
|
+
...target,
|
|
14144
|
+
hdr: "dolby-vision"
|
|
14308
14145
|
};
|
|
14309
|
-
|
|
14310
|
-
|
|
14311
|
-
|
|
14146
|
+
}
|
|
14147
|
+
return {
|
|
14148
|
+
container,
|
|
14149
|
+
durationMs,
|
|
14150
|
+
streams,
|
|
14151
|
+
chapters
|
|
14312
14152
|
};
|
|
14313
|
-
|
|
14314
|
-
|
|
14315
|
-
|
|
14316
|
-
|
|
14317
|
-
|
|
14318
|
-
|
|
14319
|
-
|
|
14320
|
-
|
|
14321
|
-
|
|
14322
|
-
|
|
14323
|
-
|
|
14153
|
+
}
|
|
14154
|
+
var PROBE_TIMEOUT_MS = 3e4;
|
|
14155
|
+
var REPORT_MAX_BYTES = 1024 * 1024;
|
|
14156
|
+
/**
|
|
14157
|
+
* ONE ffmpeg per file, reading the input report. ffmpeg exits non-zero with no output file
|
|
14158
|
+
* (the report is on stderr), so a non-zero exit is expected and only a missing report is a failure.
|
|
14159
|
+
*/
|
|
14160
|
+
function createFfmpegProber(binaryPath) {
|
|
14161
|
+
return (path) => new Promise((resolve, reject) => {
|
|
14162
|
+
(0, node_child_process.execFile)(binaryPath, [
|
|
14163
|
+
"-hide_banner",
|
|
14164
|
+
"-nostdin",
|
|
14165
|
+
"-i",
|
|
14166
|
+
path
|
|
14167
|
+
], {
|
|
14168
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
14169
|
+
maxBuffer: REPORT_MAX_BYTES,
|
|
14170
|
+
encoding: "utf8"
|
|
14171
|
+
}, (error, _stdout, stderr) => {
|
|
14172
|
+
if (error !== null && (error.killed === true || stderr === "")) {
|
|
14173
|
+
reject(new Error(error.killed === true ? "probe timed out" : error.message));
|
|
14174
|
+
return;
|
|
14175
|
+
}
|
|
14176
|
+
const result = parseFfmpegReport(stderr);
|
|
14177
|
+
if (result.streams.length === 0) reject(/* @__PURE__ */ new Error("no streams in the report"));
|
|
14178
|
+
else resolve(result);
|
|
14179
|
+
});
|
|
14324
14180
|
});
|
|
14181
|
+
}
|
|
14182
|
+
//#endregion
|
|
14183
|
+
//#region src/provider.ts
|
|
14184
|
+
/** The `media-library` capability over the store. A caller reads and writes only their own progress. */
|
|
14185
|
+
function createMediaLibraryProvider(store, scans) {
|
|
14325
14186
|
return {
|
|
14326
|
-
|
|
14327
|
-
|
|
14328
|
-
|
|
14329
|
-
|
|
14330
|
-
|
|
14331
|
-
|
|
14332
|
-
|
|
14333
|
-
|
|
14334
|
-
|
|
14335
|
-
|
|
14336
|
-
|
|
14337
|
-
},
|
|
14338
|
-
|
|
14339
|
-
|
|
14340
|
-
|
|
14341
|
-
|
|
14342
|
-
const hit = sameYear ?? (year === null || top !== void 0 && foldTitle(top.show.name) === foldTitle(title) ? top : void 0);
|
|
14343
|
-
if (hit === void 0) return null;
|
|
14344
|
-
const show = hit.show;
|
|
14345
|
-
return {
|
|
14346
|
-
providerId: TVMAZE_ID,
|
|
14347
|
-
remoteId: String(show.id),
|
|
14348
|
-
title: show.name,
|
|
14349
|
-
year: yearOf(show.premiered),
|
|
14350
|
-
overview: plain(show.summary),
|
|
14351
|
-
tvdbId: show.externals?.thetvdb ?? null,
|
|
14352
|
-
tmdbId: null,
|
|
14353
|
-
imdbId: show.externals?.imdb ?? null,
|
|
14354
|
-
poster: imageOf(show.image),
|
|
14355
|
-
fanart: null
|
|
14356
|
-
};
|
|
14357
|
-
},
|
|
14358
|
-
async episodes(match) {
|
|
14359
|
-
return array(EpisodeSchema).parse(await call(`/shows/${encodeURIComponent(match.remoteId)}/episodes?specials=1`)).flatMap((entry) => entry.number === null || entry.number === void 0 ? [] : [{
|
|
14360
|
-
season: entry.season,
|
|
14361
|
-
episode: entry.number,
|
|
14362
|
-
title: entry.name ?? null,
|
|
14363
|
-
overview: plain(entry.summary),
|
|
14364
|
-
still: imageOf(entry.image)
|
|
14365
|
-
}]);
|
|
14366
|
-
}
|
|
14187
|
+
listSeries: ({ limit, offset, language, caller }) => store.listSeries(caller.userId, limit, offset, language),
|
|
14188
|
+
listMovies: ({ limit, offset, language, caller }) => store.listMovies(caller.userId, limit, offset, language),
|
|
14189
|
+
listSeasons: ({ seriesId, caller }) => store.listSeasons(caller.userId, seriesId),
|
|
14190
|
+
listEpisodes: ({ seriesId, seasonNumber, language, caller }) => store.listEpisodes(caller.userId, seriesId, seasonNumber, language),
|
|
14191
|
+
getItem: ({ itemId, language, caller }) => store.getItem(caller.userId, itemId, language),
|
|
14192
|
+
search: ({ query, limit, language, caller }) => store.search(caller.userId, query, limit, language),
|
|
14193
|
+
listRecentlyAdded: ({ limit, language, caller }) => store.listRecentlyAdded(caller.userId, limit, language),
|
|
14194
|
+
listWatchlist: ({ limit, offset, language, caller }) => store.listWatchlist(caller.userId, limit, offset, language),
|
|
14195
|
+
setWatchlisted: ({ itemId, on, caller }) => store.setWatchlisted(caller.userId, itemId, on),
|
|
14196
|
+
getItemDetails: ({ itemId, language }) => store.getItemDetails(itemId, language),
|
|
14197
|
+
getProgress: ({ itemId, caller }) => store.getProgress(caller.userId, itemId),
|
|
14198
|
+
setProgress: ({ caller, ...input }) => store.setProgress(caller.userId, input),
|
|
14199
|
+
markWatched: ({ caller, ...input }) => store.markWatched(caller.userId, input),
|
|
14200
|
+
listContinue: ({ limit, language, caller }) => store.listContinue(caller.userId, limit, language),
|
|
14201
|
+
rescan: async () => ({ started: scans.start("manual") }),
|
|
14202
|
+
getScanStatus: async () => scans.status()
|
|
14367
14203
|
};
|
|
14368
14204
|
}
|
|
14369
14205
|
//#endregion
|
|
14370
|
-
//#region src/
|
|
14371
|
-
|
|
14372
|
-
var
|
|
14373
|
-
/**
|
|
14374
|
-
|
|
14375
|
-
const
|
|
14376
|
-
|
|
14377
|
-
|
|
14378
|
-
|
|
14379
|
-
|
|
14380
|
-
|
|
14381
|
-
|
|
14382
|
-
|
|
14383
|
-
|
|
14384
|
-
|
|
14385
|
-
|
|
14386
|
-
if (bytes.length > 8 && bytes.subarray(1, 4).toString("latin1") === "PNG") return "image/png";
|
|
14387
|
-
if (bytes.length > 12 && bytes.subarray(8, 12).toString("latin1") === "WEBP") return "image/webp";
|
|
14388
|
-
return null;
|
|
14206
|
+
//#region src/settings.ts
|
|
14207
|
+
/** The capability that owns the cluster-scoped settings (D986). */
|
|
14208
|
+
var SETTINGS_CAP = "media-library";
|
|
14209
|
+
/** An http(s) base URL without credentials, query or trailing slash; `''` is "not configured"; `null` is invalid. */
|
|
14210
|
+
function normalizeBaseUrl(raw) {
|
|
14211
|
+
const text = raw.trim();
|
|
14212
|
+
if (text === "") return "";
|
|
14213
|
+
let url;
|
|
14214
|
+
try {
|
|
14215
|
+
url = new URL(text);
|
|
14216
|
+
} catch {
|
|
14217
|
+
return null;
|
|
14218
|
+
}
|
|
14219
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
|
|
14220
|
+
if (url.username !== "" || url.password !== "" || url.search !== "" || url.hash !== "") return null;
|
|
14221
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
14389
14222
|
}
|
|
14390
|
-
|
|
14391
|
-
|
|
14392
|
-
|
|
14393
|
-
|
|
14394
|
-
|
|
14395
|
-
|
|
14396
|
-
|
|
14397
|
-
|
|
14398
|
-
const own = new URL(source.baseUrl);
|
|
14399
|
-
return absolute !== null && absolute.origin === own.origin && absolute.username === "" && absolute.password === "" ? absolute.toString() : null;
|
|
14223
|
+
var BaseUrlSchema = string().transform((value, ctx) => {
|
|
14224
|
+
const normalized = normalizeBaseUrl(value);
|
|
14225
|
+
if (normalized === null) {
|
|
14226
|
+
ctx.addIssue({
|
|
14227
|
+
code: "custom",
|
|
14228
|
+
message: "expected an http(s) URL"
|
|
14229
|
+
});
|
|
14230
|
+
return NEVER;
|
|
14400
14231
|
}
|
|
14401
|
-
|
|
14402
|
-
|
|
14403
|
-
|
|
14404
|
-
|
|
14232
|
+
return normalized;
|
|
14233
|
+
});
|
|
14234
|
+
/** The metadata steps, in the order they answer by default: files, the arr app, then online (each needs its key or switch), pictures last. */
|
|
14235
|
+
var METADATA_STEPS = [
|
|
14236
|
+
"local",
|
|
14237
|
+
"arr",
|
|
14238
|
+
"tmdb",
|
|
14239
|
+
"tvmaze",
|
|
14240
|
+
"tvdb",
|
|
14241
|
+
"omdb",
|
|
14242
|
+
"anilist",
|
|
14243
|
+
"fanart"
|
|
14244
|
+
];
|
|
14245
|
+
var DEFAULT_METADATA_ORDER = METADATA_STEPS;
|
|
14246
|
+
/** The steps that cannot answer without the installation's own key. */
|
|
14247
|
+
var KEYED_STEPS = [
|
|
14248
|
+
"tmdb",
|
|
14249
|
+
"tvdb",
|
|
14250
|
+
"omdb",
|
|
14251
|
+
"fanart"
|
|
14252
|
+
];
|
|
14253
|
+
function isStep(value) {
|
|
14254
|
+
return METADATA_STEPS.some((step) => step === value);
|
|
14405
14255
|
}
|
|
14406
|
-
function
|
|
14407
|
-
|
|
14408
|
-
res.end();
|
|
14256
|
+
function isKeyedStep(step) {
|
|
14257
|
+
return KEYED_STEPS.some((keyed) => keyed === step);
|
|
14409
14258
|
}
|
|
14410
|
-
/**
|
|
14411
|
-
|
|
14412
|
-
|
|
14413
|
-
|
|
14414
|
-
|
|
14415
|
-
|
|
14416
|
-
|
|
14417
|
-
|
|
14418
|
-
|
|
14419
|
-
|
|
14420
|
-
|
|
14421
|
-
|
|
14422
|
-
|
|
14423
|
-
|
|
14424
|
-
|
|
14425
|
-
|
|
14426
|
-
|
|
14427
|
-
|
|
14428
|
-
|
|
14429
|
-
|
|
14430
|
-
|
|
14431
|
-
|
|
14432
|
-
|
|
14433
|
-
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14437
|
-
|
|
14438
|
-
|
|
14439
|
-
});
|
|
14440
|
-
return null;
|
|
14441
|
-
}
|
|
14442
|
-
if ((await (0, node_fs_promises.stat)(real)).size > 10485760) throw new Error("image too large");
|
|
14443
|
-
return (0, node_fs_promises.readFile)(real);
|
|
14259
|
+
/** What the settings list shows for each step. */
|
|
14260
|
+
var STEP_NAMES = {
|
|
14261
|
+
local: "Local files",
|
|
14262
|
+
arr: "Sonarr and Radarr",
|
|
14263
|
+
tmdb: "TMDB",
|
|
14264
|
+
tvmaze: "TVmaze",
|
|
14265
|
+
tvdb: "TheTVDB",
|
|
14266
|
+
omdb: "OMDb",
|
|
14267
|
+
anilist: "AniList",
|
|
14268
|
+
fanart: "Fanart.tv"
|
|
14269
|
+
};
|
|
14270
|
+
/** One row of the metadata chain: the row order is the order the steps answer in (D1125). */
|
|
14271
|
+
var MetadataProviderRowSchema = object({
|
|
14272
|
+
/** The step this row is; stable, it addresses the row's secret. */
|
|
14273
|
+
id: string(),
|
|
14274
|
+
/** The step's display name, stamped by the addon for the row title. */
|
|
14275
|
+
name: string().default(""),
|
|
14276
|
+
enabled: boolean().default(true),
|
|
14277
|
+
/** The installation's own key or token, for a keyed step; unused by the others. */
|
|
14278
|
+
apiKey: string().meta({ secret: true }).default("")
|
|
14279
|
+
});
|
|
14280
|
+
/** A row for `step`; AniList needs no account but sends titles out, so it starts off. */
|
|
14281
|
+
function providerRow(step, patch = {}) {
|
|
14282
|
+
return {
|
|
14283
|
+
id: step,
|
|
14284
|
+
name: STEP_NAMES[step],
|
|
14285
|
+
enabled: step !== "anilist",
|
|
14286
|
+
apiKey: "",
|
|
14287
|
+
...patch
|
|
14444
14288
|
};
|
|
14445
|
-
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14451
|
-
|
|
14452
|
-
|
|
14453
|
-
|
|
14454
|
-
|
|
14455
|
-
|
|
14456
|
-
|
|
14457
|
-
|
|
14289
|
+
}
|
|
14290
|
+
/** The list a fresh installation starts from: every step, in the default order. */
|
|
14291
|
+
function defaultProviderRows() {
|
|
14292
|
+
return DEFAULT_METADATA_ORDER.map((step) => providerRow(step));
|
|
14293
|
+
}
|
|
14294
|
+
/** A keyed row answers only with a key; the other steps need none. */
|
|
14295
|
+
function rowAnswers(row, step) {
|
|
14296
|
+
return row.enabled && (!isKeyedStep(step) || row.apiKey.trim() !== "");
|
|
14297
|
+
}
|
|
14298
|
+
/** The steps that are on, in the list's order; a step with no row is off, an unknown id is ignored, a keyed row without its key is skipped. */
|
|
14299
|
+
function resolveMetadataSteps(settings) {
|
|
14300
|
+
const out = [];
|
|
14301
|
+
for (const row of settings.metadataProviders) {
|
|
14302
|
+
const step = row.id.toLowerCase();
|
|
14303
|
+
if (isStep(step) && rowAnswers(row, step) && !out.includes(step)) out.push(step);
|
|
14304
|
+
}
|
|
14305
|
+
return out;
|
|
14306
|
+
}
|
|
14307
|
+
/** The key of a keyed step, or `''` when the step is not answering. */
|
|
14308
|
+
function keyOf(settings, step) {
|
|
14309
|
+
if (!resolveMetadataSteps(settings).includes(step)) return "";
|
|
14310
|
+
return settings.metadataProviders.find((candidate) => candidate.id.toLowerCase() === step)?.apiKey.trim() ?? "";
|
|
14311
|
+
}
|
|
14312
|
+
var PROVIDERS_GUIDE_EN = "<p>Each online provider needs a key of your own account; no key ships with Dominevo. Titles and ids of your library are sent to a provider to look them up. A row that needs a key and has none is skipped.</p><ul><li><strong>TMDB</strong>: <a href=\"https://www.themoviedb.org/signup\">themoviedb.org</a>, then Settings, API: request a Developer key (personal use) and copy the <strong>API Read Access Token</strong> (the long one, not the short API Key).</li><li><strong>TheTVDB</strong>: <a href=\"https://thetvdb.com/\">thetvdb.com</a>, then your dashboard: create a v4 API key (free for personal use).</li><li><strong>OMDb</strong>: <a href=\"https://www.omdbapi.com/apikey.aspx\">omdbapi.com/apikey.aspx</a>: the free key allows 1,000 requests a day.</li><li><strong>Fanart.tv</strong>: <a href=\"https://fanart.tv/\">fanart.tv</a>, then your profile: copy the personal API key. It only adds posters and backgrounds.</li></ul>Local files, Sonarr and Radarr, TVmaze and AniList need no key.";
|
|
14313
|
+
var MediaLibrarySettingsSchema = object({
|
|
14314
|
+
seriesArrUrl: BaseUrlSchema.default(""),
|
|
14315
|
+
seriesArrKey: string().default(""),
|
|
14316
|
+
/** Where the series app sees the library, and where this node mounts it. */
|
|
14317
|
+
seriesPathFrom: string().default(""),
|
|
14318
|
+
seriesPathTo: string().default(""),
|
|
14319
|
+
moviesArrUrl: BaseUrlSchema.default(""),
|
|
14320
|
+
moviesArrKey: string().default(""),
|
|
14321
|
+
moviesPathFrom: string().default(""),
|
|
14322
|
+
moviesPathTo: string().default(""),
|
|
14323
|
+
/** Plain folders walked for files the arr apps do not know, one absolute path per line. */
|
|
14324
|
+
folderRoots: string().default(""),
|
|
14325
|
+
rescanMinutes: number().int().min(0).default(60),
|
|
14326
|
+
/** Scrub thumbnails, generated in the background with ffmpeg and cached under the addon's data dir. */
|
|
14327
|
+
trickplay: boolean().default(true),
|
|
14328
|
+
/** The metadata chain, one row per step in the order they answer; the first answer to a field wins (D1125). */
|
|
14329
|
+
metadataProviders: array(MetadataProviderRowSchema).default(defaultProviderRows),
|
|
14330
|
+
/** The Plex import (a one-shot, re-runnable action): the server, a token, and how paths and users line up. */
|
|
14331
|
+
plexUrl: BaseUrlSchema.default(""),
|
|
14332
|
+
plexToken: string().meta({ secret: true }).default(""),
|
|
14333
|
+
plexPathFrom: string().default(""),
|
|
14334
|
+
plexPathTo: string().default(""),
|
|
14335
|
+
plexUserMap: string().default("")
|
|
14336
|
+
});
|
|
14337
|
+
/** A source is on only when both its URL and key are set; a half-filled one is off, not guessed. */
|
|
14338
|
+
function resolveSources(settings) {
|
|
14339
|
+
const pick = (baseUrl, apiKey, pathFrom, pathTo) => baseUrl === "" || apiKey === "" ? null : {
|
|
14340
|
+
baseUrl,
|
|
14341
|
+
apiKey,
|
|
14342
|
+
pathFrom: pathFrom.trim(),
|
|
14343
|
+
pathTo: pathTo.trim()
|
|
14458
14344
|
};
|
|
14459
|
-
|
|
14460
|
-
|
|
14461
|
-
|
|
14462
|
-
|
|
14463
|
-
|
|
14464
|
-
|
|
14345
|
+
return {
|
|
14346
|
+
series: pick(settings.seriesArrUrl, settings.seriesArrKey, settings.seriesPathFrom, settings.seriesPathTo),
|
|
14347
|
+
movies: pick(settings.moviesArrUrl, settings.moviesArrKey, settings.moviesPathFrom, settings.moviesPathTo),
|
|
14348
|
+
folderRoots: settings.folderRoots.split("\n").map((line) => line.trim()).filter((line) => line !== ""),
|
|
14349
|
+
metadataSteps: resolveMetadataSteps(settings),
|
|
14350
|
+
tmdbToken: keyOf(settings, "tmdb"),
|
|
14351
|
+
tvdbApiKey: keyOf(settings, "tvdb"),
|
|
14352
|
+
fanartApiKey: keyOf(settings, "fanart"),
|
|
14353
|
+
omdbApiKey: keyOf(settings, "omdb")
|
|
14465
14354
|
};
|
|
14466
|
-
|
|
14467
|
-
|
|
14468
|
-
|
|
14469
|
-
|
|
14470
|
-
|
|
14471
|
-
|
|
14472
|
-
|
|
14473
|
-
|
|
14474
|
-
|
|
14475
|
-
|
|
14476
|
-
|
|
14477
|
-
|
|
14355
|
+
}
|
|
14356
|
+
/** The import is configured only when both the server URL and the token are set. */
|
|
14357
|
+
function resolvePlex(settings) {
|
|
14358
|
+
if (settings.plexUrl === "" || settings.plexToken === "") return null;
|
|
14359
|
+
return {
|
|
14360
|
+
baseUrl: settings.plexUrl,
|
|
14361
|
+
token: settings.plexToken,
|
|
14362
|
+
pathFrom: settings.plexPathFrom.trim(),
|
|
14363
|
+
pathTo: settings.plexPathTo.trim(),
|
|
14364
|
+
userMap: settings.plexUserMap
|
|
14365
|
+
};
|
|
14366
|
+
}
|
|
14367
|
+
var MEDIA_LIBRARY_CLUSTER_SCHEMA = { sections: [
|
|
14368
|
+
{
|
|
14369
|
+
id: "series",
|
|
14370
|
+
title: "Series source",
|
|
14371
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.title",
|
|
14372
|
+
fields: [
|
|
14373
|
+
{
|
|
14374
|
+
type: "text",
|
|
14375
|
+
key: "seriesArrUrl",
|
|
14376
|
+
label: "Sonarr URL",
|
|
14377
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrUrl.label",
|
|
14378
|
+
description: "Address of the series app, for example http://192.168.1.20:8989. Empty turns the source off.",
|
|
14379
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrUrl.description"
|
|
14380
|
+
},
|
|
14381
|
+
{
|
|
14382
|
+
type: "password",
|
|
14383
|
+
key: "seriesArrKey",
|
|
14384
|
+
label: "Sonarr API key",
|
|
14385
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrKey.label"
|
|
14386
|
+
},
|
|
14387
|
+
{
|
|
14388
|
+
type: "text",
|
|
14389
|
+
key: "seriesPathFrom",
|
|
14390
|
+
label: "Path in Sonarr",
|
|
14391
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathFrom.label",
|
|
14392
|
+
description: "The library folder as the series app sees it, for example /tv.",
|
|
14393
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathFrom.description"
|
|
14394
|
+
},
|
|
14395
|
+
{
|
|
14396
|
+
type: "text",
|
|
14397
|
+
key: "seriesPathTo",
|
|
14398
|
+
label: "Path on this hub",
|
|
14399
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathTo.label",
|
|
14400
|
+
description: "Where the same folder is mounted on this hub.",
|
|
14401
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathTo.description"
|
|
14402
|
+
}
|
|
14403
|
+
]
|
|
14404
|
+
},
|
|
14405
|
+
{
|
|
14406
|
+
id: "movies",
|
|
14407
|
+
title: "Movies source",
|
|
14408
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.title",
|
|
14409
|
+
fields: [
|
|
14410
|
+
{
|
|
14411
|
+
type: "text",
|
|
14412
|
+
key: "moviesArrUrl",
|
|
14413
|
+
label: "Radarr URL",
|
|
14414
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrUrl.label",
|
|
14415
|
+
description: "Address of the movies app, for example http://192.168.1.20:7878. Empty turns the source off.",
|
|
14416
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrUrl.description"
|
|
14417
|
+
},
|
|
14418
|
+
{
|
|
14419
|
+
type: "password",
|
|
14420
|
+
key: "moviesArrKey",
|
|
14421
|
+
label: "Radarr API key",
|
|
14422
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrKey.label"
|
|
14423
|
+
},
|
|
14424
|
+
{
|
|
14425
|
+
type: "text",
|
|
14426
|
+
key: "moviesPathFrom",
|
|
14427
|
+
label: "Path in Radarr",
|
|
14428
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathFrom.label",
|
|
14429
|
+
description: "The library folder as the movies app sees it, for example /movies.",
|
|
14430
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathFrom.description"
|
|
14431
|
+
},
|
|
14432
|
+
{
|
|
14433
|
+
type: "text",
|
|
14434
|
+
key: "moviesPathTo",
|
|
14435
|
+
label: "Path on this hub",
|
|
14436
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathTo.label",
|
|
14437
|
+
description: "Where the same folder is mounted on this hub.",
|
|
14438
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathTo.description"
|
|
14439
|
+
}
|
|
14440
|
+
]
|
|
14441
|
+
},
|
|
14442
|
+
{
|
|
14443
|
+
id: "folders",
|
|
14444
|
+
title: "Folders",
|
|
14445
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.title",
|
|
14446
|
+
fields: [
|
|
14447
|
+
{
|
|
14448
|
+
type: "textarea",
|
|
14449
|
+
key: "folderRoots",
|
|
14450
|
+
label: "Folders to walk",
|
|
14451
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.folderRoots.label",
|
|
14452
|
+
description: "One absolute path per line. Files the arr apps do not know are added from here.",
|
|
14453
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.folderRoots.description"
|
|
14454
|
+
},
|
|
14455
|
+
{
|
|
14456
|
+
type: "number",
|
|
14457
|
+
key: "rescanMinutes",
|
|
14458
|
+
label: "Rescan every (minutes)",
|
|
14459
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.rescanMinutes.label",
|
|
14460
|
+
description: "0 scans only when asked.",
|
|
14461
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.rescanMinutes.description",
|
|
14462
|
+
min: 0
|
|
14463
|
+
},
|
|
14464
|
+
{
|
|
14465
|
+
type: "boolean",
|
|
14466
|
+
key: "trickplay",
|
|
14467
|
+
label: "Scrub thumbnails",
|
|
14468
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.trickplay.label",
|
|
14469
|
+
description: "Generate preview pictures for the seek bar in the background, one ffmpeg at a time at low priority.",
|
|
14470
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.trickplay.description"
|
|
14471
|
+
}
|
|
14472
|
+
]
|
|
14473
|
+
},
|
|
14474
|
+
{
|
|
14475
|
+
id: "metadata",
|
|
14476
|
+
title: "Metadata",
|
|
14477
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.title",
|
|
14478
|
+
fields: [{
|
|
14479
|
+
type: "info",
|
|
14480
|
+
key: "providersGuide",
|
|
14481
|
+
label: "How to get the keys",
|
|
14482
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.providersGuide.label",
|
|
14483
|
+
format: "html",
|
|
14484
|
+
content: PROVIDERS_GUIDE_EN,
|
|
14485
|
+
contentKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.providersGuide.content"
|
|
14486
|
+
}, {
|
|
14487
|
+
type: "editable-array",
|
|
14488
|
+
key: "metadataProviders",
|
|
14489
|
+
label: "Metadata providers",
|
|
14490
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.label",
|
|
14491
|
+
description: "Asked from the top down: the first answer to a field wins. Move a row to change the order. A provider that needs a key and has none is skipped.",
|
|
14492
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.description",
|
|
14493
|
+
default: defaultProviderRows(),
|
|
14494
|
+
reorderable: true,
|
|
14495
|
+
fixedRows: true,
|
|
14496
|
+
itemIdKey: "id",
|
|
14497
|
+
rowTitleTemplate: "{name}",
|
|
14498
|
+
itemFields: [
|
|
14499
|
+
{
|
|
14500
|
+
type: "text",
|
|
14501
|
+
key: "id",
|
|
14502
|
+
label: "Provider",
|
|
14503
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.id.label",
|
|
14504
|
+
showWhen: {
|
|
14505
|
+
field: "id",
|
|
14506
|
+
equals: ""
|
|
14507
|
+
}
|
|
14508
|
+
},
|
|
14509
|
+
{
|
|
14510
|
+
type: "text",
|
|
14511
|
+
key: "name",
|
|
14512
|
+
label: "Name",
|
|
14513
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.name.label",
|
|
14514
|
+
showWhen: {
|
|
14515
|
+
field: "id",
|
|
14516
|
+
equals: ""
|
|
14517
|
+
}
|
|
14518
|
+
},
|
|
14519
|
+
{
|
|
14520
|
+
type: "boolean",
|
|
14521
|
+
key: "enabled",
|
|
14522
|
+
label: "Use this provider",
|
|
14523
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.enabled.label"
|
|
14524
|
+
},
|
|
14525
|
+
{
|
|
14526
|
+
type: "password",
|
|
14527
|
+
key: "apiKey",
|
|
14528
|
+
label: "API key or token",
|
|
14529
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.apiKey.label",
|
|
14530
|
+
description: "The key of your own account, stored in the keychain. Without it this provider is skipped.",
|
|
14531
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.apiKey.description",
|
|
14532
|
+
showWhen: {
|
|
14533
|
+
field: "id",
|
|
14534
|
+
in: [...KEYED_STEPS]
|
|
14535
|
+
}
|
|
14478
14536
|
}
|
|
14479
|
-
|
|
14480
|
-
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
|
-
|
|
14500
|
-
|
|
14501
|
-
|
|
14502
|
-
|
|
14503
|
-
|
|
14504
|
-
|
|
14505
|
-
|
|
14506
|
-
|
|
14507
|
-
|
|
14508
|
-
|
|
14537
|
+
]
|
|
14538
|
+
}]
|
|
14539
|
+
},
|
|
14540
|
+
{
|
|
14541
|
+
id: "plex",
|
|
14542
|
+
title: "Import from Plex",
|
|
14543
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.title",
|
|
14544
|
+
fields: [
|
|
14545
|
+
{
|
|
14546
|
+
type: "text",
|
|
14547
|
+
key: "plexUrl",
|
|
14548
|
+
label: "Plex server URL",
|
|
14549
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUrl.label",
|
|
14550
|
+
description: "Address of the Plex Media Server, for example http://192.168.1.20:32400. Used only when you press Preview or Import: nothing is linked or kept in sync.",
|
|
14551
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUrl.description"
|
|
14552
|
+
},
|
|
14553
|
+
{
|
|
14554
|
+
type: "password",
|
|
14555
|
+
key: "plexToken",
|
|
14556
|
+
label: "Plex token",
|
|
14557
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexToken.label",
|
|
14558
|
+
description: "The server owner's X-Plex-Token. Stored in the keychain.",
|
|
14559
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexToken.description"
|
|
14560
|
+
},
|
|
14561
|
+
{
|
|
14562
|
+
type: "text",
|
|
14563
|
+
key: "plexPathFrom",
|
|
14564
|
+
label: "Path in Plex",
|
|
14565
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathFrom.label",
|
|
14566
|
+
description: "The library folder as Plex sees it, for example /data/movies. Used to match files by path when the ids do not match.",
|
|
14567
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathFrom.description"
|
|
14568
|
+
},
|
|
14569
|
+
{
|
|
14570
|
+
type: "text",
|
|
14571
|
+
key: "plexPathTo",
|
|
14572
|
+
label: "Path on this hub",
|
|
14573
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathTo.label",
|
|
14574
|
+
description: "Where the same folder is mounted on this hub.",
|
|
14575
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathTo.description"
|
|
14576
|
+
},
|
|
14577
|
+
{
|
|
14578
|
+
type: "textarea",
|
|
14579
|
+
key: "plexUserMap",
|
|
14580
|
+
label: "Plex user to Dominevo user",
|
|
14581
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUserMap.label",
|
|
14582
|
+
description: "One \"plexName = dominevoUsername\" per line. Without a line a Plex user is matched by username, title or email.",
|
|
14583
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUserMap.description"
|
|
14584
|
+
},
|
|
14585
|
+
{
|
|
14586
|
+
type: "addon-action-button",
|
|
14587
|
+
addonId: "media-library",
|
|
14588
|
+
key: "__plex-import-preview",
|
|
14589
|
+
label: "Preview the Plex import",
|
|
14590
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-preview.label",
|
|
14591
|
+
description: "Reads Plex and works out what would be imported per user. Writes nothing. Save the settings first.",
|
|
14592
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-preview.description",
|
|
14593
|
+
buttonLabel: "Preview",
|
|
14594
|
+
action: "plexImportPreview",
|
|
14595
|
+
successMessage: "{message}"
|
|
14596
|
+
},
|
|
14597
|
+
{
|
|
14598
|
+
type: "addon-action-button",
|
|
14599
|
+
addonId: "media-library",
|
|
14600
|
+
key: "__plex-import-run",
|
|
14601
|
+
label: "Import from Plex",
|
|
14602
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-run.label",
|
|
14603
|
+
description: "Imports watched state, resume positions and Plex's TMDB/TVDB/IMDb ids. Safe to run again: a newer Dominevo position is never overwritten.",
|
|
14604
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-run.description",
|
|
14605
|
+
buttonLabel: "Import",
|
|
14606
|
+
action: "plexImportRun",
|
|
14607
|
+
variant: "primary",
|
|
14608
|
+
confirmMessage: "Import watch history and ids from Plex now?",
|
|
14609
|
+
successMessage: "{message}"
|
|
14509
14610
|
}
|
|
14510
|
-
|
|
14511
|
-
deps.logger.warn(found.kind === "frame" ? "frame grab failed" : "image fetch failed", {
|
|
14512
|
-
tags,
|
|
14513
|
-
meta: {
|
|
14514
|
-
reason: found.kind === "frame" ? "grab-failed" : "fetch-failed",
|
|
14515
|
-
error: error instanceof Error ? error.message : String(error)
|
|
14516
|
-
}
|
|
14517
|
-
});
|
|
14518
|
-
return null;
|
|
14519
|
-
}
|
|
14520
|
-
};
|
|
14521
|
-
return async (req, res) => {
|
|
14522
|
-
if (req.method !== "GET" && req.method !== "HEAD") return end(res, 405);
|
|
14523
|
-
const parts = ((req.url ?? "/").split("?")[0] ?? "/").replace(/^\//, "").split("/");
|
|
14524
|
-
const [rawId, which] = parts;
|
|
14525
|
-
let itemId = "";
|
|
14526
|
-
try {
|
|
14527
|
-
itemId = decodeURIComponent(rawId ?? "");
|
|
14528
|
-
} catch {
|
|
14529
|
-
return end(res, 404);
|
|
14530
|
-
}
|
|
14531
|
-
if (parts.length !== 2 || !isItemId(itemId) || !isImageKind(which)) {
|
|
14532
|
-
deps.logger.warn("image request refused", { meta: { reason: "bad-request" } });
|
|
14533
|
-
return end(res, 404);
|
|
14534
|
-
}
|
|
14535
|
-
const flightKey = `${itemId}:${which}`;
|
|
14536
|
-
const pending = inFlight.get(flightKey) ?? load(itemId, which);
|
|
14537
|
-
inFlight.set(flightKey, pending);
|
|
14538
|
-
let bytes;
|
|
14539
|
-
try {
|
|
14540
|
-
bytes = await pending;
|
|
14541
|
-
} finally {
|
|
14542
|
-
inFlight.delete(flightKey);
|
|
14543
|
-
}
|
|
14544
|
-
const contentType = bytes === null ? null : typeOf(bytes);
|
|
14545
|
-
if (bytes === null || contentType === null) return end(res, 404);
|
|
14546
|
-
res.writeHead(200, {
|
|
14547
|
-
"Content-Type": contentType,
|
|
14548
|
-
"Content-Length": bytes.length,
|
|
14549
|
-
"Cache-Control": "private, max-age=86400"
|
|
14550
|
-
});
|
|
14551
|
-
res.end(req.method === "HEAD" ? void 0 : bytes);
|
|
14552
|
-
};
|
|
14553
|
-
}
|
|
14554
|
-
//#endregion
|
|
14555
|
-
//#region src/probe.ts
|
|
14556
|
-
var CONTAINER_NAMES = new Map([
|
|
14557
|
-
["matroska", "mkv"],
|
|
14558
|
-
["mov", "mp4"],
|
|
14559
|
-
["avi", "avi"],
|
|
14560
|
-
["mpegts", "ts"]
|
|
14561
|
-
]);
|
|
14562
|
-
function containerOf(formats) {
|
|
14563
|
-
const first = formats.split(",")[0]?.trim() ?? formats;
|
|
14564
|
-
return CONTAINER_NAMES.get(first) ?? first;
|
|
14565
|
-
}
|
|
14566
|
-
function languageOf(tag) {
|
|
14567
|
-
if (tag === void 0 || tag === "" || tag === "und") return null;
|
|
14568
|
-
return tag;
|
|
14569
|
-
}
|
|
14570
|
-
function bitDepthOf(pixFmt) {
|
|
14571
|
-
if (pixFmt === null) return null;
|
|
14572
|
-
const match = /(?:p|le|be)(9|10|12|14|16)(?:le|be)?$/.exec(pixFmt);
|
|
14573
|
-
if (match?.[1] !== void 0) return Number(match[1]);
|
|
14574
|
-
return /^(yuv|nv|gray|rgb|bgr)/.test(pixFmt) ? 8 : null;
|
|
14575
|
-
}
|
|
14576
|
-
function hdrOf(line, doviSeen) {
|
|
14577
|
-
if (doviSeen) return "dolby-vision";
|
|
14578
|
-
if (line.includes("smpte2084")) return "hdr10";
|
|
14579
|
-
if (line.includes("arib-std-b67")) return "hlg";
|
|
14580
|
-
return null;
|
|
14581
|
-
}
|
|
14582
|
-
function channelsOf(line) {
|
|
14583
|
-
if (/\bmono\b/.test(line)) return 1;
|
|
14584
|
-
if (/\bstereo\b/.test(line)) return 2;
|
|
14585
|
-
const layout = /\b(\d)\.(\d)(?:\([a-z]+\))?/.exec(line);
|
|
14586
|
-
if (layout?.[1] !== void 0 && layout[2] !== void 0) return Number(layout[1]) + Number(layout[2]);
|
|
14587
|
-
const count = /\b(\d+) channels\b/.exec(line);
|
|
14588
|
-
return count?.[1] !== void 0 ? Number(count[1]) : null;
|
|
14589
|
-
}
|
|
14590
|
-
var STREAM_LINE = /^\s*Stream #\d+:(\d+)(?:\[[^\]]*\])?(?:\(([^)]*)\))?[^:]*: (Video|Audio|Subtitle): (.*)$/;
|
|
14591
|
-
var CHAPTER_LINE = /^\s*Chapter #\d+:\d+: start ([\d.]+), end ([\d.]+)/;
|
|
14592
|
-
var CHAPTER_TITLE = /^\s+title\s*:\s*(.*)$/;
|
|
14593
|
-
/** Parse the report `ffmpeg -i <file>` prints on stderr. A report that is not one yields no streams and no duration. */
|
|
14594
|
-
function parseFfmpegReport(report) {
|
|
14595
|
-
const lines = report.split("\n");
|
|
14596
|
-
let container = null;
|
|
14597
|
-
let durationMs = null;
|
|
14598
|
-
const streams = [];
|
|
14599
|
-
const chapters = [];
|
|
14600
|
-
let doviSeenFor = null;
|
|
14601
|
-
let inChapters = false;
|
|
14602
|
-
for (const line of lines) {
|
|
14603
|
-
const input = /^Input #\d+, ([^,]+(?:,[^,]+)*), from /.exec(line);
|
|
14604
|
-
if (input?.[1] !== void 0 && container === null) container = containerOf(input[1]);
|
|
14605
|
-
const duration = /^\s*Duration: (\d+):(\d{2}):(\d{2})\.(\d{2})/.exec(line);
|
|
14606
|
-
if (duration && durationMs === null) durationMs = (Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3])) * 1e3 + Number(duration[4]) * 10;
|
|
14607
|
-
const chapter = CHAPTER_LINE.exec(line);
|
|
14608
|
-
if (chapter?.[1] !== void 0 && chapter[2] !== void 0) {
|
|
14609
|
-
const startSec = Number(chapter[1]);
|
|
14610
|
-
const endSec = Number(chapter[2]);
|
|
14611
|
-
if (Number.isFinite(startSec) && Number.isFinite(endSec) && endSec > startSec) chapters.push({
|
|
14612
|
-
startSec,
|
|
14613
|
-
endSec,
|
|
14614
|
-
title: null
|
|
14615
|
-
});
|
|
14616
|
-
continue;
|
|
14617
|
-
}
|
|
14618
|
-
const titled = CHAPTER_TITLE.exec(line);
|
|
14619
|
-
const last = chapters[chapters.length - 1];
|
|
14620
|
-
if (titled?.[1] !== void 0 && last !== void 0 && last.title === null && inChapters) {
|
|
14621
|
-
if (titled[1].trim() !== "") chapters[chapters.length - 1] = {
|
|
14622
|
-
...last,
|
|
14623
|
-
title: titled[1].trim()
|
|
14624
|
-
};
|
|
14625
|
-
continue;
|
|
14626
|
-
}
|
|
14627
|
-
if (/^\s*Chapters:/.test(line)) inChapters = true;
|
|
14628
|
-
if (STREAM_LINE.test(line)) inChapters = false;
|
|
14629
|
-
if (/DOVI configuration record/.test(line) && streams.length > 0) {
|
|
14630
|
-
doviSeenFor = streams.length - 1;
|
|
14631
|
-
continue;
|
|
14632
|
-
}
|
|
14633
|
-
const match = STREAM_LINE.exec(line);
|
|
14634
|
-
if (!match) continue;
|
|
14635
|
-
const [, indexText, lang, kindText, rest] = match;
|
|
14636
|
-
if (indexText === void 0 || kindText === void 0 || rest === void 0) continue;
|
|
14637
|
-
const kind = kindText === "Video" ? "video" : kindText === "Audio" ? "audio" : "subtitle";
|
|
14638
|
-
const codecMatch = /^([A-Za-z0-9_]+)(?: \(([^)]*)\))?/.exec(rest);
|
|
14639
|
-
const codec = codecMatch?.[1] ?? "unknown";
|
|
14640
|
-
const rawProfile = codecMatch?.[2];
|
|
14641
|
-
const profile = kind !== "subtitle" && rawProfile !== void 0 && !/ 0x|^(default|forced)$/.test(rawProfile) ? rawProfile : null;
|
|
14642
|
-
const pixFmt = kind === "video" ? /\b(yuv[a-z0-9]*|nv\d+[a-z0-9]*|gray[a-z0-9]*|rgb[a-z0-9]*|bgr[a-z0-9]*)\b/.exec(rest)?.[1] ?? null : null;
|
|
14643
|
-
const size = kind === "video" ? /\b(\d{2,5})x(\d{2,5})\b/.exec(rest) : null;
|
|
14644
|
-
streams.push({
|
|
14645
|
-
index: Number(indexText),
|
|
14646
|
-
kind,
|
|
14647
|
-
codec,
|
|
14648
|
-
profile,
|
|
14649
|
-
language: languageOf(lang),
|
|
14650
|
-
channels: kind === "audio" ? channelsOf(rest) : null,
|
|
14651
|
-
bitDepth: kind === "video" ? bitDepthOf(pixFmt) : null,
|
|
14652
|
-
hdr: kind === "video" ? hdrOf(rest, false) : null,
|
|
14653
|
-
width: size?.[1] !== void 0 ? Number(size[1]) : null,
|
|
14654
|
-
height: size?.[2] !== void 0 ? Number(size[2]) : null,
|
|
14655
|
-
isDefault: /\(default\)/.test(rest),
|
|
14656
|
-
isForced: /\(forced\)/.test(rest)
|
|
14657
|
-
});
|
|
14658
|
-
}
|
|
14659
|
-
if (doviSeenFor !== null) {
|
|
14660
|
-
const target = streams[doviSeenFor];
|
|
14661
|
-
if (target?.kind === "video") streams[doviSeenFor] = {
|
|
14662
|
-
...target,
|
|
14663
|
-
hdr: "dolby-vision"
|
|
14664
|
-
};
|
|
14611
|
+
]
|
|
14665
14612
|
}
|
|
14666
|
-
|
|
14667
|
-
container,
|
|
14668
|
-
durationMs,
|
|
14669
|
-
streams,
|
|
14670
|
-
chapters
|
|
14671
|
-
};
|
|
14672
|
-
}
|
|
14673
|
-
var PROBE_TIMEOUT_MS = 3e4;
|
|
14674
|
-
var REPORT_MAX_BYTES = 1024 * 1024;
|
|
14675
|
-
/**
|
|
14676
|
-
* ONE ffmpeg per file, reading the input report. ffmpeg exits non-zero with no output file
|
|
14677
|
-
* (the report is on stderr), so a non-zero exit is expected and only a missing report is a failure.
|
|
14678
|
-
*/
|
|
14679
|
-
function createFfmpegProber(binaryPath) {
|
|
14680
|
-
return (path) => new Promise((resolve, reject) => {
|
|
14681
|
-
(0, node_child_process.execFile)(binaryPath, [
|
|
14682
|
-
"-hide_banner",
|
|
14683
|
-
"-nostdin",
|
|
14684
|
-
"-i",
|
|
14685
|
-
path
|
|
14686
|
-
], {
|
|
14687
|
-
timeout: PROBE_TIMEOUT_MS,
|
|
14688
|
-
maxBuffer: REPORT_MAX_BYTES,
|
|
14689
|
-
encoding: "utf8"
|
|
14690
|
-
}, (error, _stdout, stderr) => {
|
|
14691
|
-
if (error !== null && (error.killed === true || stderr === "")) {
|
|
14692
|
-
reject(new Error(error.killed === true ? "probe timed out" : error.message));
|
|
14693
|
-
return;
|
|
14694
|
-
}
|
|
14695
|
-
const result = parseFfmpegReport(stderr);
|
|
14696
|
-
if (result.streams.length === 0) reject(/* @__PURE__ */ new Error("no streams in the report"));
|
|
14697
|
-
else resolve(result);
|
|
14698
|
-
});
|
|
14699
|
-
});
|
|
14700
|
-
}
|
|
14701
|
-
//#endregion
|
|
14702
|
-
//#region src/provider.ts
|
|
14703
|
-
/** The `media-library` capability over the store. A caller reads and writes only their own progress. */
|
|
14704
|
-
function createMediaLibraryProvider(store, scans) {
|
|
14705
|
-
return {
|
|
14706
|
-
listSeries: ({ limit, offset, language, caller }) => store.listSeries(caller.userId, limit, offset, language),
|
|
14707
|
-
listMovies: ({ limit, offset, language, caller }) => store.listMovies(caller.userId, limit, offset, language),
|
|
14708
|
-
listSeasons: ({ seriesId, caller }) => store.listSeasons(caller.userId, seriesId),
|
|
14709
|
-
listEpisodes: ({ seriesId, seasonNumber, language, caller }) => store.listEpisodes(caller.userId, seriesId, seasonNumber, language),
|
|
14710
|
-
getItem: ({ itemId, language, caller }) => store.getItem(caller.userId, itemId, language),
|
|
14711
|
-
search: ({ query, limit, language, caller }) => store.search(caller.userId, query, limit, language),
|
|
14712
|
-
listRecentlyAdded: ({ limit, language, caller }) => store.listRecentlyAdded(caller.userId, limit, language),
|
|
14713
|
-
listWatchlist: ({ limit, offset, language, caller }) => store.listWatchlist(caller.userId, limit, offset, language),
|
|
14714
|
-
setWatchlisted: ({ itemId, on, caller }) => store.setWatchlisted(caller.userId, itemId, on),
|
|
14715
|
-
getItemDetails: ({ itemId, language }) => store.getItemDetails(itemId, language),
|
|
14716
|
-
getProgress: ({ itemId, caller }) => store.getProgress(caller.userId, itemId),
|
|
14717
|
-
setProgress: ({ caller, ...input }) => store.setProgress(caller.userId, input),
|
|
14718
|
-
markWatched: ({ caller, ...input }) => store.markWatched(caller.userId, input),
|
|
14719
|
-
listContinue: ({ limit, language, caller }) => store.listContinue(caller.userId, limit, language),
|
|
14720
|
-
rescan: async () => ({ started: scans.start("manual") }),
|
|
14721
|
-
getScanStatus: async () => scans.status()
|
|
14722
|
-
};
|
|
14723
|
-
}
|
|
14613
|
+
] };
|
|
14724
14614
|
//#endregion
|
|
14725
14615
|
//#region src/enrich.ts
|
|
14726
14616
|
/** The default order when settings name none (D1125): files next to the media, the arr app, then online. */
|
|
@@ -14896,9 +14786,7 @@ var Enricher = class {
|
|
|
14896
14786
|
const known = this.deps.cache.getMatch(key);
|
|
14897
14787
|
if (known === null) return null;
|
|
14898
14788
|
if (!known.found) return known;
|
|
14899
|
-
|
|
14900
|
-
const predatesDetails = provider.providesDetails === true && known.match.details === void 0;
|
|
14901
|
-
return predatesTranslations || predatesDetails ? null : known;
|
|
14789
|
+
return provider.translates === true && known.match.translations === void 0 || provider.providesDetails === true && known.match.details === void 0 ? null : known;
|
|
14902
14790
|
}
|
|
14903
14791
|
/** A pinned id is asked for directly: an answer of "nothing" is final, never turned into a title guess. */
|
|
14904
14792
|
async lookup(provider, ask, item, kind, pin) {
|
|
@@ -15186,12 +15074,11 @@ async function classify(root, path, reader) {
|
|
|
15186
15074
|
if (folderSeason !== null) seriesDir = (0, node_path.dirname)(parent);
|
|
15187
15075
|
else if (parent !== root) seriesDir = parent;
|
|
15188
15076
|
}
|
|
15189
|
-
const prefix = guess.kind === "episode" ? guess.title : "";
|
|
15190
15077
|
return {
|
|
15191
15078
|
path,
|
|
15192
15079
|
kind: "episode",
|
|
15193
15080
|
seriesDir,
|
|
15194
|
-
namedTitle:
|
|
15081
|
+
namedTitle: guess.kind === "episode" ? guess.title : "",
|
|
15195
15082
|
season,
|
|
15196
15083
|
episode,
|
|
15197
15084
|
year: null
|
|
@@ -15698,53 +15585,7 @@ var MediaLibraryAddon = class extends BaseAddon {
|
|
|
15698
15585
|
this.scans?.schedule(settings.rescanMinutes);
|
|
15699
15586
|
this.scans?.start("settings");
|
|
15700
15587
|
}
|
|
15701
|
-
/**
|
|
15702
|
-
* One-time, idempotent: the metadata settings of earlier versions (an order string, switches and
|
|
15703
|
-
* four keys) become the `metadataProviders` list. The rows are written first, so each key leaves
|
|
15704
|
-
* through the normal secret write into a keychain ref addressed by its row id (D787). An old key
|
|
15705
|
-
* is released only once its row holds a stored key (a marker counts), and nothing at all is
|
|
15706
|
-
* touched while an old secret cannot be read (the keychain is locked): the next boot retries.
|
|
15707
|
-
*/
|
|
15708
|
-
async migrateLegacyProviderSettings() {
|
|
15709
|
-
const stored = await this.resolveGlobalStore(void 0, SETTINGS_CAP);
|
|
15710
|
-
if (!hasLegacyProviderKeys(stored)) return;
|
|
15711
|
-
const unreadable = LEGACY_SECRET_KEYS.filter((key) => isSecretMarker(stored[key]));
|
|
15712
|
-
if (unreadable.length > 0) {
|
|
15713
|
-
this.ctx.logger.warn("media-library provider migration postponed: a stored key is unreadable", { meta: { keys: unreadable } });
|
|
15714
|
-
return;
|
|
15715
|
-
}
|
|
15716
|
-
const parsed = array(MetadataProviderRowSchema).safeParse(stored["metadataProviders"] ?? []);
|
|
15717
|
-
if (!parsed.success) {
|
|
15718
|
-
this.ctx.logger.warn("media-library provider migration postponed: the stored list is invalid");
|
|
15719
|
-
return;
|
|
15720
|
-
}
|
|
15721
|
-
const rows = parsed.data.length === 0 ? providerRowsFromLegacy(stored) : fillMissingKeys(parsed.data, stored);
|
|
15722
|
-
if (JSON.stringify(rows) !== JSON.stringify(parsed.data)) await this.clusterSettings(SETTINGS_CAP, MediaLibrarySettingsSchema).patch({ metadataProviders: rows });
|
|
15723
|
-
const after = await this.resolveGlobalStore(void 0, SETTINGS_CAP);
|
|
15724
|
-
const held = array(MetadataProviderRowSchema).safeParse(after["metadataProviders"]);
|
|
15725
|
-
const present = LEGACY_PROVIDER_KEYS.filter((key) => stored[key] !== void 0);
|
|
15726
|
-
const releasable = present.filter((key) => !LEGACY_SECRET_KEYS.some((secret) => secret === key) || typeof stored[key] === "string" && stored[key] === "" || held.success && rowHoldsKey(held.data, key));
|
|
15727
|
-
const secrets = releasable.filter((key) => LEGACY_SECRET_KEYS.some((s) => s === key));
|
|
15728
|
-
await this.clearSecrets(secrets);
|
|
15729
|
-
const outcome = await this.unsetStoredSettingsKeys(releasable);
|
|
15730
|
-
this.ctx.logger.info("media-library provider settings migrated to the provider list", { meta: {
|
|
15731
|
-
removed: outcome.removed.length,
|
|
15732
|
-
kept: present.length - releasable.length
|
|
15733
|
-
} });
|
|
15734
|
-
}
|
|
15735
|
-
/** A failed migration never stops the boot: the old keys stay and the next boot retries. */
|
|
15736
|
-
async migrateProviderSettingsOrKeepOld() {
|
|
15737
|
-
try {
|
|
15738
|
-
await this.migrateLegacyProviderSettings();
|
|
15739
|
-
} catch (error) {
|
|
15740
|
-
this.ctx.logger.warn("media-library provider migration failed; the old settings are kept", { meta: {
|
|
15741
|
-
step: "migrateLegacyProviderSettings",
|
|
15742
|
-
error: String(error)
|
|
15743
|
-
} });
|
|
15744
|
-
}
|
|
15745
|
-
}
|
|
15746
15588
|
async onInitialize() {
|
|
15747
|
-
await this.migrateProviderSettingsOrKeepOld();
|
|
15748
15589
|
const { ctx } = this;
|
|
15749
15590
|
const logger = ctx.logger;
|
|
15750
15591
|
const db = settingsStoreDb(ctx.api.settingsStore);
|