@dominevo/addon-media-library 0.1.13 → 0.1.15
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 +809 -954
- package/dist/media-library.addon.mjs +809 -954
- 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
|
|
@@ -8612,57 +8605,6 @@ var NOT_A_DEVICE = {
|
|
|
8612
8605
|
INTERNAL: "internal plumbing between addons — never operator-facing"
|
|
8613
8606
|
};
|
|
8614
8607
|
//#endregion
|
|
8615
|
-
//#region ../types/dist/esm/capabilities/address-role-source.cap.mjs
|
|
8616
|
-
/**
|
|
8617
|
-
* `address-role-source` — the connection kinds an addon needs of the hub's address
|
|
8618
|
-
* palette (D1124). A collection cap, shaped like `retention-source` (D1084): each addon
|
|
8619
|
-
* that wants its OWN kind of connection (media playback, a notification link, …)
|
|
8620
|
-
* registers a provider and lists its declarations; the hub's collection fan-out
|
|
8621
|
-
* concatenates the answers, so no central list has to be edited and `local-network`
|
|
8622
|
-
* (which owns the palette and the operator's flags) hardcodes none.
|
|
8623
|
-
*
|
|
8624
|
-
* A declaration stores nothing. The operator's choice lives in `local-network`
|
|
8625
|
-
* (`setDeclaredAddressRole`), validated against the same palette every fixed role uses
|
|
8626
|
-
* (`HUB_ADDRESS_ROLES` stays the framework's own four). `default` says what the role
|
|
8627
|
-
* resolves to while nothing is flagged: `follow: 'connection'` means "whatever the client
|
|
8628
|
-
* is connected to" (the behaviour before the role existed), the others name a fixed role.
|
|
8629
|
-
*/
|
|
8630
|
-
var AddressRoleCardinalitySchema = /* @__PURE__ */ _enum(["many", "single"]);
|
|
8631
|
-
/** What an unflagged declared role resolves to. */
|
|
8632
|
-
var AddressRoleFollowSchema = /* @__PURE__ */ _enum([
|
|
8633
|
-
"connection",
|
|
8634
|
-
"appConnections",
|
|
8635
|
-
"publicEndpoint",
|
|
8636
|
-
"internal"
|
|
8637
|
-
]);
|
|
8638
|
-
var addressRoleSourceCapability = {
|
|
8639
|
-
name: "address-role-source",
|
|
8640
|
-
scope: "system",
|
|
8641
|
-
mode: "collection",
|
|
8642
|
-
internal: true,
|
|
8643
|
-
methods: {
|
|
8644
|
-
/** List the address roles this addon declares. */
|
|
8645
|
-
listAddressRoles: /* @__PURE__ */ method(/* @__PURE__ */ _void(), /* @__PURE__ */ array(/* @__PURE__ */ object({
|
|
8646
|
-
/** Stable id: `<addonId>:<kind>`. */
|
|
8647
|
-
id: /* @__PURE__ */ string().min(1),
|
|
8648
|
-
/** The addon that declares and consumes the role. */
|
|
8649
|
-
owner: /* @__PURE__ */ string().min(1),
|
|
8650
|
-
/** i18n key of the label (`addressRole.<owner>.<kind>`). */
|
|
8651
|
-
labelKey: /* @__PURE__ */ string().min(1),
|
|
8652
|
-
/** English fallback when the key has no translation. */
|
|
8653
|
-
label: /* @__PURE__ */ string().min(1),
|
|
8654
|
-
/** i18n key of the description. */
|
|
8655
|
-
descriptionKey: /* @__PURE__ */ string().min(1).optional(),
|
|
8656
|
-
/** English fallback of the description. */
|
|
8657
|
-
description: /* @__PURE__ */ string().min(1).optional(),
|
|
8658
|
-
/** `many`: a set of addresses the client races; `single`: at most one address carries it. */
|
|
8659
|
-
cardinality: AddressRoleCardinalitySchema,
|
|
8660
|
-
/** What the role resolves to while the operator has flagged nothing. */
|
|
8661
|
-
default: /* @__PURE__ */ object({ follow: AddressRoleFollowSchema })
|
|
8662
|
-
})).readonly(), { auth: "admin" }) },
|
|
8663
|
-
vocabulary: { notOperatorFacing: NOT_A_DEVICE.INTERNAL }
|
|
8664
|
-
};
|
|
8665
|
-
//#endregion
|
|
8666
8608
|
//#region ../types/dist/esm/capabilities/app-source.cap.mjs
|
|
8667
8609
|
/**
|
|
8668
8610
|
* `app-source` — collection cap: every addon that offers an app in the viewer
|
|
@@ -8717,22 +8659,21 @@ var AppReachSchema = /* @__PURE__ */ discriminatedUnion("kind", [
|
|
|
8717
8659
|
]);
|
|
8718
8660
|
/** The role an app is offered to. */
|
|
8719
8661
|
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
8662
|
var AppNavSectionSchema = /* @__PURE__ */ object({
|
|
8733
8663
|
id: /* @__PURE__ */ string(),
|
|
8734
8664
|
label: /* @__PURE__ */ AppLabelSchema.nullable(),
|
|
8735
|
-
items: /* @__PURE__ */ array(
|
|
8665
|
+
items: /* @__PURE__ */ array(/* @__PURE__ */ object({
|
|
8666
|
+
id: /* @__PURE__ */ string(),
|
|
8667
|
+
label: AppLabelSchema,
|
|
8668
|
+
/** A lucide icon name. */
|
|
8669
|
+
icon: /* @__PURE__ */ string(),
|
|
8670
|
+
path: /* @__PURE__ */ string(),
|
|
8671
|
+
adminOnly: /* @__PURE__ */ boolean().optional(),
|
|
8672
|
+
keywords: /* @__PURE__ */ array(/* @__PURE__ */ string()).optional(),
|
|
8673
|
+
badgeKey: /* @__PURE__ */ string().optional(),
|
|
8674
|
+
/** Interpreted by the shell (phase 4): the item is hidden while the capability is absent. */
|
|
8675
|
+
requiresCapability: /* @__PURE__ */ string().optional()
|
|
8676
|
+
}))
|
|
8736
8677
|
});
|
|
8737
8678
|
var appSourceCapability = {
|
|
8738
8679
|
name: "app-source",
|
|
@@ -8766,6 +8707,57 @@ var appSourceCapability = {
|
|
|
8766
8707
|
})).readonly(), { auth: "admin" }) },
|
|
8767
8708
|
vocabulary: { notOperatorFacing: NOT_A_DEVICE.UI_PLUMBING }
|
|
8768
8709
|
};
|
|
8710
|
+
//#endregion
|
|
8711
|
+
//#region ../types/dist/esm/capabilities/address-role-source.cap.mjs
|
|
8712
|
+
/**
|
|
8713
|
+
* `address-role-source` — the connection kinds an addon needs of the hub's address
|
|
8714
|
+
* palette (D1124). A collection cap, shaped like `retention-source` (D1084): each addon
|
|
8715
|
+
* that wants its OWN kind of connection (media playback, a notification link, …)
|
|
8716
|
+
* registers a provider and lists its declarations; the hub's collection fan-out
|
|
8717
|
+
* concatenates the answers, so no central list has to be edited and `local-network`
|
|
8718
|
+
* (which owns the palette and the operator's flags) hardcodes none.
|
|
8719
|
+
*
|
|
8720
|
+
* A declaration stores nothing. The operator's choice lives in `local-network`
|
|
8721
|
+
* (`setDeclaredAddressRole`), validated against the same palette every fixed role uses
|
|
8722
|
+
* (`HUB_ADDRESS_ROLES` stays the framework's own four). `default` says what the role
|
|
8723
|
+
* resolves to while nothing is flagged: `follow: 'connection'` means "whatever the client
|
|
8724
|
+
* is connected to" (the behaviour before the role existed), the others name a fixed role.
|
|
8725
|
+
*/
|
|
8726
|
+
var AddressRoleCardinalitySchema = /* @__PURE__ */ _enum(["many", "single"]);
|
|
8727
|
+
/** What an unflagged declared role resolves to. */
|
|
8728
|
+
var AddressRoleFollowSchema = /* @__PURE__ */ _enum([
|
|
8729
|
+
"connection",
|
|
8730
|
+
"appConnections",
|
|
8731
|
+
"publicEndpoint",
|
|
8732
|
+
"internal"
|
|
8733
|
+
]);
|
|
8734
|
+
var addressRoleSourceCapability = {
|
|
8735
|
+
name: "address-role-source",
|
|
8736
|
+
scope: "system",
|
|
8737
|
+
mode: "collection",
|
|
8738
|
+
internal: true,
|
|
8739
|
+
methods: {
|
|
8740
|
+
/** List the address roles this addon declares. */
|
|
8741
|
+
listAddressRoles: /* @__PURE__ */ method(/* @__PURE__ */ _void(), /* @__PURE__ */ array(/* @__PURE__ */ object({
|
|
8742
|
+
/** Stable id: `<addonId>:<kind>`. */
|
|
8743
|
+
id: /* @__PURE__ */ string().min(1),
|
|
8744
|
+
/** The addon that declares and consumes the role. */
|
|
8745
|
+
owner: /* @__PURE__ */ string().min(1),
|
|
8746
|
+
/** i18n key of the label (`addressRole.<owner>.<kind>`). */
|
|
8747
|
+
labelKey: /* @__PURE__ */ string().min(1),
|
|
8748
|
+
/** English fallback when the key has no translation. */
|
|
8749
|
+
label: /* @__PURE__ */ string().min(1),
|
|
8750
|
+
/** i18n key of the description. */
|
|
8751
|
+
descriptionKey: /* @__PURE__ */ string().min(1).optional(),
|
|
8752
|
+
/** English fallback of the description. */
|
|
8753
|
+
description: /* @__PURE__ */ string().min(1).optional(),
|
|
8754
|
+
/** `many`: a set of addresses the client races; `single`: at most one address carries it. */
|
|
8755
|
+
cardinality: AddressRoleCardinalitySchema,
|
|
8756
|
+
/** What the role resolves to while the operator has flagged nothing. */
|
|
8757
|
+
default: /* @__PURE__ */ object({ follow: AddressRoleFollowSchema })
|
|
8758
|
+
})).readonly(), { auth: "admin" }) },
|
|
8759
|
+
vocabulary: { notOperatorFacing: NOT_A_DEVICE.INTERNAL }
|
|
8760
|
+
};
|
|
8769
8761
|
var MediaItemKindSchema = /* @__PURE__ */ _enum([
|
|
8770
8762
|
"series",
|
|
8771
8763
|
"movie",
|
|
@@ -8975,7 +8967,20 @@ var mediaLibraryCapability = {
|
|
|
8975
8967
|
name: "media-library",
|
|
8976
8968
|
scope: "system",
|
|
8977
8969
|
mode: "singleton",
|
|
8978
|
-
role: { feature: "media" },
|
|
8970
|
+
role: { feature: "media.library" },
|
|
8971
|
+
features: [{
|
|
8972
|
+
id: "media.library",
|
|
8973
|
+
app: "media",
|
|
8974
|
+
label: {
|
|
8975
|
+
key: "feature.media.library",
|
|
8976
|
+
fallback: "Media library"
|
|
8977
|
+
},
|
|
8978
|
+
description: {
|
|
8979
|
+
key: "feature.media.library.description",
|
|
8980
|
+
fallback: "Browse the media library."
|
|
8981
|
+
},
|
|
8982
|
+
defaultRoles: ["admin", "viewer"]
|
|
8983
|
+
}],
|
|
8979
8984
|
methods: {
|
|
8980
8985
|
/** Series, sorted by title. */
|
|
8981
8986
|
listSeries: /* @__PURE__ */ method(PageInputSchema, MediaItemPageSchema, { caller: "required" }),
|
|
@@ -9088,7 +9093,8 @@ function customAction(input, output, options) {
|
|
|
9088
9093
|
kind: options?.kind ?? "query",
|
|
9089
9094
|
auth: options?.auth ?? "protected",
|
|
9090
9095
|
scope: options?.scope ?? { kind: "system" },
|
|
9091
|
-
...options?.caller ? { caller: "required" } : {}
|
|
9096
|
+
...options?.caller ? { caller: "required" } : {},
|
|
9097
|
+
...options?.feature !== void 0 ? { feature: options.feature } : {}
|
|
9092
9098
|
};
|
|
9093
9099
|
}
|
|
9094
9100
|
//#endregion
|
|
@@ -9174,7 +9180,7 @@ function buildPluginApp(version) {
|
|
|
9174
9180
|
version
|
|
9175
9181
|
},
|
|
9176
9182
|
reach: { kind: "hub" },
|
|
9177
|
-
adminOnly:
|
|
9183
|
+
adminOnly: false,
|
|
9178
9184
|
nav: [],
|
|
9179
9185
|
takesSharedSearch: false,
|
|
9180
9186
|
settings: null
|
|
@@ -9346,629 +9352,119 @@ function withOptionalId(record) {
|
|
|
9346
9352
|
};
|
|
9347
9353
|
}
|
|
9348
9354
|
//#endregion
|
|
9349
|
-
//#region src/
|
|
9350
|
-
/**
|
|
9351
|
-
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
|
|
9355
|
+
//#region src/servable.ts
|
|
9356
|
+
/**
|
|
9357
|
+
* A file is servable only when its REAL path (symlinks resolved) is inside a configured root.
|
|
9358
|
+
* The path itself comes from the catalogue by item id; this is the second lock on the same door,
|
|
9359
|
+
* so a catalogue row that names `/etc/passwd`, or a symlink that points out of the library, serves nothing.
|
|
9360
|
+
*/
|
|
9361
|
+
async function resolveServable(path, roots) {
|
|
9362
|
+
if (!(0, node_path.isAbsolute)(path) || path.includes("\0")) return null;
|
|
9363
|
+
let real;
|
|
9357
9364
|
try {
|
|
9358
|
-
|
|
9365
|
+
real = await (0, node_fs_promises.realpath)(path);
|
|
9359
9366
|
} catch {
|
|
9360
9367
|
return null;
|
|
9361
9368
|
}
|
|
9362
|
-
|
|
9363
|
-
|
|
9364
|
-
|
|
9365
|
-
|
|
9366
|
-
|
|
9367
|
-
|
|
9368
|
-
|
|
9369
|
-
|
|
9370
|
-
|
|
9371
|
-
|
|
9372
|
-
});
|
|
9373
|
-
return NEVER;
|
|
9369
|
+
for (const root of roots) {
|
|
9370
|
+
if (root === "") continue;
|
|
9371
|
+
let realRoot;
|
|
9372
|
+
try {
|
|
9373
|
+
realRoot = await (0, node_fs_promises.realpath)(root);
|
|
9374
|
+
} catch {
|
|
9375
|
+
continue;
|
|
9376
|
+
}
|
|
9377
|
+
const prefix = realRoot.endsWith(node_path.sep) ? realRoot : `${realRoot}${node_path.sep}`;
|
|
9378
|
+
if (real.startsWith(prefix)) return real;
|
|
9374
9379
|
}
|
|
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);
|
|
9380
|
+
return null;
|
|
9398
9381
|
}
|
|
9399
|
-
|
|
9400
|
-
|
|
9382
|
+
//#endregion
|
|
9383
|
+
//#region src/naming.ts
|
|
9384
|
+
/** Case- and accent-insensitive form of a title, for search and ordering. */
|
|
9385
|
+
function foldTitle(title) {
|
|
9386
|
+
return title.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim();
|
|
9401
9387
|
}
|
|
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
|
-
};
|
|
9388
|
+
/** The ordering key: the folded title without a leading article. */
|
|
9389
|
+
function sortKey(title) {
|
|
9390
|
+
return foldTitle(title).replace(/^(the|a|an|il|lo|la|le|i|gli|un|una)\s+/, "");
|
|
9432
9391
|
}
|
|
9433
|
-
/**
|
|
9434
|
-
function
|
|
9435
|
-
return
|
|
9392
|
+
/** A stable short id for a thing that has no id of its own (a folder-found file or show). */
|
|
9393
|
+
function hashKey(text) {
|
|
9394
|
+
return (0, node_crypto.createHash)("sha1").update(text).digest("hex").slice(0, 16);
|
|
9436
9395
|
}
|
|
9437
|
-
|
|
9438
|
-
|
|
9439
|
-
return row.enabled && (!isKeyedStep(step) || row.apiKey.trim() !== "");
|
|
9396
|
+
function itemId(sourceId, letter, key) {
|
|
9397
|
+
return `${sourceId}:${letter}:${key}`;
|
|
9440
9398
|
}
|
|
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;
|
|
9399
|
+
var ID_PATTERN = /^[a-z-]+:[sme]:[A-Za-z0-9]+$/;
|
|
9400
|
+
/** An item id as a client may send it: the shape this module mints, nothing else. */
|
|
9401
|
+
function isItemId(candidate) {
|
|
9402
|
+
return ID_PATTERN.test(candidate);
|
|
9449
9403
|
}
|
|
9450
|
-
/**
|
|
9451
|
-
function
|
|
9452
|
-
if (
|
|
9453
|
-
|
|
9404
|
+
/** Apply a path-prefix mapping (arr path → local path). A path outside the prefix is returned unchanged. */
|
|
9405
|
+
function mapPath(path, from, to) {
|
|
9406
|
+
if (from === "" || to === "") return path;
|
|
9407
|
+
const prefix = from.replace(/\/+$/, "");
|
|
9408
|
+
if (path === prefix) return to.replace(/\/+$/, "");
|
|
9409
|
+
if (path.startsWith(`${prefix}/`)) return `${to.replace(/\/+$/, "")}${path.slice(prefix.length)}`;
|
|
9410
|
+
return path;
|
|
9454
9411
|
}
|
|
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
|
-
};
|
|
9412
|
+
function cleanName(raw) {
|
|
9413
|
+
return raw.replace(/[._]+/g, " ").replace(/\s+/g, " ").replace(/[\s-]+$/, "").trim();
|
|
9414
|
+
}
|
|
9415
|
+
/** Guess what a file nobody catalogued is, from its name: `Show.S01E02…` is an episode, anything else a movie. */
|
|
9416
|
+
function guessFromFilename(fileName, parentDir) {
|
|
9417
|
+
const base = fileName.replace(/\.[A-Za-z0-9]+$/, "");
|
|
9418
|
+
const episode = /^(.*?)[\s._-]*S(\d{1,2})E(\d{1,3})/i.exec(base);
|
|
9419
|
+
if (episode?.[2] !== void 0 && episode[3] !== void 0) {
|
|
9420
|
+
const named = cleanName(episode[1] ?? "");
|
|
9421
|
+
return {
|
|
9422
|
+
kind: "episode",
|
|
9423
|
+
title: named === "" ? cleanName(parentDir) : named,
|
|
9424
|
+
year: null,
|
|
9425
|
+
seasonNumber: Number(episode[2]),
|
|
9426
|
+
episodeNumber: Number(episode[3])
|
|
9427
|
+
};
|
|
9428
|
+
}
|
|
9429
|
+
const year = /[([.\s_-]((?:19|20)\d{2})[)\].\s_-]/.exec(`${base} `);
|
|
9430
|
+
const title = cleanName(year ? base.slice(0, year.index) : base);
|
|
9488
9431
|
return {
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
|
|
9492
|
-
|
|
9493
|
-
|
|
9494
|
-
tvdbApiKey: keyOf(settings, "tvdb"),
|
|
9495
|
-
fanartApiKey: keyOf(settings, "fanart"),
|
|
9496
|
-
omdbApiKey: keyOf(settings, "omdb")
|
|
9432
|
+
kind: "movie",
|
|
9433
|
+
title: title === "" ? cleanName(base) : title,
|
|
9434
|
+
year: year?.[1] !== void 0 ? Number(year[1]) : null,
|
|
9435
|
+
seasonNumber: null,
|
|
9436
|
+
episodeNumber: null
|
|
9497
9437
|
};
|
|
9498
9438
|
}
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9439
|
+
//#endregion
|
|
9440
|
+
//#region src/file-plane.ts
|
|
9441
|
+
/**
|
|
9442
|
+
* Parse one `Range: bytes=…` header against a file of `size` bytes. A header this server does not
|
|
9443
|
+
* understand, and a multi-range one, is served as the whole file (200), which RFC 9110 allows.
|
|
9444
|
+
*/
|
|
9445
|
+
function parseRange(header, size) {
|
|
9446
|
+
if (header === void 0) return { kind: "full" };
|
|
9447
|
+
const match = /^bytes=(\d*)-(\d*)$/.exec(header.trim());
|
|
9448
|
+
if (match === null) return { kind: "full" };
|
|
9449
|
+
const [, first = "", last = ""] = match;
|
|
9450
|
+
if (first === "" && last === "") return { kind: "full" };
|
|
9451
|
+
if (first === "") {
|
|
9452
|
+
const suffix = Number(last);
|
|
9453
|
+
if (suffix === 0 || size === 0) return { kind: "unsatisfiable" };
|
|
9454
|
+
return {
|
|
9455
|
+
kind: "range",
|
|
9456
|
+
start: Math.max(0, size - suffix),
|
|
9457
|
+
end: size - 1
|
|
9458
|
+
};
|
|
9459
|
+
}
|
|
9460
|
+
const start = Number(first);
|
|
9461
|
+
if (start >= size) return { kind: "unsatisfiable" };
|
|
9462
|
+
const end = last === "" ? size - 1 : Math.min(Number(last), size - 1);
|
|
9463
|
+
if (end < start) return { kind: "full" };
|
|
9502
9464
|
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
|
|
9465
|
+
kind: "range",
|
|
9466
|
+
start,
|
|
9467
|
+
end
|
|
9972
9468
|
};
|
|
9973
9469
|
}
|
|
9974
9470
|
var CONTENT_TYPES = new Map([
|
|
@@ -14207,8 +13703,7 @@ function createTvdbProvider(deps) {
|
|
|
14207
13703
|
...year === null ? {} : { year: String(year) }
|
|
14208
13704
|
})).data ?? []).filter((entry) => foldTitle(entry.name ?? "") === foldTitle(title));
|
|
14209
13705
|
const sameYear = year === null ? [] : exact.filter((entry) => yearOf$2(entry.year) === year);
|
|
14210
|
-
const
|
|
14211
|
-
const ids = new Set(pool.map((entry) => Number(entry.tvdb_id)));
|
|
13706
|
+
const ids = new Set((sameYear.length > 0 ? sameYear : exact).map((entry) => Number(entry.tvdb_id)));
|
|
14212
13707
|
const [id] = [...ids];
|
|
14213
13708
|
return ids.size === 1 && id !== void 0 && Number.isInteger(id) ? detailsOf(kind, id) : null;
|
|
14214
13709
|
},
|
|
@@ -14507,220 +14002,629 @@ function createImagePlaneHandler(deps) {
|
|
|
14507
14002
|
});
|
|
14508
14003
|
return null;
|
|
14509
14004
|
}
|
|
14510
|
-
if (found.kind === "frame") rememberFailure(key);
|
|
14511
|
-
deps.logger.warn(found.kind === "frame" ? "frame grab failed" : "image fetch failed", {
|
|
14512
|
-
tags,
|
|
14513
|
-
meta: {
|
|
14514
|
-
reason: found.kind === "frame" ? "grab-failed" : "fetch-failed",
|
|
14515
|
-
error: error instanceof Error ? error.message : String(error)
|
|
14516
|
-
}
|
|
14517
|
-
});
|
|
14518
|
-
return null;
|
|
14519
|
-
}
|
|
14520
|
-
};
|
|
14521
|
-
return async (req, res) => {
|
|
14522
|
-
if (req.method !== "GET" && req.method !== "HEAD") return end(res, 405);
|
|
14523
|
-
const parts = ((req.url ?? "/").split("?")[0] ?? "/").replace(/^\//, "").split("/");
|
|
14524
|
-
const [rawId, which] = parts;
|
|
14525
|
-
let itemId = "";
|
|
14526
|
-
try {
|
|
14527
|
-
itemId = decodeURIComponent(rawId ?? "");
|
|
14528
|
-
} catch {
|
|
14529
|
-
return end(res, 404);
|
|
14530
|
-
}
|
|
14531
|
-
if (parts.length !== 2 || !isItemId(itemId) || !isImageKind(which)) {
|
|
14532
|
-
deps.logger.warn("image request refused", { meta: { reason: "bad-request" } });
|
|
14533
|
-
return end(res, 404);
|
|
14534
|
-
}
|
|
14535
|
-
const flightKey = `${itemId}:${which}`;
|
|
14536
|
-
const pending = inFlight.get(flightKey) ?? load(itemId, which);
|
|
14537
|
-
inFlight.set(flightKey, pending);
|
|
14538
|
-
let bytes;
|
|
14539
|
-
try {
|
|
14540
|
-
bytes = await pending;
|
|
14541
|
-
} finally {
|
|
14542
|
-
inFlight.delete(flightKey);
|
|
14543
|
-
}
|
|
14544
|
-
const contentType = bytes === null ? null : typeOf(bytes);
|
|
14545
|
-
if (bytes === null || contentType === null) return end(res, 404);
|
|
14546
|
-
res.writeHead(200, {
|
|
14547
|
-
"Content-Type": contentType,
|
|
14548
|
-
"Content-Length": bytes.length,
|
|
14549
|
-
"Cache-Control": "private, max-age=86400"
|
|
14550
|
-
});
|
|
14551
|
-
res.end(req.method === "HEAD" ? void 0 : bytes);
|
|
14552
|
-
};
|
|
14553
|
-
}
|
|
14554
|
-
//#endregion
|
|
14555
|
-
//#region src/probe.ts
|
|
14556
|
-
var CONTAINER_NAMES = new Map([
|
|
14557
|
-
["matroska", "mkv"],
|
|
14558
|
-
["mov", "mp4"],
|
|
14559
|
-
["avi", "avi"],
|
|
14560
|
-
["mpegts", "ts"]
|
|
14561
|
-
]);
|
|
14562
|
-
function containerOf(formats) {
|
|
14563
|
-
const first = formats.split(",")[0]?.trim() ?? formats;
|
|
14564
|
-
return CONTAINER_NAMES.get(first) ?? first;
|
|
14565
|
-
}
|
|
14566
|
-
function languageOf(tag) {
|
|
14567
|
-
if (tag === void 0 || tag === "" || tag === "und") return null;
|
|
14568
|
-
return tag;
|
|
14569
|
-
}
|
|
14570
|
-
function bitDepthOf(pixFmt) {
|
|
14571
|
-
if (pixFmt === null) return null;
|
|
14572
|
-
const match = /(?:p|le|be)(9|10|12|14|16)(?:le|be)?$/.exec(pixFmt);
|
|
14573
|
-
if (match?.[1] !== void 0) return Number(match[1]);
|
|
14574
|
-
return /^(yuv|nv|gray|rgb|bgr)/.test(pixFmt) ? 8 : null;
|
|
14575
|
-
}
|
|
14576
|
-
function hdrOf(line, doviSeen) {
|
|
14577
|
-
if (doviSeen) return "dolby-vision";
|
|
14578
|
-
if (line.includes("smpte2084")) return "hdr10";
|
|
14579
|
-
if (line.includes("arib-std-b67")) return "hlg";
|
|
14580
|
-
return null;
|
|
14581
|
-
}
|
|
14582
|
-
function channelsOf(line) {
|
|
14583
|
-
if (/\bmono\b/.test(line)) return 1;
|
|
14584
|
-
if (/\bstereo\b/.test(line)) return 2;
|
|
14585
|
-
const layout = /\b(\d)\.(\d)(?:\([a-z]+\))?/.exec(line);
|
|
14586
|
-
if (layout?.[1] !== void 0 && layout[2] !== void 0) return Number(layout[1]) + Number(layout[2]);
|
|
14587
|
-
const count = /\b(\d+) channels\b/.exec(line);
|
|
14588
|
-
return count?.[1] !== void 0 ? Number(count[1]) : null;
|
|
14589
|
-
}
|
|
14590
|
-
var STREAM_LINE = /^\s*Stream #\d+:(\d+)(?:\[[^\]]*\])?(?:\(([^)]*)\))?[^:]*: (Video|Audio|Subtitle): (.*)$/;
|
|
14591
|
-
var CHAPTER_LINE = /^\s*Chapter #\d+:\d+: start ([\d.]+), end ([\d.]+)/;
|
|
14592
|
-
var CHAPTER_TITLE = /^\s+title\s*:\s*(.*)$/;
|
|
14593
|
-
/** Parse the report `ffmpeg -i <file>` prints on stderr. A report that is not one yields no streams and no duration. */
|
|
14594
|
-
function parseFfmpegReport(report) {
|
|
14595
|
-
const lines = report.split("\n");
|
|
14596
|
-
let container = null;
|
|
14597
|
-
let durationMs = null;
|
|
14598
|
-
const streams = [];
|
|
14599
|
-
const chapters = [];
|
|
14600
|
-
let doviSeenFor = null;
|
|
14601
|
-
let inChapters = false;
|
|
14602
|
-
for (const line of lines) {
|
|
14603
|
-
const input = /^Input #\d+, ([^,]+(?:,[^,]+)*), from /.exec(line);
|
|
14604
|
-
if (input?.[1] !== void 0 && container === null) container = containerOf(input[1]);
|
|
14605
|
-
const duration = /^\s*Duration: (\d+):(\d{2}):(\d{2})\.(\d{2})/.exec(line);
|
|
14606
|
-
if (duration && durationMs === null) durationMs = (Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3])) * 1e3 + Number(duration[4]) * 10;
|
|
14607
|
-
const chapter = CHAPTER_LINE.exec(line);
|
|
14608
|
-
if (chapter?.[1] !== void 0 && chapter[2] !== void 0) {
|
|
14609
|
-
const startSec = Number(chapter[1]);
|
|
14610
|
-
const endSec = Number(chapter[2]);
|
|
14611
|
-
if (Number.isFinite(startSec) && Number.isFinite(endSec) && endSec > startSec) chapters.push({
|
|
14612
|
-
startSec,
|
|
14613
|
-
endSec,
|
|
14614
|
-
title: null
|
|
14615
|
-
});
|
|
14616
|
-
continue;
|
|
14617
|
-
}
|
|
14618
|
-
const titled = CHAPTER_TITLE.exec(line);
|
|
14619
|
-
const last = chapters[chapters.length - 1];
|
|
14620
|
-
if (titled?.[1] !== void 0 && last !== void 0 && last.title === null && inChapters) {
|
|
14621
|
-
if (titled[1].trim() !== "") chapters[chapters.length - 1] = {
|
|
14622
|
-
...last,
|
|
14623
|
-
title: titled[1].trim()
|
|
14624
|
-
};
|
|
14625
|
-
continue;
|
|
14626
|
-
}
|
|
14627
|
-
if (/^\s*Chapters:/.test(line)) inChapters = true;
|
|
14628
|
-
if (STREAM_LINE.test(line)) inChapters = false;
|
|
14629
|
-
if (/DOVI configuration record/.test(line) && streams.length > 0) {
|
|
14630
|
-
doviSeenFor = streams.length - 1;
|
|
14631
|
-
continue;
|
|
14632
|
-
}
|
|
14633
|
-
const match = STREAM_LINE.exec(line);
|
|
14634
|
-
if (!match) continue;
|
|
14635
|
-
const [, indexText, lang, kindText, rest] = match;
|
|
14636
|
-
if (indexText === void 0 || kindText === void 0 || rest === void 0) continue;
|
|
14637
|
-
const kind = kindText === "Video" ? "video" : kindText === "Audio" ? "audio" : "subtitle";
|
|
14638
|
-
const codecMatch = /^([A-Za-z0-9_]+)(?: \(([^)]*)\))?/.exec(rest);
|
|
14639
|
-
const codec = codecMatch?.[1] ?? "unknown";
|
|
14640
|
-
const rawProfile = codecMatch?.[2];
|
|
14641
|
-
const profile = kind !== "subtitle" && rawProfile !== void 0 && !/ 0x|^(default|forced)$/.test(rawProfile) ? rawProfile : null;
|
|
14642
|
-
const pixFmt = kind === "video" ? /\b(yuv[a-z0-9]*|nv\d+[a-z0-9]*|gray[a-z0-9]*|rgb[a-z0-9]*|bgr[a-z0-9]*)\b/.exec(rest)?.[1] ?? null : null;
|
|
14643
|
-
const size = kind === "video" ? /\b(\d{2,5})x(\d{2,5})\b/.exec(rest) : null;
|
|
14644
|
-
streams.push({
|
|
14645
|
-
index: Number(indexText),
|
|
14646
|
-
kind,
|
|
14647
|
-
codec,
|
|
14648
|
-
profile,
|
|
14649
|
-
language: languageOf(lang),
|
|
14650
|
-
channels: kind === "audio" ? channelsOf(rest) : null,
|
|
14651
|
-
bitDepth: kind === "video" ? bitDepthOf(pixFmt) : null,
|
|
14652
|
-
hdr: kind === "video" ? hdrOf(rest, false) : null,
|
|
14653
|
-
width: size?.[1] !== void 0 ? Number(size[1]) : null,
|
|
14654
|
-
height: size?.[2] !== void 0 ? Number(size[2]) : null,
|
|
14655
|
-
isDefault: /\(default\)/.test(rest),
|
|
14656
|
-
isForced: /\(forced\)/.test(rest)
|
|
14657
|
-
});
|
|
14658
|
-
}
|
|
14659
|
-
if (doviSeenFor !== null) {
|
|
14660
|
-
const target = streams[doviSeenFor];
|
|
14661
|
-
if (target?.kind === "video") streams[doviSeenFor] = {
|
|
14662
|
-
...target,
|
|
14663
|
-
hdr: "dolby-vision"
|
|
14664
|
-
};
|
|
14005
|
+
if (found.kind === "frame") rememberFailure(key);
|
|
14006
|
+
deps.logger.warn(found.kind === "frame" ? "frame grab failed" : "image fetch failed", {
|
|
14007
|
+
tags,
|
|
14008
|
+
meta: {
|
|
14009
|
+
reason: found.kind === "frame" ? "grab-failed" : "fetch-failed",
|
|
14010
|
+
error: error instanceof Error ? error.message : String(error)
|
|
14011
|
+
}
|
|
14012
|
+
});
|
|
14013
|
+
return null;
|
|
14014
|
+
}
|
|
14015
|
+
};
|
|
14016
|
+
return async (req, res) => {
|
|
14017
|
+
if (req.method !== "GET" && req.method !== "HEAD") return end(res, 405);
|
|
14018
|
+
const parts = ((req.url ?? "/").split("?")[0] ?? "/").replace(/^\//, "").split("/");
|
|
14019
|
+
const [rawId, which] = parts;
|
|
14020
|
+
let itemId = "";
|
|
14021
|
+
try {
|
|
14022
|
+
itemId = decodeURIComponent(rawId ?? "");
|
|
14023
|
+
} catch {
|
|
14024
|
+
return end(res, 404);
|
|
14025
|
+
}
|
|
14026
|
+
if (parts.length !== 2 || !isItemId(itemId) || !isImageKind(which)) {
|
|
14027
|
+
deps.logger.warn("image request refused", { meta: { reason: "bad-request" } });
|
|
14028
|
+
return end(res, 404);
|
|
14029
|
+
}
|
|
14030
|
+
const flightKey = `${itemId}:${which}`;
|
|
14031
|
+
const pending = inFlight.get(flightKey) ?? load(itemId, which);
|
|
14032
|
+
inFlight.set(flightKey, pending);
|
|
14033
|
+
let bytes;
|
|
14034
|
+
try {
|
|
14035
|
+
bytes = await pending;
|
|
14036
|
+
} finally {
|
|
14037
|
+
inFlight.delete(flightKey);
|
|
14038
|
+
}
|
|
14039
|
+
const contentType = bytes === null ? null : typeOf(bytes);
|
|
14040
|
+
if (bytes === null || contentType === null) return end(res, 404);
|
|
14041
|
+
res.writeHead(200, {
|
|
14042
|
+
"Content-Type": contentType,
|
|
14043
|
+
"Content-Length": bytes.length,
|
|
14044
|
+
"Cache-Control": "private, max-age=86400"
|
|
14045
|
+
});
|
|
14046
|
+
res.end(req.method === "HEAD" ? void 0 : bytes);
|
|
14047
|
+
};
|
|
14048
|
+
}
|
|
14049
|
+
//#endregion
|
|
14050
|
+
//#region src/probe.ts
|
|
14051
|
+
var CONTAINER_NAMES = new Map([
|
|
14052
|
+
["matroska", "mkv"],
|
|
14053
|
+
["mov", "mp4"],
|
|
14054
|
+
["avi", "avi"],
|
|
14055
|
+
["mpegts", "ts"]
|
|
14056
|
+
]);
|
|
14057
|
+
function containerOf(formats) {
|
|
14058
|
+
const first = formats.split(",")[0]?.trim() ?? formats;
|
|
14059
|
+
return CONTAINER_NAMES.get(first) ?? first;
|
|
14060
|
+
}
|
|
14061
|
+
function languageOf(tag) {
|
|
14062
|
+
if (tag === void 0 || tag === "" || tag === "und") return null;
|
|
14063
|
+
return tag;
|
|
14064
|
+
}
|
|
14065
|
+
function bitDepthOf(pixFmt) {
|
|
14066
|
+
if (pixFmt === null) return null;
|
|
14067
|
+
const match = /(?:p|le|be)(9|10|12|14|16)(?:le|be)?$/.exec(pixFmt);
|
|
14068
|
+
if (match?.[1] !== void 0) return Number(match[1]);
|
|
14069
|
+
return /^(yuv|nv|gray|rgb|bgr)/.test(pixFmt) ? 8 : null;
|
|
14070
|
+
}
|
|
14071
|
+
function hdrOf(line, doviSeen) {
|
|
14072
|
+
if (doviSeen) return "dolby-vision";
|
|
14073
|
+
if (line.includes("smpte2084")) return "hdr10";
|
|
14074
|
+
if (line.includes("arib-std-b67")) return "hlg";
|
|
14075
|
+
return null;
|
|
14076
|
+
}
|
|
14077
|
+
function channelsOf(line) {
|
|
14078
|
+
if (/\bmono\b/.test(line)) return 1;
|
|
14079
|
+
if (/\bstereo\b/.test(line)) return 2;
|
|
14080
|
+
const layout = /\b(\d)\.(\d)(?:\([a-z]+\))?/.exec(line);
|
|
14081
|
+
if (layout?.[1] !== void 0 && layout[2] !== void 0) return Number(layout[1]) + Number(layout[2]);
|
|
14082
|
+
const count = /\b(\d+) channels\b/.exec(line);
|
|
14083
|
+
return count?.[1] !== void 0 ? Number(count[1]) : null;
|
|
14084
|
+
}
|
|
14085
|
+
var STREAM_LINE = /^\s*Stream #\d+:(\d+)(?:\[[^\]]*\])?(?:\(([^)]*)\))?[^:]*: (Video|Audio|Subtitle): (.*)$/;
|
|
14086
|
+
var CHAPTER_LINE = /^\s*Chapter #\d+:\d+: start ([\d.]+), end ([\d.]+)/;
|
|
14087
|
+
var CHAPTER_TITLE = /^\s+title\s*:\s*(.*)$/;
|
|
14088
|
+
/** Parse the report `ffmpeg -i <file>` prints on stderr. A report that is not one yields no streams and no duration. */
|
|
14089
|
+
function parseFfmpegReport(report) {
|
|
14090
|
+
const lines = report.split("\n");
|
|
14091
|
+
let container = null;
|
|
14092
|
+
let durationMs = null;
|
|
14093
|
+
const streams = [];
|
|
14094
|
+
const chapters = [];
|
|
14095
|
+
let doviSeenFor = null;
|
|
14096
|
+
let inChapters = false;
|
|
14097
|
+
for (const line of lines) {
|
|
14098
|
+
const input = /^Input #\d+, ([^,]+(?:,[^,]+)*), from /.exec(line);
|
|
14099
|
+
if (input?.[1] !== void 0 && container === null) container = containerOf(input[1]);
|
|
14100
|
+
const duration = /^\s*Duration: (\d+):(\d{2}):(\d{2})\.(\d{2})/.exec(line);
|
|
14101
|
+
if (duration && durationMs === null) durationMs = (Number(duration[1]) * 3600 + Number(duration[2]) * 60 + Number(duration[3])) * 1e3 + Number(duration[4]) * 10;
|
|
14102
|
+
const chapter = CHAPTER_LINE.exec(line);
|
|
14103
|
+
if (chapter?.[1] !== void 0 && chapter[2] !== void 0) {
|
|
14104
|
+
const startSec = Number(chapter[1]);
|
|
14105
|
+
const endSec = Number(chapter[2]);
|
|
14106
|
+
if (Number.isFinite(startSec) && Number.isFinite(endSec) && endSec > startSec) chapters.push({
|
|
14107
|
+
startSec,
|
|
14108
|
+
endSec,
|
|
14109
|
+
title: null
|
|
14110
|
+
});
|
|
14111
|
+
continue;
|
|
14112
|
+
}
|
|
14113
|
+
const titled = CHAPTER_TITLE.exec(line);
|
|
14114
|
+
const last = chapters[chapters.length - 1];
|
|
14115
|
+
if (titled?.[1] !== void 0 && last !== void 0 && last.title === null && inChapters) {
|
|
14116
|
+
if (titled[1].trim() !== "") chapters[chapters.length - 1] = {
|
|
14117
|
+
...last,
|
|
14118
|
+
title: titled[1].trim()
|
|
14119
|
+
};
|
|
14120
|
+
continue;
|
|
14121
|
+
}
|
|
14122
|
+
if (/^\s*Chapters:/.test(line)) inChapters = true;
|
|
14123
|
+
if (STREAM_LINE.test(line)) inChapters = false;
|
|
14124
|
+
if (/DOVI configuration record/.test(line) && streams.length > 0) {
|
|
14125
|
+
doviSeenFor = streams.length - 1;
|
|
14126
|
+
continue;
|
|
14127
|
+
}
|
|
14128
|
+
const match = STREAM_LINE.exec(line);
|
|
14129
|
+
if (!match) continue;
|
|
14130
|
+
const [, indexText, lang, kindText, rest] = match;
|
|
14131
|
+
if (indexText === void 0 || kindText === void 0 || rest === void 0) continue;
|
|
14132
|
+
const kind = kindText === "Video" ? "video" : kindText === "Audio" ? "audio" : "subtitle";
|
|
14133
|
+
const codecMatch = /^([A-Za-z0-9_]+)(?: \(([^)]*)\))?/.exec(rest);
|
|
14134
|
+
const codec = codecMatch?.[1] ?? "unknown";
|
|
14135
|
+
const rawProfile = codecMatch?.[2];
|
|
14136
|
+
const profile = kind !== "subtitle" && rawProfile !== void 0 && !/ 0x|^(default|forced)$/.test(rawProfile) ? rawProfile : null;
|
|
14137
|
+
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;
|
|
14138
|
+
const size = kind === "video" ? /\b(\d{2,5})x(\d{2,5})\b/.exec(rest) : null;
|
|
14139
|
+
streams.push({
|
|
14140
|
+
index: Number(indexText),
|
|
14141
|
+
kind,
|
|
14142
|
+
codec,
|
|
14143
|
+
profile,
|
|
14144
|
+
language: languageOf(lang),
|
|
14145
|
+
channels: kind === "audio" ? channelsOf(rest) : null,
|
|
14146
|
+
bitDepth: kind === "video" ? bitDepthOf(pixFmt) : null,
|
|
14147
|
+
hdr: kind === "video" ? hdrOf(rest, false) : null,
|
|
14148
|
+
width: size?.[1] !== void 0 ? Number(size[1]) : null,
|
|
14149
|
+
height: size?.[2] !== void 0 ? Number(size[2]) : null,
|
|
14150
|
+
isDefault: /\(default\)/.test(rest),
|
|
14151
|
+
isForced: /\(forced\)/.test(rest)
|
|
14152
|
+
});
|
|
14153
|
+
}
|
|
14154
|
+
if (doviSeenFor !== null) {
|
|
14155
|
+
const target = streams[doviSeenFor];
|
|
14156
|
+
if (target?.kind === "video") streams[doviSeenFor] = {
|
|
14157
|
+
...target,
|
|
14158
|
+
hdr: "dolby-vision"
|
|
14159
|
+
};
|
|
14160
|
+
}
|
|
14161
|
+
return {
|
|
14162
|
+
container,
|
|
14163
|
+
durationMs,
|
|
14164
|
+
streams,
|
|
14165
|
+
chapters
|
|
14166
|
+
};
|
|
14167
|
+
}
|
|
14168
|
+
var PROBE_TIMEOUT_MS = 3e4;
|
|
14169
|
+
var REPORT_MAX_BYTES = 1024 * 1024;
|
|
14170
|
+
/**
|
|
14171
|
+
* ONE ffmpeg per file, reading the input report. ffmpeg exits non-zero with no output file
|
|
14172
|
+
* (the report is on stderr), so a non-zero exit is expected and only a missing report is a failure.
|
|
14173
|
+
*/
|
|
14174
|
+
function createFfmpegProber(binaryPath) {
|
|
14175
|
+
return (path) => new Promise((resolve, reject) => {
|
|
14176
|
+
(0, node_child_process.execFile)(binaryPath, [
|
|
14177
|
+
"-hide_banner",
|
|
14178
|
+
"-nostdin",
|
|
14179
|
+
"-i",
|
|
14180
|
+
path
|
|
14181
|
+
], {
|
|
14182
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
14183
|
+
maxBuffer: REPORT_MAX_BYTES,
|
|
14184
|
+
encoding: "utf8"
|
|
14185
|
+
}, (error, _stdout, stderr) => {
|
|
14186
|
+
if (error !== null && (error.killed === true || stderr === "")) {
|
|
14187
|
+
reject(new Error(error.killed === true ? "probe timed out" : error.message));
|
|
14188
|
+
return;
|
|
14189
|
+
}
|
|
14190
|
+
const result = parseFfmpegReport(stderr);
|
|
14191
|
+
if (result.streams.length === 0) reject(/* @__PURE__ */ new Error("no streams in the report"));
|
|
14192
|
+
else resolve(result);
|
|
14193
|
+
});
|
|
14194
|
+
});
|
|
14195
|
+
}
|
|
14196
|
+
//#endregion
|
|
14197
|
+
//#region src/provider.ts
|
|
14198
|
+
/** The `media-library` capability over the store. A caller reads and writes only their own progress. */
|
|
14199
|
+
function createMediaLibraryProvider(store, scans) {
|
|
14200
|
+
return {
|
|
14201
|
+
listSeries: ({ limit, offset, language, caller }) => store.listSeries(caller.userId, limit, offset, language),
|
|
14202
|
+
listMovies: ({ limit, offset, language, caller }) => store.listMovies(caller.userId, limit, offset, language),
|
|
14203
|
+
listSeasons: ({ seriesId, caller }) => store.listSeasons(caller.userId, seriesId),
|
|
14204
|
+
listEpisodes: ({ seriesId, seasonNumber, language, caller }) => store.listEpisodes(caller.userId, seriesId, seasonNumber, language),
|
|
14205
|
+
getItem: ({ itemId, language, caller }) => store.getItem(caller.userId, itemId, language),
|
|
14206
|
+
search: ({ query, limit, language, caller }) => store.search(caller.userId, query, limit, language),
|
|
14207
|
+
listRecentlyAdded: ({ limit, language, caller }) => store.listRecentlyAdded(caller.userId, limit, language),
|
|
14208
|
+
listWatchlist: ({ limit, offset, language, caller }) => store.listWatchlist(caller.userId, limit, offset, language),
|
|
14209
|
+
setWatchlisted: ({ itemId, on, caller }) => store.setWatchlisted(caller.userId, itemId, on),
|
|
14210
|
+
getItemDetails: ({ itemId, language }) => store.getItemDetails(itemId, language),
|
|
14211
|
+
getProgress: ({ itemId, caller }) => store.getProgress(caller.userId, itemId),
|
|
14212
|
+
setProgress: ({ caller, ...input }) => store.setProgress(caller.userId, input),
|
|
14213
|
+
markWatched: ({ caller, ...input }) => store.markWatched(caller.userId, input),
|
|
14214
|
+
listContinue: ({ limit, language, caller }) => store.listContinue(caller.userId, limit, language),
|
|
14215
|
+
rescan: async () => ({ started: scans.start("manual") }),
|
|
14216
|
+
getScanStatus: async () => scans.status()
|
|
14217
|
+
};
|
|
14218
|
+
}
|
|
14219
|
+
//#endregion
|
|
14220
|
+
//#region src/settings.ts
|
|
14221
|
+
/** The capability that owns the cluster-scoped settings (D986). */
|
|
14222
|
+
var SETTINGS_CAP = "media-library";
|
|
14223
|
+
/** An http(s) base URL without credentials, query or trailing slash; `''` is "not configured"; `null` is invalid. */
|
|
14224
|
+
function normalizeBaseUrl(raw) {
|
|
14225
|
+
const text = raw.trim();
|
|
14226
|
+
if (text === "") return "";
|
|
14227
|
+
let url;
|
|
14228
|
+
try {
|
|
14229
|
+
url = new URL(text);
|
|
14230
|
+
} catch {
|
|
14231
|
+
return null;
|
|
14232
|
+
}
|
|
14233
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
|
|
14234
|
+
if (url.username !== "" || url.password !== "" || url.search !== "" || url.hash !== "") return null;
|
|
14235
|
+
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
|
14236
|
+
}
|
|
14237
|
+
var BaseUrlSchema = string().transform((value, ctx) => {
|
|
14238
|
+
const normalized = normalizeBaseUrl(value);
|
|
14239
|
+
if (normalized === null) {
|
|
14240
|
+
ctx.addIssue({
|
|
14241
|
+
code: "custom",
|
|
14242
|
+
message: "expected an http(s) URL"
|
|
14243
|
+
});
|
|
14244
|
+
return NEVER;
|
|
14245
|
+
}
|
|
14246
|
+
return normalized;
|
|
14247
|
+
});
|
|
14248
|
+
/** The metadata steps, in the order they answer by default: files, the arr app, then online (each needs its key or switch), pictures last. */
|
|
14249
|
+
var METADATA_STEPS = [
|
|
14250
|
+
"local",
|
|
14251
|
+
"arr",
|
|
14252
|
+
"tmdb",
|
|
14253
|
+
"tvmaze",
|
|
14254
|
+
"tvdb",
|
|
14255
|
+
"omdb",
|
|
14256
|
+
"anilist",
|
|
14257
|
+
"fanart"
|
|
14258
|
+
];
|
|
14259
|
+
var DEFAULT_METADATA_ORDER = METADATA_STEPS;
|
|
14260
|
+
/** The steps that cannot answer without the installation's own key. */
|
|
14261
|
+
var KEYED_STEPS = [
|
|
14262
|
+
"tmdb",
|
|
14263
|
+
"tvdb",
|
|
14264
|
+
"omdb",
|
|
14265
|
+
"fanart"
|
|
14266
|
+
];
|
|
14267
|
+
function isStep(value) {
|
|
14268
|
+
return METADATA_STEPS.some((step) => step === value);
|
|
14269
|
+
}
|
|
14270
|
+
function isKeyedStep(step) {
|
|
14271
|
+
return KEYED_STEPS.some((keyed) => keyed === step);
|
|
14272
|
+
}
|
|
14273
|
+
/** What the settings list shows for each step. */
|
|
14274
|
+
var STEP_NAMES = {
|
|
14275
|
+
local: "Local files",
|
|
14276
|
+
arr: "Sonarr and Radarr",
|
|
14277
|
+
tmdb: "TMDB",
|
|
14278
|
+
tvmaze: "TVmaze",
|
|
14279
|
+
tvdb: "TheTVDB",
|
|
14280
|
+
omdb: "OMDb",
|
|
14281
|
+
anilist: "AniList",
|
|
14282
|
+
fanart: "Fanart.tv"
|
|
14283
|
+
};
|
|
14284
|
+
/** One row of the metadata chain: the row order is the order the steps answer in (D1125). */
|
|
14285
|
+
var MetadataProviderRowSchema = object({
|
|
14286
|
+
/** The step this row is; stable, it addresses the row's secret. */
|
|
14287
|
+
id: string(),
|
|
14288
|
+
/** The step's display name, stamped by the addon for the row title. */
|
|
14289
|
+
name: string().default(""),
|
|
14290
|
+
enabled: boolean().default(true),
|
|
14291
|
+
/** The installation's own key or token, for a keyed step; unused by the others. */
|
|
14292
|
+
apiKey: string().meta({ secret: true }).default("")
|
|
14293
|
+
});
|
|
14294
|
+
/** A row for `step`; AniList needs no account but sends titles out, so it starts off. */
|
|
14295
|
+
function providerRow(step, patch = {}) {
|
|
14296
|
+
return {
|
|
14297
|
+
id: step,
|
|
14298
|
+
name: STEP_NAMES[step],
|
|
14299
|
+
enabled: step !== "anilist",
|
|
14300
|
+
apiKey: "",
|
|
14301
|
+
...patch
|
|
14302
|
+
};
|
|
14303
|
+
}
|
|
14304
|
+
/** The list a fresh installation starts from: every step, in the default order. */
|
|
14305
|
+
function defaultProviderRows() {
|
|
14306
|
+
return DEFAULT_METADATA_ORDER.map((step) => providerRow(step));
|
|
14307
|
+
}
|
|
14308
|
+
/** A keyed row answers only with a key; the other steps need none. */
|
|
14309
|
+
function rowAnswers(row, step) {
|
|
14310
|
+
return row.enabled && (!isKeyedStep(step) || row.apiKey.trim() !== "");
|
|
14311
|
+
}
|
|
14312
|
+
/** 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. */
|
|
14313
|
+
function resolveMetadataSteps(settings) {
|
|
14314
|
+
const out = [];
|
|
14315
|
+
for (const row of settings.metadataProviders) {
|
|
14316
|
+
const step = row.id.toLowerCase();
|
|
14317
|
+
if (isStep(step) && rowAnswers(row, step) && !out.includes(step)) out.push(step);
|
|
14318
|
+
}
|
|
14319
|
+
return out;
|
|
14320
|
+
}
|
|
14321
|
+
/** The key of a keyed step, or `''` when the step is not answering. */
|
|
14322
|
+
function keyOf(settings, step) {
|
|
14323
|
+
if (!resolveMetadataSteps(settings).includes(step)) return "";
|
|
14324
|
+
return settings.metadataProviders.find((candidate) => candidate.id.toLowerCase() === step)?.apiKey.trim() ?? "";
|
|
14325
|
+
}
|
|
14326
|
+
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.";
|
|
14327
|
+
var MediaLibrarySettingsSchema = object({
|
|
14328
|
+
seriesArrUrl: BaseUrlSchema.default(""),
|
|
14329
|
+
seriesArrKey: string().default(""),
|
|
14330
|
+
/** Where the series app sees the library, and where this node mounts it. */
|
|
14331
|
+
seriesPathFrom: string().default(""),
|
|
14332
|
+
seriesPathTo: string().default(""),
|
|
14333
|
+
moviesArrUrl: BaseUrlSchema.default(""),
|
|
14334
|
+
moviesArrKey: string().default(""),
|
|
14335
|
+
moviesPathFrom: string().default(""),
|
|
14336
|
+
moviesPathTo: string().default(""),
|
|
14337
|
+
/** Plain folders walked for files the arr apps do not know, one absolute path per line. */
|
|
14338
|
+
folderRoots: string().default(""),
|
|
14339
|
+
rescanMinutes: number().int().min(0).default(60),
|
|
14340
|
+
/** Scrub thumbnails, generated in the background with ffmpeg and cached under the addon's data dir. */
|
|
14341
|
+
trickplay: boolean().default(true),
|
|
14342
|
+
/** The metadata chain, one row per step in the order they answer; the first answer to a field wins (D1125). */
|
|
14343
|
+
metadataProviders: array(MetadataProviderRowSchema).default(defaultProviderRows),
|
|
14344
|
+
/** The Plex import (a one-shot, re-runnable action): the server, a token, and how paths and users line up. */
|
|
14345
|
+
plexUrl: BaseUrlSchema.default(""),
|
|
14346
|
+
plexToken: string().meta({ secret: true }).default(""),
|
|
14347
|
+
plexPathFrom: string().default(""),
|
|
14348
|
+
plexPathTo: string().default(""),
|
|
14349
|
+
plexUserMap: string().default("")
|
|
14350
|
+
});
|
|
14351
|
+
/** A source is on only when both its URL and key are set; a half-filled one is off, not guessed. */
|
|
14352
|
+
function resolveSources(settings) {
|
|
14353
|
+
const pick = (baseUrl, apiKey, pathFrom, pathTo) => baseUrl === "" || apiKey === "" ? null : {
|
|
14354
|
+
baseUrl,
|
|
14355
|
+
apiKey,
|
|
14356
|
+
pathFrom: pathFrom.trim(),
|
|
14357
|
+
pathTo: pathTo.trim()
|
|
14358
|
+
};
|
|
14359
|
+
return {
|
|
14360
|
+
series: pick(settings.seriesArrUrl, settings.seriesArrKey, settings.seriesPathFrom, settings.seriesPathTo),
|
|
14361
|
+
movies: pick(settings.moviesArrUrl, settings.moviesArrKey, settings.moviesPathFrom, settings.moviesPathTo),
|
|
14362
|
+
folderRoots: settings.folderRoots.split("\n").map((line) => line.trim()).filter((line) => line !== ""),
|
|
14363
|
+
metadataSteps: resolveMetadataSteps(settings),
|
|
14364
|
+
tmdbToken: keyOf(settings, "tmdb"),
|
|
14365
|
+
tvdbApiKey: keyOf(settings, "tvdb"),
|
|
14366
|
+
fanartApiKey: keyOf(settings, "fanart"),
|
|
14367
|
+
omdbApiKey: keyOf(settings, "omdb")
|
|
14368
|
+
};
|
|
14369
|
+
}
|
|
14370
|
+
/** The import is configured only when both the server URL and the token are set. */
|
|
14371
|
+
function resolvePlex(settings) {
|
|
14372
|
+
if (settings.plexUrl === "" || settings.plexToken === "") return null;
|
|
14373
|
+
return {
|
|
14374
|
+
baseUrl: settings.plexUrl,
|
|
14375
|
+
token: settings.plexToken,
|
|
14376
|
+
pathFrom: settings.plexPathFrom.trim(),
|
|
14377
|
+
pathTo: settings.plexPathTo.trim(),
|
|
14378
|
+
userMap: settings.plexUserMap
|
|
14379
|
+
};
|
|
14380
|
+
}
|
|
14381
|
+
var MEDIA_LIBRARY_CLUSTER_SCHEMA = { sections: [
|
|
14382
|
+
{
|
|
14383
|
+
id: "series",
|
|
14384
|
+
title: "Series source",
|
|
14385
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.title",
|
|
14386
|
+
fields: [
|
|
14387
|
+
{
|
|
14388
|
+
type: "text",
|
|
14389
|
+
key: "seriesArrUrl",
|
|
14390
|
+
label: "Sonarr URL",
|
|
14391
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrUrl.label",
|
|
14392
|
+
description: "Address of the series app, for example http://192.168.1.20:8989. Empty turns the source off.",
|
|
14393
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrUrl.description"
|
|
14394
|
+
},
|
|
14395
|
+
{
|
|
14396
|
+
type: "password",
|
|
14397
|
+
key: "seriesArrKey",
|
|
14398
|
+
label: "Sonarr API key",
|
|
14399
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesArrKey.label"
|
|
14400
|
+
},
|
|
14401
|
+
{
|
|
14402
|
+
type: "text",
|
|
14403
|
+
key: "seriesPathFrom",
|
|
14404
|
+
label: "Path in Sonarr",
|
|
14405
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathFrom.label",
|
|
14406
|
+
description: "The library folder as the series app sees it, for example /tv.",
|
|
14407
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathFrom.description"
|
|
14408
|
+
},
|
|
14409
|
+
{
|
|
14410
|
+
type: "text",
|
|
14411
|
+
key: "seriesPathTo",
|
|
14412
|
+
label: "Path on this hub",
|
|
14413
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathTo.label",
|
|
14414
|
+
description: "Where the same folder is mounted on this hub.",
|
|
14415
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_series.seriesPathTo.description"
|
|
14416
|
+
}
|
|
14417
|
+
]
|
|
14418
|
+
},
|
|
14419
|
+
{
|
|
14420
|
+
id: "movies",
|
|
14421
|
+
title: "Movies source",
|
|
14422
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.title",
|
|
14423
|
+
fields: [
|
|
14424
|
+
{
|
|
14425
|
+
type: "text",
|
|
14426
|
+
key: "moviesArrUrl",
|
|
14427
|
+
label: "Radarr URL",
|
|
14428
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrUrl.label",
|
|
14429
|
+
description: "Address of the movies app, for example http://192.168.1.20:7878. Empty turns the source off.",
|
|
14430
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrUrl.description"
|
|
14431
|
+
},
|
|
14432
|
+
{
|
|
14433
|
+
type: "password",
|
|
14434
|
+
key: "moviesArrKey",
|
|
14435
|
+
label: "Radarr API key",
|
|
14436
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesArrKey.label"
|
|
14437
|
+
},
|
|
14438
|
+
{
|
|
14439
|
+
type: "text",
|
|
14440
|
+
key: "moviesPathFrom",
|
|
14441
|
+
label: "Path in Radarr",
|
|
14442
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathFrom.label",
|
|
14443
|
+
description: "The library folder as the movies app sees it, for example /movies.",
|
|
14444
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathFrom.description"
|
|
14445
|
+
},
|
|
14446
|
+
{
|
|
14447
|
+
type: "text",
|
|
14448
|
+
key: "moviesPathTo",
|
|
14449
|
+
label: "Path on this hub",
|
|
14450
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathTo.label",
|
|
14451
|
+
description: "Where the same folder is mounted on this hub.",
|
|
14452
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_movies.moviesPathTo.description"
|
|
14453
|
+
}
|
|
14454
|
+
]
|
|
14455
|
+
},
|
|
14456
|
+
{
|
|
14457
|
+
id: "folders",
|
|
14458
|
+
title: "Folders",
|
|
14459
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.title",
|
|
14460
|
+
fields: [
|
|
14461
|
+
{
|
|
14462
|
+
type: "textarea",
|
|
14463
|
+
key: "folderRoots",
|
|
14464
|
+
label: "Folders to walk",
|
|
14465
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.folderRoots.label",
|
|
14466
|
+
description: "One absolute path per line. Files the arr apps do not know are added from here.",
|
|
14467
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.folderRoots.description"
|
|
14468
|
+
},
|
|
14469
|
+
{
|
|
14470
|
+
type: "number",
|
|
14471
|
+
key: "rescanMinutes",
|
|
14472
|
+
label: "Rescan every (minutes)",
|
|
14473
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.rescanMinutes.label",
|
|
14474
|
+
description: "0 scans only when asked.",
|
|
14475
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.rescanMinutes.description",
|
|
14476
|
+
min: 0
|
|
14477
|
+
},
|
|
14478
|
+
{
|
|
14479
|
+
type: "boolean",
|
|
14480
|
+
key: "trickplay",
|
|
14481
|
+
label: "Scrub thumbnails",
|
|
14482
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.trickplay.label",
|
|
14483
|
+
description: "Generate preview pictures for the seek bar in the background, one ffmpeg at a time at low priority.",
|
|
14484
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_folders.trickplay.description"
|
|
14485
|
+
}
|
|
14486
|
+
]
|
|
14487
|
+
},
|
|
14488
|
+
{
|
|
14489
|
+
id: "metadata",
|
|
14490
|
+
title: "Metadata",
|
|
14491
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.title",
|
|
14492
|
+
fields: [{
|
|
14493
|
+
type: "info",
|
|
14494
|
+
key: "providersGuide",
|
|
14495
|
+
label: "How to get the keys",
|
|
14496
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.providersGuide.label",
|
|
14497
|
+
format: "html",
|
|
14498
|
+
content: PROVIDERS_GUIDE_EN,
|
|
14499
|
+
contentKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.providersGuide.content"
|
|
14500
|
+
}, {
|
|
14501
|
+
type: "editable-array",
|
|
14502
|
+
key: "metadataProviders",
|
|
14503
|
+
label: "Metadata providers",
|
|
14504
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.label",
|
|
14505
|
+
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.",
|
|
14506
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.description",
|
|
14507
|
+
default: defaultProviderRows(),
|
|
14508
|
+
reorderable: true,
|
|
14509
|
+
fixedRows: true,
|
|
14510
|
+
itemIdKey: "id",
|
|
14511
|
+
rowTitleTemplate: "{name}",
|
|
14512
|
+
itemFields: [
|
|
14513
|
+
{
|
|
14514
|
+
type: "text",
|
|
14515
|
+
key: "id",
|
|
14516
|
+
label: "Provider",
|
|
14517
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.id.label",
|
|
14518
|
+
showWhen: {
|
|
14519
|
+
field: "id",
|
|
14520
|
+
equals: ""
|
|
14521
|
+
}
|
|
14522
|
+
},
|
|
14523
|
+
{
|
|
14524
|
+
type: "text",
|
|
14525
|
+
key: "name",
|
|
14526
|
+
label: "Name",
|
|
14527
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.name.label",
|
|
14528
|
+
showWhen: {
|
|
14529
|
+
field: "id",
|
|
14530
|
+
equals: ""
|
|
14531
|
+
}
|
|
14532
|
+
},
|
|
14533
|
+
{
|
|
14534
|
+
type: "boolean",
|
|
14535
|
+
key: "enabled",
|
|
14536
|
+
label: "Use this provider",
|
|
14537
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.enabled.label"
|
|
14538
|
+
},
|
|
14539
|
+
{
|
|
14540
|
+
type: "password",
|
|
14541
|
+
key: "apiKey",
|
|
14542
|
+
label: "API key or token",
|
|
14543
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.apiKey.label",
|
|
14544
|
+
description: "The key of your own account, stored in the keychain. Without it this provider is skipped.",
|
|
14545
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_metadata.metadataProviders.apiKey.description",
|
|
14546
|
+
showWhen: {
|
|
14547
|
+
field: "id",
|
|
14548
|
+
in: [...KEYED_STEPS]
|
|
14549
|
+
}
|
|
14550
|
+
}
|
|
14551
|
+
]
|
|
14552
|
+
}]
|
|
14553
|
+
},
|
|
14554
|
+
{
|
|
14555
|
+
id: "plex",
|
|
14556
|
+
title: "Import from Plex",
|
|
14557
|
+
titleKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.title",
|
|
14558
|
+
fields: [
|
|
14559
|
+
{
|
|
14560
|
+
type: "text",
|
|
14561
|
+
key: "plexUrl",
|
|
14562
|
+
label: "Plex server URL",
|
|
14563
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUrl.label",
|
|
14564
|
+
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.",
|
|
14565
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUrl.description"
|
|
14566
|
+
},
|
|
14567
|
+
{
|
|
14568
|
+
type: "password",
|
|
14569
|
+
key: "plexToken",
|
|
14570
|
+
label: "Plex token",
|
|
14571
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexToken.label",
|
|
14572
|
+
description: "The server owner's X-Plex-Token. Stored in the keychain.",
|
|
14573
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexToken.description"
|
|
14574
|
+
},
|
|
14575
|
+
{
|
|
14576
|
+
type: "text",
|
|
14577
|
+
key: "plexPathFrom",
|
|
14578
|
+
label: "Path in Plex",
|
|
14579
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathFrom.label",
|
|
14580
|
+
description: "The library folder as Plex sees it, for example /data/movies. Used to match files by path when the ids do not match.",
|
|
14581
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathFrom.description"
|
|
14582
|
+
},
|
|
14583
|
+
{
|
|
14584
|
+
type: "text",
|
|
14585
|
+
key: "plexPathTo",
|
|
14586
|
+
label: "Path on this hub",
|
|
14587
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathTo.label",
|
|
14588
|
+
description: "Where the same folder is mounted on this hub.",
|
|
14589
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexPathTo.description"
|
|
14590
|
+
},
|
|
14591
|
+
{
|
|
14592
|
+
type: "textarea",
|
|
14593
|
+
key: "plexUserMap",
|
|
14594
|
+
label: "Plex user to Dominevo user",
|
|
14595
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUserMap.label",
|
|
14596
|
+
description: "One \"plexName = dominevoUsername\" per line. Without a line a Plex user is matched by username, title or email.",
|
|
14597
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.plexUserMap.description"
|
|
14598
|
+
},
|
|
14599
|
+
{
|
|
14600
|
+
type: "addon-action-button",
|
|
14601
|
+
addonId: "media-library",
|
|
14602
|
+
key: "__plex-import-preview",
|
|
14603
|
+
label: "Preview the Plex import",
|
|
14604
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-preview.label",
|
|
14605
|
+
description: "Reads Plex and works out what would be imported per user. Writes nothing. Save the settings first.",
|
|
14606
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-preview.description",
|
|
14607
|
+
buttonLabel: "Preview",
|
|
14608
|
+
action: "plexImportPreview",
|
|
14609
|
+
successMessage: "{message}"
|
|
14610
|
+
},
|
|
14611
|
+
{
|
|
14612
|
+
type: "addon-action-button",
|
|
14613
|
+
addonId: "media-library",
|
|
14614
|
+
key: "__plex-import-run",
|
|
14615
|
+
label: "Import from Plex",
|
|
14616
|
+
labelKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-run.label",
|
|
14617
|
+
description: "Imports watched state, resume positions and Plex's TMDB/TVDB/IMDb ids. Safe to run again: a newer Dominevo position is never overwritten.",
|
|
14618
|
+
descriptionKey: "media-library:mediaLibraryAddon.clusterSettings.s_plex.__plex-import-run.description",
|
|
14619
|
+
buttonLabel: "Import",
|
|
14620
|
+
action: "plexImportRun",
|
|
14621
|
+
variant: "primary",
|
|
14622
|
+
confirmMessage: "Import watch history and ids from Plex now?",
|
|
14623
|
+
successMessage: "{message}"
|
|
14624
|
+
}
|
|
14625
|
+
]
|
|
14665
14626
|
}
|
|
14666
|
-
|
|
14667
|
-
container,
|
|
14668
|
-
durationMs,
|
|
14669
|
-
streams,
|
|
14670
|
-
chapters
|
|
14671
|
-
};
|
|
14672
|
-
}
|
|
14673
|
-
var PROBE_TIMEOUT_MS = 3e4;
|
|
14674
|
-
var REPORT_MAX_BYTES = 1024 * 1024;
|
|
14675
|
-
/**
|
|
14676
|
-
* ONE ffmpeg per file, reading the input report. ffmpeg exits non-zero with no output file
|
|
14677
|
-
* (the report is on stderr), so a non-zero exit is expected and only a missing report is a failure.
|
|
14678
|
-
*/
|
|
14679
|
-
function createFfmpegProber(binaryPath) {
|
|
14680
|
-
return (path) => new Promise((resolve, reject) => {
|
|
14681
|
-
(0, node_child_process.execFile)(binaryPath, [
|
|
14682
|
-
"-hide_banner",
|
|
14683
|
-
"-nostdin",
|
|
14684
|
-
"-i",
|
|
14685
|
-
path
|
|
14686
|
-
], {
|
|
14687
|
-
timeout: PROBE_TIMEOUT_MS,
|
|
14688
|
-
maxBuffer: REPORT_MAX_BYTES,
|
|
14689
|
-
encoding: "utf8"
|
|
14690
|
-
}, (error, _stdout, stderr) => {
|
|
14691
|
-
if (error !== null && (error.killed === true || stderr === "")) {
|
|
14692
|
-
reject(new Error(error.killed === true ? "probe timed out" : error.message));
|
|
14693
|
-
return;
|
|
14694
|
-
}
|
|
14695
|
-
const result = parseFfmpegReport(stderr);
|
|
14696
|
-
if (result.streams.length === 0) reject(/* @__PURE__ */ new Error("no streams in the report"));
|
|
14697
|
-
else resolve(result);
|
|
14698
|
-
});
|
|
14699
|
-
});
|
|
14700
|
-
}
|
|
14701
|
-
//#endregion
|
|
14702
|
-
//#region src/provider.ts
|
|
14703
|
-
/** The `media-library` capability over the store. A caller reads and writes only their own progress. */
|
|
14704
|
-
function createMediaLibraryProvider(store, scans) {
|
|
14705
|
-
return {
|
|
14706
|
-
listSeries: ({ limit, offset, language, caller }) => store.listSeries(caller.userId, limit, offset, language),
|
|
14707
|
-
listMovies: ({ limit, offset, language, caller }) => store.listMovies(caller.userId, limit, offset, language),
|
|
14708
|
-
listSeasons: ({ seriesId, caller }) => store.listSeasons(caller.userId, seriesId),
|
|
14709
|
-
listEpisodes: ({ seriesId, seasonNumber, language, caller }) => store.listEpisodes(caller.userId, seriesId, seasonNumber, language),
|
|
14710
|
-
getItem: ({ itemId, language, caller }) => store.getItem(caller.userId, itemId, language),
|
|
14711
|
-
search: ({ query, limit, language, caller }) => store.search(caller.userId, query, limit, language),
|
|
14712
|
-
listRecentlyAdded: ({ limit, language, caller }) => store.listRecentlyAdded(caller.userId, limit, language),
|
|
14713
|
-
listWatchlist: ({ limit, offset, language, caller }) => store.listWatchlist(caller.userId, limit, offset, language),
|
|
14714
|
-
setWatchlisted: ({ itemId, on, caller }) => store.setWatchlisted(caller.userId, itemId, on),
|
|
14715
|
-
getItemDetails: ({ itemId, language }) => store.getItemDetails(itemId, language),
|
|
14716
|
-
getProgress: ({ itemId, caller }) => store.getProgress(caller.userId, itemId),
|
|
14717
|
-
setProgress: ({ caller, ...input }) => store.setProgress(caller.userId, input),
|
|
14718
|
-
markWatched: ({ caller, ...input }) => store.markWatched(caller.userId, input),
|
|
14719
|
-
listContinue: ({ limit, language, caller }) => store.listContinue(caller.userId, limit, language),
|
|
14720
|
-
rescan: async () => ({ started: scans.start("manual") }),
|
|
14721
|
-
getScanStatus: async () => scans.status()
|
|
14722
|
-
};
|
|
14723
|
-
}
|
|
14627
|
+
] };
|
|
14724
14628
|
//#endregion
|
|
14725
14629
|
//#region src/enrich.ts
|
|
14726
14630
|
/** The default order when settings name none (D1125): files next to the media, the arr app, then online. */
|
|
@@ -14896,9 +14800,7 @@ var Enricher = class {
|
|
|
14896
14800
|
const known = this.deps.cache.getMatch(key);
|
|
14897
14801
|
if (known === null) return null;
|
|
14898
14802
|
if (!known.found) return known;
|
|
14899
|
-
|
|
14900
|
-
const predatesDetails = provider.providesDetails === true && known.match.details === void 0;
|
|
14901
|
-
return predatesTranslations || predatesDetails ? null : known;
|
|
14803
|
+
return provider.translates === true && known.match.translations === void 0 || provider.providesDetails === true && known.match.details === void 0 ? null : known;
|
|
14902
14804
|
}
|
|
14903
14805
|
/** A pinned id is asked for directly: an answer of "nothing" is final, never turned into a title guess. */
|
|
14904
14806
|
async lookup(provider, ask, item, kind, pin) {
|
|
@@ -15186,12 +15088,11 @@ async function classify(root, path, reader) {
|
|
|
15186
15088
|
if (folderSeason !== null) seriesDir = (0, node_path.dirname)(parent);
|
|
15187
15089
|
else if (parent !== root) seriesDir = parent;
|
|
15188
15090
|
}
|
|
15189
|
-
const prefix = guess.kind === "episode" ? guess.title : "";
|
|
15190
15091
|
return {
|
|
15191
15092
|
path,
|
|
15192
15093
|
kind: "episode",
|
|
15193
15094
|
seriesDir,
|
|
15194
|
-
namedTitle:
|
|
15095
|
+
namedTitle: guess.kind === "episode" ? guess.title : "",
|
|
15195
15096
|
season,
|
|
15196
15097
|
episode,
|
|
15197
15098
|
year: null
|
|
@@ -15698,53 +15599,7 @@ var MediaLibraryAddon = class extends BaseAddon {
|
|
|
15698
15599
|
this.scans?.schedule(settings.rescanMinutes);
|
|
15699
15600
|
this.scans?.start("settings");
|
|
15700
15601
|
}
|
|
15701
|
-
/**
|
|
15702
|
-
* One-time, idempotent: the metadata settings of earlier versions (an order string, switches and
|
|
15703
|
-
* four keys) become the `metadataProviders` list. The rows are written first, so each key leaves
|
|
15704
|
-
* through the normal secret write into a keychain ref addressed by its row id (D787). An old key
|
|
15705
|
-
* is released only once its row holds a stored key (a marker counts), and nothing at all is
|
|
15706
|
-
* touched while an old secret cannot be read (the keychain is locked): the next boot retries.
|
|
15707
|
-
*/
|
|
15708
|
-
async migrateLegacyProviderSettings() {
|
|
15709
|
-
const stored = await this.resolveGlobalStore(void 0, SETTINGS_CAP);
|
|
15710
|
-
if (!hasLegacyProviderKeys(stored)) return;
|
|
15711
|
-
const unreadable = LEGACY_SECRET_KEYS.filter((key) => isSecretMarker(stored[key]));
|
|
15712
|
-
if (unreadable.length > 0) {
|
|
15713
|
-
this.ctx.logger.warn("media-library provider migration postponed: a stored key is unreadable", { meta: { keys: unreadable } });
|
|
15714
|
-
return;
|
|
15715
|
-
}
|
|
15716
|
-
const parsed = array(MetadataProviderRowSchema).safeParse(stored["metadataProviders"] ?? []);
|
|
15717
|
-
if (!parsed.success) {
|
|
15718
|
-
this.ctx.logger.warn("media-library provider migration postponed: the stored list is invalid");
|
|
15719
|
-
return;
|
|
15720
|
-
}
|
|
15721
|
-
const rows = parsed.data.length === 0 ? providerRowsFromLegacy(stored) : fillMissingKeys(parsed.data, stored);
|
|
15722
|
-
if (JSON.stringify(rows) !== JSON.stringify(parsed.data)) await this.clusterSettings(SETTINGS_CAP, MediaLibrarySettingsSchema).patch({ metadataProviders: rows });
|
|
15723
|
-
const after = await this.resolveGlobalStore(void 0, SETTINGS_CAP);
|
|
15724
|
-
const held = array(MetadataProviderRowSchema).safeParse(after["metadataProviders"]);
|
|
15725
|
-
const present = LEGACY_PROVIDER_KEYS.filter((key) => stored[key] !== void 0);
|
|
15726
|
-
const releasable = present.filter((key) => !LEGACY_SECRET_KEYS.some((secret) => secret === key) || typeof stored[key] === "string" && stored[key] === "" || held.success && rowHoldsKey(held.data, key));
|
|
15727
|
-
const secrets = releasable.filter((key) => LEGACY_SECRET_KEYS.some((s) => s === key));
|
|
15728
|
-
await this.clearSecrets(secrets);
|
|
15729
|
-
const outcome = await this.unsetStoredSettingsKeys(releasable);
|
|
15730
|
-
this.ctx.logger.info("media-library provider settings migrated to the provider list", { meta: {
|
|
15731
|
-
removed: outcome.removed.length,
|
|
15732
|
-
kept: present.length - releasable.length
|
|
15733
|
-
} });
|
|
15734
|
-
}
|
|
15735
|
-
/** A failed migration never stops the boot: the old keys stay and the next boot retries. */
|
|
15736
|
-
async migrateProviderSettingsOrKeepOld() {
|
|
15737
|
-
try {
|
|
15738
|
-
await this.migrateLegacyProviderSettings();
|
|
15739
|
-
} catch (error) {
|
|
15740
|
-
this.ctx.logger.warn("media-library provider migration failed; the old settings are kept", { meta: {
|
|
15741
|
-
step: "migrateLegacyProviderSettings",
|
|
15742
|
-
error: String(error)
|
|
15743
|
-
} });
|
|
15744
|
-
}
|
|
15745
|
-
}
|
|
15746
15602
|
async onInitialize() {
|
|
15747
|
-
await this.migrateProviderSettingsOrKeepOld();
|
|
15748
15603
|
const { ctx } = this;
|
|
15749
15604
|
const logger = ctx.logger;
|
|
15750
15605
|
const db = settingsStoreDb(ctx.api.settingsStore);
|