@dominevo/addon-media-library 0.1.12 → 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 +12 -0
- package/dist/media-library.addon.js +1190 -1335
- package/dist/media-library.addon.mjs +1190 -1335
- 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([
|
|
@@ -13734,6 +13216,20 @@ var TranslationsSchema = object({ translations: array(object({
|
|
|
13734
13216
|
overview: string().nullish()
|
|
13735
13217
|
}).nullish()
|
|
13736
13218
|
})) });
|
|
13219
|
+
/**
|
|
13220
|
+
* A list parsed per entry: an entry that does not parse is dropped and the rest kept, so one
|
|
13221
|
+
* malformed person never fails the whole response. (No logger reaches this module, so the drop is silent.)
|
|
13222
|
+
*/
|
|
13223
|
+
function lenientArray(schema) {
|
|
13224
|
+
return array(unknown()).transform((items) => {
|
|
13225
|
+
const kept = [];
|
|
13226
|
+
for (const item of items) {
|
|
13227
|
+
const parsed = schema.safeParse(item);
|
|
13228
|
+
if (parsed.success) kept.push(parsed.data);
|
|
13229
|
+
}
|
|
13230
|
+
return kept;
|
|
13231
|
+
});
|
|
13232
|
+
}
|
|
13737
13233
|
var PersonSchema = object({
|
|
13738
13234
|
id: number().int(),
|
|
13739
13235
|
name: string().nullish(),
|
|
@@ -13751,8 +13247,8 @@ var CrewEntrySchema = PersonSchema.extend({
|
|
|
13751
13247
|
jobs: array(object({ job: string().nullish() })).nullish()
|
|
13752
13248
|
});
|
|
13753
13249
|
var CreditsSchema = object({
|
|
13754
|
-
cast:
|
|
13755
|
-
crew:
|
|
13250
|
+
cast: lenientArray(CastEntrySchema).nullish(),
|
|
13251
|
+
crew: lenientArray(CrewEntrySchema).nullish()
|
|
13756
13252
|
});
|
|
13757
13253
|
/** `release_dates` (movie): per country, a list of releases that may carry a certification. */
|
|
13758
13254
|
var ReleaseDatesSchema = object({ results: array(object({
|
|
@@ -13800,8 +13296,8 @@ var SeasonSchema = object({ episodes: array(object({
|
|
|
13800
13296
|
overview: string().nullish(),
|
|
13801
13297
|
still_path: string().nullish(),
|
|
13802
13298
|
runtime: number().nullish(),
|
|
13803
|
-
guest_stars:
|
|
13804
|
-
crew:
|
|
13299
|
+
guest_stars: lenientArray(CastEntrySchema).nullish(),
|
|
13300
|
+
crew: lenientArray(CrewEntrySchema).nullish()
|
|
13805
13301
|
})) });
|
|
13806
13302
|
/** Waited when TMDB says 429 and names no time. */
|
|
13807
13303
|
var TMDB_DEFAULT_RETRY_WAIT_MS = 2e3;
|
|
@@ -14011,702 +13507,1110 @@ function createTmdbProvider(deps) {
|
|
|
14011
13507
|
return hit === void 0 ? null : detailsOf(kind, hit.id);
|
|
14012
13508
|
},
|
|
14013
13509
|
async lookup(kind, ids) {
|
|
14014
|
-
if (ids.tmdbId !== null) return detailsOf(kind, ids.tmdbId);
|
|
14015
|
-
const external = ids.imdbId !== null ? {
|
|
14016
|
-
source: "imdb_id",
|
|
14017
|
-
value: ids.imdbId
|
|
14018
|
-
} : ids.tvdbId !== null ? {
|
|
14019
|
-
source: "tvdb_id",
|
|
14020
|
-
value: String(ids.tvdbId)
|
|
14021
|
-
} : 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));
|
|
14022
13699
|
if (external === null) return null;
|
|
14023
|
-
|
|
14024
|
-
|
|
14025
|
-
|
|
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);
|
|
14026
13709
|
},
|
|
14027
13710
|
async episodes(match) {
|
|
14028
|
-
const base = `/tv/${encodeURIComponent(match.remoteId)}`;
|
|
14029
|
-
const show = DetailsSchema.parse(await call(base));
|
|
14030
13711
|
const out = [];
|
|
14031
|
-
|
|
14032
|
-
|
|
14033
|
-
|
|
14034
|
-
|
|
14035
|
-
|
|
14036
|
-
|
|
14037
|
-
|
|
14038
|
-
|
|
14039
|
-
|
|
14040
|
-
genres: {},
|
|
14041
|
-
runtimeMinutes: positive(entry.runtime),
|
|
14042
|
-
certification: null,
|
|
14043
|
-
creators: [],
|
|
14044
|
-
directors: personsOf(entry.crew, DIRECTOR_JOBS),
|
|
14045
|
-
writers: personsOf(entry.crew, WRITER_JOBS),
|
|
14046
|
-
cast: [],
|
|
14047
|
-
guestStars: castOf(entry.guest_stars)
|
|
14048
|
-
}
|
|
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)
|
|
14049
13721
|
});
|
|
13722
|
+
page = list.links?.next ?? null;
|
|
14050
13723
|
}
|
|
14051
13724
|
return out;
|
|
14052
13725
|
}
|
|
14053
13726
|
};
|
|
14054
13727
|
}
|
|
14055
13728
|
//#endregion
|
|
14056
|
-
//#region src/
|
|
14057
|
-
var
|
|
14058
|
-
var API
|
|
14059
|
-
|
|
14060
|
-
|
|
14061
|
-
|
|
14062
|
-
|
|
14063
|
-
|
|
14064
|
-
poster: 2,
|
|
14065
|
-
fanart: 3
|
|
14066
|
-
},
|
|
14067
|
-
movie: {
|
|
14068
|
-
poster: 14,
|
|
14069
|
-
fanart: 15
|
|
14070
|
-
}
|
|
14071
|
-
};
|
|
14072
|
-
var MAX_EPISODE_PAGES = 50;
|
|
14073
|
-
/** The login answer; the bearer is read by name below, it is a response, not a setting. */
|
|
14074
|
-
var LoginSchema = object({ data: record(string(), string()) });
|
|
14075
|
-
var SearchSchema$1 = object({ data: array(object({
|
|
14076
|
-
tvdb_id: union([string(), number()]),
|
|
14077
|
-
name: string().nullish(),
|
|
14078
|
-
year: union([string(), number()]).nullish()
|
|
14079
|
-
})).nullish() });
|
|
14080
|
-
var RemoteIdSchema = object({
|
|
14081
|
-
id: union([string(), number()]),
|
|
14082
|
-
sourceName: string()
|
|
14083
|
-
});
|
|
14084
|
-
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({
|
|
14085
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({
|
|
14086
13752
|
name: string().nullish(),
|
|
14087
|
-
|
|
14088
|
-
|
|
14089
|
-
|
|
14090
|
-
image:
|
|
14091
|
-
remoteIds: array(RemoteIdSchema).nullish(),
|
|
14092
|
-
artworks: array(object({
|
|
14093
|
-
image: string(),
|
|
14094
|
-
type: number().int(),
|
|
14095
|
-
score: number().nullish()
|
|
14096
|
-
})).nullish()
|
|
14097
|
-
}) });
|
|
14098
|
-
var RemoteSearchSchema = object({ data: array(object({
|
|
14099
|
-
series: object({ id: number().int() }).nullish(),
|
|
14100
|
-
movie: object({ id: number().int() }).nullish()
|
|
14101
|
-
})).nullish() });
|
|
14102
|
-
var EpisodesSchema = object({
|
|
14103
|
-
data: object({ episodes: array(object({
|
|
14104
|
-
seasonNumber: number().int(),
|
|
14105
|
-
number: number().int(),
|
|
14106
|
-
name: string().nullish(),
|
|
14107
|
-
overview: string().nullish(),
|
|
14108
|
-
image: string().nullish()
|
|
14109
|
-
})) }),
|
|
14110
|
-
links: object({ next: number().int().nullish() }).nullish()
|
|
13753
|
+
season: number().int(),
|
|
13754
|
+
number: number().int().nullish(),
|
|
13755
|
+
summary: string().nullish(),
|
|
13756
|
+
image: ImageSchema
|
|
14111
13757
|
});
|
|
14112
|
-
|
|
14113
|
-
|
|
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;
|
|
14114
13886
|
}
|
|
14115
|
-
function
|
|
14116
|
-
|
|
13887
|
+
function end(res, status) {
|
|
13888
|
+
res.writeHead(status, { "Content-Length": 0 });
|
|
13889
|
+
res.end();
|
|
14117
13890
|
}
|
|
14118
|
-
/**
|
|
14119
|
-
function
|
|
14120
|
-
|
|
14121
|
-
const
|
|
14122
|
-
|
|
14123
|
-
|
|
14124
|
-
|
|
14125
|
-
|
|
14126
|
-
|
|
14127
|
-
|
|
14128
|
-
|
|
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" }
|
|
14129
13920
|
});
|
|
14130
|
-
|
|
14131
|
-
if (bearer === void 0) throw new Error("TheTVDB login answered without a bearer");
|
|
14132
|
-
token = bearer;
|
|
14133
|
-
return bearer;
|
|
14134
|
-
} catch (error) {
|
|
14135
|
-
if (isHttp(error, 401)) throw new ProviderAuthError(TVDB_REJECTED);
|
|
14136
|
-
throw error;
|
|
13921
|
+
return null;
|
|
14137
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);
|
|
14138
13925
|
};
|
|
14139
|
-
const
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
const
|
|
14143
|
-
|
|
14144
|
-
|
|
14145
|
-
|
|
14146
|
-
|
|
14147
|
-
|
|
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;
|
|
14148
13953
|
} catch (error) {
|
|
14149
|
-
|
|
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;
|
|
14150
13962
|
}
|
|
13963
|
+
const key = hashKey(`${itemId}:${which}:${origin}`);
|
|
13964
|
+
if (hasFailed(key)) return null;
|
|
13965
|
+
const cached = (0, node_path.join)(deps.cacheDir, key);
|
|
14151
13966
|
try {
|
|
14152
|
-
|
|
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;
|
|
14153
13983
|
} catch (error) {
|
|
14154
|
-
if (
|
|
14155
|
-
|
|
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;
|
|
14156
14000
|
}
|
|
14157
14001
|
};
|
|
14158
|
-
|
|
14159
|
-
|
|
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 = "";
|
|
14160
14007
|
try {
|
|
14161
|
-
|
|
14162
|
-
|
|
14163
|
-
|
|
14164
|
-
return {
|
|
14165
|
-
providerId: TVDB_ID,
|
|
14166
|
-
remoteId: String(data.id),
|
|
14167
|
-
title: data.name ?? "",
|
|
14168
|
-
year: yearOf$2(data.year) ?? yearOf$2(data.firstAired),
|
|
14169
|
-
overview: text$1(data.overview),
|
|
14170
|
-
tvdbId: data.id,
|
|
14171
|
-
tmdbId: tmdb === null || !/^\d+$/.test(tmdb) ? null : Number(tmdb),
|
|
14172
|
-
imdbId: imdb,
|
|
14173
|
-
poster: bestArtwork(data, ARTWORK[kind].poster) ?? text$1(data.image),
|
|
14174
|
-
fanart: bestArtwork(data, ARTWORK[kind].fanart)
|
|
14175
|
-
};
|
|
14176
|
-
} catch (error) {
|
|
14177
|
-
if (isHttp(error, 404)) return null;
|
|
14178
|
-
throw error;
|
|
14008
|
+
itemId = decodeURIComponent(rawId ?? "");
|
|
14009
|
+
} catch {
|
|
14010
|
+
return end(res, 404);
|
|
14179
14011
|
}
|
|
14180
|
-
|
|
14181
|
-
|
|
14182
|
-
|
|
14183
|
-
|
|
14184
|
-
|
|
14185
|
-
|
|
14186
|
-
|
|
14187
|
-
|
|
14188
|
-
|
|
14189
|
-
|
|
14190
|
-
|
|
14191
|
-
|
|
14192
|
-
type: kind,
|
|
14193
|
-
...year === null ? {} : { year: String(year) }
|
|
14194
|
-
})).data ?? []).filter((entry) => foldTitle(entry.name ?? "") === foldTitle(title));
|
|
14195
|
-
const sameYear = year === null ? [] : exact.filter((entry) => yearOf$2(entry.year) === year);
|
|
14196
|
-
const pool = sameYear.length > 0 ? sameYear : exact;
|
|
14197
|
-
const ids = new Set(pool.map((entry) => Number(entry.tvdb_id)));
|
|
14198
|
-
const [id] = [...ids];
|
|
14199
|
-
return ids.size === 1 && id !== void 0 && Number.isInteger(id) ? detailsOf(kind, id) : null;
|
|
14200
|
-
},
|
|
14201
|
-
async lookup(kind, ids) {
|
|
14202
|
-
if (ids.tvdbId !== null) return detailsOf(kind, ids.tvdbId);
|
|
14203
|
-
const external = ids.imdbId ?? (ids.tmdbId === null ? null : String(ids.tmdbId));
|
|
14204
|
-
if (external === null) return null;
|
|
14205
|
-
let found;
|
|
14206
|
-
try {
|
|
14207
|
-
found = RemoteSearchSchema.parse(await call(`/search/remoteid/${encodeURIComponent(external)}`));
|
|
14208
|
-
} catch (error) {
|
|
14209
|
-
if (isHttp(error, 404)) return null;
|
|
14210
|
-
throw error;
|
|
14211
|
-
}
|
|
14212
|
-
const hit = (found.data ?? []).map((entry) => kind === "movie" ? entry.movie : entry.series).find((entry) => entry !== null && entry !== void 0);
|
|
14213
|
-
return hit === void 0 || hit === null ? null : detailsOf(kind, hit.id);
|
|
14214
|
-
},
|
|
14215
|
-
async episodes(match) {
|
|
14216
|
-
const out = [];
|
|
14217
|
-
let page = 0;
|
|
14218
|
-
for (let guard = 0; page !== null && guard < MAX_EPISODE_PAGES; guard += 1) {
|
|
14219
|
-
const list = EpisodesSchema.parse(await call(`/series/${encodeURIComponent(match.remoteId)}/episodes/default`, { page: String(page) }));
|
|
14220
|
-
for (const entry of list.data.episodes) out.push({
|
|
14221
|
-
season: entry.seasonNumber,
|
|
14222
|
-
episode: entry.number,
|
|
14223
|
-
title: text$1(entry.name),
|
|
14224
|
-
overview: text$1(entry.overview),
|
|
14225
|
-
still: text$1(entry.image)
|
|
14226
|
-
});
|
|
14227
|
-
page = list.links?.next ?? null;
|
|
14228
|
-
}
|
|
14229
|
-
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);
|
|
14230
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);
|
|
14231
14033
|
};
|
|
14232
14034
|
}
|
|
14233
|
-
//#endregion
|
|
14234
|
-
//#region src/
|
|
14235
|
-
var
|
|
14236
|
-
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
|
|
14240
|
-
|
|
14241
|
-
|
|
14242
|
-
|
|
14243
|
-
|
|
14244
|
-
|
|
14245
|
-
|
|
14246
|
-
|
|
14247
|
-
|
|
14248
|
-
thetvdb: number().int().nullish(),
|
|
14249
|
-
imdb: string().nullish()
|
|
14250
|
-
}).nullish()
|
|
14251
|
-
});
|
|
14252
|
-
var SearchSchema = array(object({
|
|
14253
|
-
score: number(),
|
|
14254
|
-
show: ShowSchema
|
|
14255
|
-
}));
|
|
14256
|
-
var EpisodeSchema = object({
|
|
14257
|
-
name: string().nullish(),
|
|
14258
|
-
season: number().int(),
|
|
14259
|
-
number: number().int().nullish(),
|
|
14260
|
-
summary: string().nullish(),
|
|
14261
|
-
image: ImageSchema
|
|
14262
|
-
});
|
|
14263
|
-
/** The summary field is HTML; keep the text. */
|
|
14264
|
-
function plain(html) {
|
|
14265
|
-
if (html === null || html === void 0) return null;
|
|
14266
|
-
const text = html.replace(/<[^>]*>/g, " ").replace(/&#(\d{1,6});|&#x([0-9a-f]{1,6});/gi, (_whole, dec, hex) => {
|
|
14267
|
-
const code = typeof dec === "string" ? Number(dec) : Number.parseInt(String(hex), 16);
|
|
14268
|
-
return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : "";
|
|
14269
|
-
}).replace(/'/g, "'").replace(/"/g, "\"").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&").replace(/\s+/g, " ").trim();
|
|
14270
|
-
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;
|
|
14271
14050
|
}
|
|
14272
|
-
function
|
|
14273
|
-
|
|
14274
|
-
|
|
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;
|
|
14275
14056
|
}
|
|
14276
|
-
function
|
|
14277
|
-
|
|
14278
|
-
|
|
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;
|
|
14279
14062
|
}
|
|
14280
|
-
|
|
14281
|
-
|
|
14282
|
-
|
|
14283
|
-
const
|
|
14284
|
-
|
|
14285
|
-
|
|
14286
|
-
|
|
14287
|
-
|
|
14288
|
-
|
|
14289
|
-
|
|
14290
|
-
|
|
14291
|
-
|
|
14292
|
-
|
|
14293
|
-
|
|
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"
|
|
14294
14145
|
};
|
|
14295
|
-
|
|
14296
|
-
|
|
14297
|
-
|
|
14146
|
+
}
|
|
14147
|
+
return {
|
|
14148
|
+
container,
|
|
14149
|
+
durationMs,
|
|
14150
|
+
streams,
|
|
14151
|
+
chapters
|
|
14298
14152
|
};
|
|
14299
|
-
|
|
14300
|
-
|
|
14301
|
-
|
|
14302
|
-
|
|
14303
|
-
|
|
14304
|
-
|
|
14305
|
-
|
|
14306
|
-
|
|
14307
|
-
|
|
14308
|
-
|
|
14309
|
-
|
|
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
|
+
});
|
|
14310
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) {
|
|
14311
14186
|
return {
|
|
14312
|
-
|
|
14313
|
-
|
|
14314
|
-
|
|
14315
|
-
|
|
14316
|
-
|
|
14317
|
-
|
|
14318
|
-
|
|
14319
|
-
|
|
14320
|
-
|
|
14321
|
-
|
|
14322
|
-
|
|
14323
|
-
},
|
|
14324
|
-
|
|
14325
|
-
|
|
14326
|
-
|
|
14327
|
-
|
|
14328
|
-
const hit = sameYear ?? (year === null || top !== void 0 && foldTitle(top.show.name) === foldTitle(title) ? top : void 0);
|
|
14329
|
-
if (hit === void 0) return null;
|
|
14330
|
-
const show = hit.show;
|
|
14331
|
-
return {
|
|
14332
|
-
providerId: TVMAZE_ID,
|
|
14333
|
-
remoteId: String(show.id),
|
|
14334
|
-
title: show.name,
|
|
14335
|
-
year: yearOf(show.premiered),
|
|
14336
|
-
overview: plain(show.summary),
|
|
14337
|
-
tvdbId: show.externals?.thetvdb ?? null,
|
|
14338
|
-
tmdbId: null,
|
|
14339
|
-
imdbId: show.externals?.imdb ?? null,
|
|
14340
|
-
poster: imageOf(show.image),
|
|
14341
|
-
fanart: null
|
|
14342
|
-
};
|
|
14343
|
-
},
|
|
14344
|
-
async episodes(match) {
|
|
14345
|
-
return array(EpisodeSchema).parse(await call(`/shows/${encodeURIComponent(match.remoteId)}/episodes?specials=1`)).flatMap((entry) => entry.number === null || entry.number === void 0 ? [] : [{
|
|
14346
|
-
season: entry.season,
|
|
14347
|
-
episode: entry.number,
|
|
14348
|
-
title: entry.name ?? null,
|
|
14349
|
-
overview: plain(entry.summary),
|
|
14350
|
-
still: imageOf(entry.image)
|
|
14351
|
-
}]);
|
|
14352
|
-
}
|
|
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()
|
|
14353
14203
|
};
|
|
14354
14204
|
}
|
|
14355
14205
|
//#endregion
|
|
14356
|
-
//#region src/
|
|
14357
|
-
|
|
14358
|
-
var
|
|
14359
|
-
/**
|
|
14360
|
-
|
|
14361
|
-
const
|
|
14362
|
-
|
|
14363
|
-
|
|
14364
|
-
|
|
14365
|
-
|
|
14366
|
-
|
|
14367
|
-
|
|
14368
|
-
|
|
14369
|
-
|
|
14370
|
-
|
|
14371
|
-
|
|
14372
|
-
if (bytes.length > 8 && bytes.subarray(1, 4).toString("latin1") === "PNG") return "image/png";
|
|
14373
|
-
if (bytes.length > 12 && bytes.subarray(8, 12).toString("latin1") === "WEBP") return "image/webp";
|
|
14374
|
-
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(/\/+$/, "")}`;
|
|
14375
14222
|
}
|
|
14376
|
-
|
|
14377
|
-
|
|
14378
|
-
|
|
14379
|
-
|
|
14380
|
-
|
|
14381
|
-
|
|
14382
|
-
|
|
14383
|
-
|
|
14384
|
-
const own = new URL(source.baseUrl);
|
|
14385
|
-
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;
|
|
14386
14231
|
}
|
|
14387
|
-
|
|
14388
|
-
|
|
14389
|
-
|
|
14390
|
-
|
|
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);
|
|
14391
14255
|
}
|
|
14392
|
-
function
|
|
14393
|
-
|
|
14394
|
-
res.end();
|
|
14256
|
+
function isKeyedStep(step) {
|
|
14257
|
+
return KEYED_STEPS.some((keyed) => keyed === step);
|
|
14395
14258
|
}
|
|
14396
|
-
/**
|
|
14397
|
-
|
|
14398
|
-
|
|
14399
|
-
|
|
14400
|
-
|
|
14401
|
-
|
|
14402
|
-
|
|
14403
|
-
|
|
14404
|
-
|
|
14405
|
-
|
|
14406
|
-
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
|
|
14411
|
-
|
|
14412
|
-
|
|
14413
|
-
|
|
14414
|
-
|
|
14415
|
-
|
|
14416
|
-
|
|
14417
|
-
|
|
14418
|
-
|
|
14419
|
-
|
|
14420
|
-
|
|
14421
|
-
|
|
14422
|
-
|
|
14423
|
-
|
|
14424
|
-
|
|
14425
|
-
});
|
|
14426
|
-
return null;
|
|
14427
|
-
}
|
|
14428
|
-
if ((await (0, node_fs_promises.stat)(real)).size > 10485760) throw new Error("image too large");
|
|
14429
|
-
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
|
|
14430
14288
|
};
|
|
14431
|
-
|
|
14432
|
-
|
|
14433
|
-
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14437
|
-
|
|
14438
|
-
|
|
14439
|
-
|
|
14440
|
-
|
|
14441
|
-
|
|
14442
|
-
|
|
14443
|
-
|
|
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()
|
|
14444
14344
|
};
|
|
14445
|
-
|
|
14446
|
-
|
|
14447
|
-
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
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")
|
|
14451
14354
|
};
|
|
14452
|
-
|
|
14453
|
-
|
|
14454
|
-
|
|
14455
|
-
|
|
14456
|
-
|
|
14457
|
-
|
|
14458
|
-
|
|
14459
|
-
|
|
14460
|
-
|
|
14461
|
-
|
|
14462
|
-
|
|
14463
|
-
|
|
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
|
+
}
|
|
14464
14536
|
}
|
|
14465
|
-
|
|
14466
|
-
|
|
14467
|
-
|
|
14468
|
-
|
|
14469
|
-
|
|
14470
|
-
|
|
14471
|
-
|
|
14472
|
-
|
|
14473
|
-
|
|
14474
|
-
|
|
14475
|
-
|
|
14476
|
-
|
|
14477
|
-
|
|
14478
|
-
|
|
14479
|
-
|
|
14480
|
-
|
|
14481
|
-
|
|
14482
|
-
|
|
14483
|
-
|
|
14484
|
-
|
|
14485
|
-
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14494
|
-
|
|
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}"
|
|
14495
14610
|
}
|
|
14496
|
-
|
|
14497
|
-
deps.logger.warn(found.kind === "frame" ? "frame grab failed" : "image fetch failed", {
|
|
14498
|
-
tags,
|
|
14499
|
-
meta: {
|
|
14500
|
-
reason: found.kind === "frame" ? "grab-failed" : "fetch-failed",
|
|
14501
|
-
error: error instanceof Error ? error.message : String(error)
|
|
14502
|
-
}
|
|
14503
|
-
});
|
|
14504
|
-
return null;
|
|
14505
|
-
}
|
|
14506
|
-
};
|
|
14507
|
-
return async (req, res) => {
|
|
14508
|
-
if (req.method !== "GET" && req.method !== "HEAD") return end(res, 405);
|
|
14509
|
-
const parts = ((req.url ?? "/").split("?")[0] ?? "/").replace(/^\//, "").split("/");
|
|
14510
|
-
const [rawId, which] = parts;
|
|
14511
|
-
let itemId = "";
|
|
14512
|
-
try {
|
|
14513
|
-
itemId = decodeURIComponent(rawId ?? "");
|
|
14514
|
-
} catch {
|
|
14515
|
-
return end(res, 404);
|
|
14516
|
-
}
|
|
14517
|
-
if (parts.length !== 2 || !isItemId(itemId) || !isImageKind(which)) {
|
|
14518
|
-
deps.logger.warn("image request refused", { meta: { reason: "bad-request" } });
|
|
14519
|
-
return end(res, 404);
|
|
14520
|
-
}
|
|
14521
|
-
const flightKey = `${itemId}:${which}`;
|
|
14522
|
-
const pending = inFlight.get(flightKey) ?? load(itemId, which);
|
|
14523
|
-
inFlight.set(flightKey, pending);
|
|
14524
|
-
let bytes;
|
|
14525
|
-
try {
|
|
14526
|
-
bytes = await pending;
|
|
14527
|
-
} finally {
|
|
14528
|
-
inFlight.delete(flightKey);
|
|
14529
|
-
}
|
|
14530
|
-
const contentType = bytes === null ? null : typeOf(bytes);
|
|
14531
|
-
if (bytes === null || contentType === null) return end(res, 404);
|
|
14532
|
-
res.writeHead(200, {
|
|
14533
|
-
"Content-Type": contentType,
|
|
14534
|
-
"Content-Length": bytes.length,
|
|
14535
|
-
"Cache-Control": "private, max-age=86400"
|
|
14536
|
-
});
|
|
14537
|
-
res.end(req.method === "HEAD" ? void 0 : bytes);
|
|
14538
|
-
};
|
|
14539
|
-
}
|
|
14540
|
-
//#endregion
|
|
14541
|
-
//#region src/probe.ts
|
|
14542
|
-
var CONTAINER_NAMES = new Map([
|
|
14543
|
-
["matroska", "mkv"],
|
|
14544
|
-
["mov", "mp4"],
|
|
14545
|
-
["avi", "avi"],
|
|
14546
|
-
["mpegts", "ts"]
|
|
14547
|
-
]);
|
|
14548
|
-
function containerOf(formats) {
|
|
14549
|
-
const first = formats.split(",")[0]?.trim() ?? formats;
|
|
14550
|
-
return CONTAINER_NAMES.get(first) ?? first;
|
|
14551
|
-
}
|
|
14552
|
-
function languageOf(tag) {
|
|
14553
|
-
if (tag === void 0 || tag === "" || tag === "und") return null;
|
|
14554
|
-
return tag;
|
|
14555
|
-
}
|
|
14556
|
-
function bitDepthOf(pixFmt) {
|
|
14557
|
-
if (pixFmt === null) return null;
|
|
14558
|
-
const match = /(?:p|le|be)(9|10|12|14|16)(?:le|be)?$/.exec(pixFmt);
|
|
14559
|
-
if (match?.[1] !== void 0) return Number(match[1]);
|
|
14560
|
-
return /^(yuv|nv|gray|rgb|bgr)/.test(pixFmt) ? 8 : null;
|
|
14561
|
-
}
|
|
14562
|
-
function hdrOf(line, doviSeen) {
|
|
14563
|
-
if (doviSeen) return "dolby-vision";
|
|
14564
|
-
if (line.includes("smpte2084")) return "hdr10";
|
|
14565
|
-
if (line.includes("arib-std-b67")) return "hlg";
|
|
14566
|
-
return null;
|
|
14567
|
-
}
|
|
14568
|
-
function channelsOf(line) {
|
|
14569
|
-
if (/\bmono\b/.test(line)) return 1;
|
|
14570
|
-
if (/\bstereo\b/.test(line)) return 2;
|
|
14571
|
-
const layout = /\b(\d)\.(\d)(?:\([a-z]+\))?/.exec(line);
|
|
14572
|
-
if (layout?.[1] !== void 0 && layout[2] !== void 0) return Number(layout[1]) + Number(layout[2]);
|
|
14573
|
-
const count = /\b(\d+) channels\b/.exec(line);
|
|
14574
|
-
return count?.[1] !== void 0 ? Number(count[1]) : null;
|
|
14575
|
-
}
|
|
14576
|
-
var STREAM_LINE = /^\s*Stream #\d+:(\d+)(?:\[[^\]]*\])?(?:\(([^)]*)\))?[^:]*: (Video|Audio|Subtitle): (.*)$/;
|
|
14577
|
-
var CHAPTER_LINE = /^\s*Chapter #\d+:\d+: start ([\d.]+), end ([\d.]+)/;
|
|
14578
|
-
var CHAPTER_TITLE = /^\s+title\s*:\s*(.*)$/;
|
|
14579
|
-
/** Parse the report `ffmpeg -i <file>` prints on stderr. A report that is not one yields no streams and no duration. */
|
|
14580
|
-
function parseFfmpegReport(report) {
|
|
14581
|
-
const lines = report.split("\n");
|
|
14582
|
-
let container = null;
|
|
14583
|
-
let durationMs = null;
|
|
14584
|
-
const streams = [];
|
|
14585
|
-
const chapters = [];
|
|
14586
|
-
let doviSeenFor = null;
|
|
14587
|
-
let inChapters = false;
|
|
14588
|
-
for (const line of lines) {
|
|
14589
|
-
const input = /^Input #\d+, ([^,]+(?:,[^,]+)*), from /.exec(line);
|
|
14590
|
-
if (input?.[1] !== void 0 && container === null) container = containerOf(input[1]);
|
|
14591
|
-
const duration = /^\s*Duration: (\d+):(\d{2}):(\d{2})\.(\d{2})/.exec(line);
|
|
14592
|
-
if (duration && durationMs === null) durationMs = (Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3])) * 1e3 + Number(duration[4]) * 10;
|
|
14593
|
-
const chapter = CHAPTER_LINE.exec(line);
|
|
14594
|
-
if (chapter?.[1] !== void 0 && chapter[2] !== void 0) {
|
|
14595
|
-
const startSec = Number(chapter[1]);
|
|
14596
|
-
const endSec = Number(chapter[2]);
|
|
14597
|
-
if (Number.isFinite(startSec) && Number.isFinite(endSec) && endSec > startSec) chapters.push({
|
|
14598
|
-
startSec,
|
|
14599
|
-
endSec,
|
|
14600
|
-
title: null
|
|
14601
|
-
});
|
|
14602
|
-
continue;
|
|
14603
|
-
}
|
|
14604
|
-
const titled = CHAPTER_TITLE.exec(line);
|
|
14605
|
-
const last = chapters[chapters.length - 1];
|
|
14606
|
-
if (titled?.[1] !== void 0 && last !== void 0 && last.title === null && inChapters) {
|
|
14607
|
-
if (titled[1].trim() !== "") chapters[chapters.length - 1] = {
|
|
14608
|
-
...last,
|
|
14609
|
-
title: titled[1].trim()
|
|
14610
|
-
};
|
|
14611
|
-
continue;
|
|
14612
|
-
}
|
|
14613
|
-
if (/^\s*Chapters:/.test(line)) inChapters = true;
|
|
14614
|
-
if (STREAM_LINE.test(line)) inChapters = false;
|
|
14615
|
-
if (/DOVI configuration record/.test(line) && streams.length > 0) {
|
|
14616
|
-
doviSeenFor = streams.length - 1;
|
|
14617
|
-
continue;
|
|
14618
|
-
}
|
|
14619
|
-
const match = STREAM_LINE.exec(line);
|
|
14620
|
-
if (!match) continue;
|
|
14621
|
-
const [, indexText, lang, kindText, rest] = match;
|
|
14622
|
-
if (indexText === void 0 || kindText === void 0 || rest === void 0) continue;
|
|
14623
|
-
const kind = kindText === "Video" ? "video" : kindText === "Audio" ? "audio" : "subtitle";
|
|
14624
|
-
const codecMatch = /^([A-Za-z0-9_]+)(?: \(([^)]*)\))?/.exec(rest);
|
|
14625
|
-
const codec = codecMatch?.[1] ?? "unknown";
|
|
14626
|
-
const rawProfile = codecMatch?.[2];
|
|
14627
|
-
const profile = kind !== "subtitle" && rawProfile !== void 0 && !/ 0x|^(default|forced)$/.test(rawProfile) ? rawProfile : null;
|
|
14628
|
-
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;
|
|
14629
|
-
const size = kind === "video" ? /\b(\d{2,5})x(\d{2,5})\b/.exec(rest) : null;
|
|
14630
|
-
streams.push({
|
|
14631
|
-
index: Number(indexText),
|
|
14632
|
-
kind,
|
|
14633
|
-
codec,
|
|
14634
|
-
profile,
|
|
14635
|
-
language: languageOf(lang),
|
|
14636
|
-
channels: kind === "audio" ? channelsOf(rest) : null,
|
|
14637
|
-
bitDepth: kind === "video" ? bitDepthOf(pixFmt) : null,
|
|
14638
|
-
hdr: kind === "video" ? hdrOf(rest, false) : null,
|
|
14639
|
-
width: size?.[1] !== void 0 ? Number(size[1]) : null,
|
|
14640
|
-
height: size?.[2] !== void 0 ? Number(size[2]) : null,
|
|
14641
|
-
isDefault: /\(default\)/.test(rest),
|
|
14642
|
-
isForced: /\(forced\)/.test(rest)
|
|
14643
|
-
});
|
|
14644
|
-
}
|
|
14645
|
-
if (doviSeenFor !== null) {
|
|
14646
|
-
const target = streams[doviSeenFor];
|
|
14647
|
-
if (target?.kind === "video") streams[doviSeenFor] = {
|
|
14648
|
-
...target,
|
|
14649
|
-
hdr: "dolby-vision"
|
|
14650
|
-
};
|
|
14611
|
+
]
|
|
14651
14612
|
}
|
|
14652
|
-
|
|
14653
|
-
container,
|
|
14654
|
-
durationMs,
|
|
14655
|
-
streams,
|
|
14656
|
-
chapters
|
|
14657
|
-
};
|
|
14658
|
-
}
|
|
14659
|
-
var PROBE_TIMEOUT_MS = 3e4;
|
|
14660
|
-
var REPORT_MAX_BYTES = 1024 * 1024;
|
|
14661
|
-
/**
|
|
14662
|
-
* ONE ffmpeg per file, reading the input report. ffmpeg exits non-zero with no output file
|
|
14663
|
-
* (the report is on stderr), so a non-zero exit is expected and only a missing report is a failure.
|
|
14664
|
-
*/
|
|
14665
|
-
function createFfmpegProber(binaryPath) {
|
|
14666
|
-
return (path) => new Promise((resolve, reject) => {
|
|
14667
|
-
(0, node_child_process.execFile)(binaryPath, [
|
|
14668
|
-
"-hide_banner",
|
|
14669
|
-
"-nostdin",
|
|
14670
|
-
"-i",
|
|
14671
|
-
path
|
|
14672
|
-
], {
|
|
14673
|
-
timeout: PROBE_TIMEOUT_MS,
|
|
14674
|
-
maxBuffer: REPORT_MAX_BYTES,
|
|
14675
|
-
encoding: "utf8"
|
|
14676
|
-
}, (error, _stdout, stderr) => {
|
|
14677
|
-
if (error !== null && (error.killed === true || stderr === "")) {
|
|
14678
|
-
reject(new Error(error.killed === true ? "probe timed out" : error.message));
|
|
14679
|
-
return;
|
|
14680
|
-
}
|
|
14681
|
-
const result = parseFfmpegReport(stderr);
|
|
14682
|
-
if (result.streams.length === 0) reject(/* @__PURE__ */ new Error("no streams in the report"));
|
|
14683
|
-
else resolve(result);
|
|
14684
|
-
});
|
|
14685
|
-
});
|
|
14686
|
-
}
|
|
14687
|
-
//#endregion
|
|
14688
|
-
//#region src/provider.ts
|
|
14689
|
-
/** The `media-library` capability over the store. A caller reads and writes only their own progress. */
|
|
14690
|
-
function createMediaLibraryProvider(store, scans) {
|
|
14691
|
-
return {
|
|
14692
|
-
listSeries: ({ limit, offset, language, caller }) => store.listSeries(caller.userId, limit, offset, language),
|
|
14693
|
-
listMovies: ({ limit, offset, language, caller }) => store.listMovies(caller.userId, limit, offset, language),
|
|
14694
|
-
listSeasons: ({ seriesId, caller }) => store.listSeasons(caller.userId, seriesId),
|
|
14695
|
-
listEpisodes: ({ seriesId, seasonNumber, language, caller }) => store.listEpisodes(caller.userId, seriesId, seasonNumber, language),
|
|
14696
|
-
getItem: ({ itemId, language, caller }) => store.getItem(caller.userId, itemId, language),
|
|
14697
|
-
search: ({ query, limit, language, caller }) => store.search(caller.userId, query, limit, language),
|
|
14698
|
-
listRecentlyAdded: ({ limit, language, caller }) => store.listRecentlyAdded(caller.userId, limit, language),
|
|
14699
|
-
listWatchlist: ({ limit, offset, language, caller }) => store.listWatchlist(caller.userId, limit, offset, language),
|
|
14700
|
-
setWatchlisted: ({ itemId, on, caller }) => store.setWatchlisted(caller.userId, itemId, on),
|
|
14701
|
-
getItemDetails: ({ itemId, language }) => store.getItemDetails(itemId, language),
|
|
14702
|
-
getProgress: ({ itemId, caller }) => store.getProgress(caller.userId, itemId),
|
|
14703
|
-
setProgress: ({ caller, ...input }) => store.setProgress(caller.userId, input),
|
|
14704
|
-
markWatched: ({ caller, ...input }) => store.markWatched(caller.userId, input),
|
|
14705
|
-
listContinue: ({ limit, language, caller }) => store.listContinue(caller.userId, limit, language),
|
|
14706
|
-
rescan: async () => ({ started: scans.start("manual") }),
|
|
14707
|
-
getScanStatus: async () => scans.status()
|
|
14708
|
-
};
|
|
14709
|
-
}
|
|
14613
|
+
] };
|
|
14710
14614
|
//#endregion
|
|
14711
14615
|
//#region src/enrich.ts
|
|
14712
14616
|
/** The default order when settings name none (D1125): files next to the media, the arr app, then online. */
|
|
@@ -14882,9 +14786,7 @@ var Enricher = class {
|
|
|
14882
14786
|
const known = this.deps.cache.getMatch(key);
|
|
14883
14787
|
if (known === null) return null;
|
|
14884
14788
|
if (!known.found) return known;
|
|
14885
|
-
|
|
14886
|
-
const predatesDetails = provider.providesDetails === true && known.match.details === void 0;
|
|
14887
|
-
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;
|
|
14888
14790
|
}
|
|
14889
14791
|
/** A pinned id is asked for directly: an answer of "nothing" is final, never turned into a title guess. */
|
|
14890
14792
|
async lookup(provider, ask, item, kind, pin) {
|
|
@@ -15172,12 +15074,11 @@ async function classify(root, path, reader) {
|
|
|
15172
15074
|
if (folderSeason !== null) seriesDir = (0, node_path.dirname)(parent);
|
|
15173
15075
|
else if (parent !== root) seriesDir = parent;
|
|
15174
15076
|
}
|
|
15175
|
-
const prefix = guess.kind === "episode" ? guess.title : "";
|
|
15176
15077
|
return {
|
|
15177
15078
|
path,
|
|
15178
15079
|
kind: "episode",
|
|
15179
15080
|
seriesDir,
|
|
15180
|
-
namedTitle:
|
|
15081
|
+
namedTitle: guess.kind === "episode" ? guess.title : "",
|
|
15181
15082
|
season,
|
|
15182
15083
|
episode,
|
|
15183
15084
|
year: null
|
|
@@ -15684,53 +15585,7 @@ var MediaLibraryAddon = class extends BaseAddon {
|
|
|
15684
15585
|
this.scans?.schedule(settings.rescanMinutes);
|
|
15685
15586
|
this.scans?.start("settings");
|
|
15686
15587
|
}
|
|
15687
|
-
/**
|
|
15688
|
-
* One-time, idempotent: the metadata settings of earlier versions (an order string, switches and
|
|
15689
|
-
* four keys) become the `metadataProviders` list. The rows are written first, so each key leaves
|
|
15690
|
-
* through the normal secret write into a keychain ref addressed by its row id (D787). An old key
|
|
15691
|
-
* is released only once its row holds a stored key (a marker counts), and nothing at all is
|
|
15692
|
-
* touched while an old secret cannot be read (the keychain is locked): the next boot retries.
|
|
15693
|
-
*/
|
|
15694
|
-
async migrateLegacyProviderSettings() {
|
|
15695
|
-
const stored = await this.resolveGlobalStore(void 0, SETTINGS_CAP);
|
|
15696
|
-
if (!hasLegacyProviderKeys(stored)) return;
|
|
15697
|
-
const unreadable = LEGACY_SECRET_KEYS.filter((key) => isSecretMarker(stored[key]));
|
|
15698
|
-
if (unreadable.length > 0) {
|
|
15699
|
-
this.ctx.logger.warn("media-library provider migration postponed: a stored key is unreadable", { meta: { keys: unreadable } });
|
|
15700
|
-
return;
|
|
15701
|
-
}
|
|
15702
|
-
const parsed = array(MetadataProviderRowSchema).safeParse(stored["metadataProviders"] ?? []);
|
|
15703
|
-
if (!parsed.success) {
|
|
15704
|
-
this.ctx.logger.warn("media-library provider migration postponed: the stored list is invalid");
|
|
15705
|
-
return;
|
|
15706
|
-
}
|
|
15707
|
-
const rows = parsed.data.length === 0 ? providerRowsFromLegacy(stored) : fillMissingKeys(parsed.data, stored);
|
|
15708
|
-
if (JSON.stringify(rows) !== JSON.stringify(parsed.data)) await this.clusterSettings(SETTINGS_CAP, MediaLibrarySettingsSchema).patch({ metadataProviders: rows });
|
|
15709
|
-
const after = await this.resolveGlobalStore(void 0, SETTINGS_CAP);
|
|
15710
|
-
const held = array(MetadataProviderRowSchema).safeParse(after["metadataProviders"]);
|
|
15711
|
-
const present = LEGACY_PROVIDER_KEYS.filter((key) => stored[key] !== void 0);
|
|
15712
|
-
const releasable = present.filter((key) => !LEGACY_SECRET_KEYS.some((secret) => secret === key) || typeof stored[key] === "string" && stored[key] === "" || held.success && rowHoldsKey(held.data, key));
|
|
15713
|
-
const secrets = releasable.filter((key) => LEGACY_SECRET_KEYS.some((s) => s === key));
|
|
15714
|
-
await this.clearSecrets(secrets);
|
|
15715
|
-
const outcome = await this.unsetStoredSettingsKeys(releasable);
|
|
15716
|
-
this.ctx.logger.info("media-library provider settings migrated to the provider list", { meta: {
|
|
15717
|
-
removed: outcome.removed.length,
|
|
15718
|
-
kept: present.length - releasable.length
|
|
15719
|
-
} });
|
|
15720
|
-
}
|
|
15721
|
-
/** A failed migration never stops the boot: the old keys stay and the next boot retries. */
|
|
15722
|
-
async migrateProviderSettingsOrKeepOld() {
|
|
15723
|
-
try {
|
|
15724
|
-
await this.migrateLegacyProviderSettings();
|
|
15725
|
-
} catch (error) {
|
|
15726
|
-
this.ctx.logger.warn("media-library provider migration failed; the old settings are kept", { meta: {
|
|
15727
|
-
step: "migrateLegacyProviderSettings",
|
|
15728
|
-
error: String(error)
|
|
15729
|
-
} });
|
|
15730
|
-
}
|
|
15731
|
-
}
|
|
15732
15588
|
async onInitialize() {
|
|
15733
|
-
await this.migrateProviderSettingsOrKeepOld();
|
|
15734
15589
|
const { ctx } = this;
|
|
15735
15590
|
const logger = ctx.logger;
|
|
15736
15591
|
const db = settingsStoreDb(ctx.api.settingsStore);
|