mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-14 17:55:55 -07:00
After thorough testing, some renaming and refactoring
This commit is contained in:
parent
5198d4b805
commit
f9e9215bcb
2 changed files with 56 additions and 50 deletions
|
|
@ -100,7 +100,7 @@ var details = function () { return ({
|
||||||
],
|
],
|
||||||
}); };
|
}); };
|
||||||
exports.details = details;
|
exports.details = details;
|
||||||
var getId = function (args, arr, arrHost, headers, fileName, refreshType) { return __awaiter(void 0, void 0, void 0, function () {
|
var getId = function (args, arrApp, fileName) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var imdbId, id, _a, _b, _c, _d;
|
var imdbId, id, _a, _b, _c, _d;
|
||||||
var _e, _f, _g, _h, _j;
|
var _e, _f, _g, _h, _j;
|
||||||
return __generator(this, function (_k) {
|
return __generator(this, function (_k) {
|
||||||
|
|
@ -111,8 +111,8 @@ var getId = function (args, arr, arrHost, headers, fileName, refreshType) { retu
|
||||||
_b = Number;
|
_b = Number;
|
||||||
return [4 /*yield*/, args.deps.axios({
|
return [4 /*yield*/, args.deps.axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: "".concat(arrHost, "/api/v3/").concat(arr === 'radarr' ? 'movie' : 'series', "/lookup?term=imdb:").concat(imdbId),
|
url: "".concat(arrApp.host, "/api/v3/").concat(arrApp.name === 'radarr' ? 'movie' : 'series', "/lookup?term=imdb:").concat(imdbId),
|
||||||
headers: headers,
|
headers: arrApp.headers,
|
||||||
})];
|
})];
|
||||||
case 1:
|
case 1:
|
||||||
_a = _b.apply(void 0, [(_j = (_h = (_g = (_k.sent()).data) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.id) !== null && _j !== void 0 ? _j : -1]);
|
_a = _b.apply(void 0, [(_j = (_h = (_g = (_k.sent()).data) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.id) !== null && _j !== void 0 ? _j : -1]);
|
||||||
|
|
@ -122,24 +122,24 @@ var getId = function (args, arr, arrHost, headers, fileName, refreshType) { retu
|
||||||
_k.label = 3;
|
_k.label = 3;
|
||||||
case 3:
|
case 3:
|
||||||
id = _a;
|
id = _a;
|
||||||
args.jobLog("".concat(refreshType.content, " ").concat(id !== -1 ? "".concat(id, " found") : 'not found', " for imdb '").concat(imdbId, "'"));
|
args.jobLog("".concat(arrApp.content, " ").concat(id !== -1 ? "'".concat(id, "' found") : 'not found', " for imdb '").concat(imdbId, "'"));
|
||||||
if (!(id === -1)) return [3 /*break*/, 5];
|
if (!(id === -1)) return [3 /*break*/, 5];
|
||||||
_d = (_c = refreshType.delegates).getIdFromParseResponse;
|
_d = (_c = arrApp.delegates).getIdFromParseResponse;
|
||||||
return [4 /*yield*/, args.deps.axios({
|
return [4 /*yield*/, args.deps.axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: "".concat(arrHost, "/api/v3/parse?title=").concat(encodeURIComponent((0, fileUtils_1.getFileName)(fileName))),
|
url: "".concat(arrApp.host, "/api/v3/parse?title=").concat(encodeURIComponent((0, fileUtils_1.getFileName)(fileName))),
|
||||||
headers: headers,
|
headers: arrApp.headers,
|
||||||
})];
|
})];
|
||||||
case 4:
|
case 4:
|
||||||
id = _d.apply(_c, [(_k.sent())]);
|
id = _d.apply(_c, [(_k.sent())]);
|
||||||
args.jobLog("".concat(refreshType.content, " ").concat(id !== -1 ? "".concat(id, " found") : 'not found', " for '").concat((0, fileUtils_1.getFileName)(fileName), "'"));
|
args.jobLog("".concat(arrApp.content, " ").concat(id !== -1 ? "'".concat(id, "' found") : 'not found', " for '").concat((0, fileUtils_1.getFileName)(fileName), "'"));
|
||||||
_k.label = 5;
|
_k.label = 5;
|
||||||
case 5: return [2 /*return*/, id];
|
case 5: return [2 /*return*/, id];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}); };
|
}); };
|
||||||
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var lib, refreshed, arr, arr_host, arrHost, originalFileName, currentFileName, headers, refreshType, id;
|
var lib, refreshed, arr, arr_host, arrHost, originalFileName, currentFileName, headers, arrApp, id;
|
||||||
var _a, _b, _c, _d;
|
var _a, _b, _c, _d;
|
||||||
return __generator(this, function (_e) {
|
return __generator(this, function (_e) {
|
||||||
switch (_e.label) {
|
switch (_e.label) {
|
||||||
|
|
@ -158,30 +158,34 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
'X-Api-Key': String(args.inputs.arr_api_key),
|
'X-Api-Key': String(args.inputs.arr_api_key),
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
};
|
};
|
||||||
refreshType = arr === 'radarr'
|
arrApp = arr === 'radarr'
|
||||||
? {
|
? {
|
||||||
appName: 'Radarr',
|
name: arr,
|
||||||
|
host: arrHost,
|
||||||
|
headers: headers,
|
||||||
content: 'Movie',
|
content: 'Movie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseResponse: function (parseRequestResult) { var _a, _b, _c; return Number((_c = (_b = (_a = parseRequestResult.data) === null || _a === void 0 ? void 0 : _a.movie) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : -1); },
|
getIdFromParseResponse: function (parseResponse) { var _a, _b, _c; return Number((_c = (_b = (_a = parseResponse === null || parseResponse === void 0 ? void 0 : parseResponse.data) === null || _a === void 0 ? void 0 : _a.movie) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : -1); },
|
||||||
buildRefreshResquestData: function (id) { return JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }); },
|
buildRefreshResquestData: function (id) { return JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }); },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
appName: 'Sonarr',
|
name: arr,
|
||||||
|
host: arrHost,
|
||||||
|
headers: headers,
|
||||||
content: 'Serie',
|
content: 'Serie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseResponse: function (parseRequestResult) { var _a, _b, _c; return Number((_c = (_b = (_a = parseRequestResult.data) === null || _a === void 0 ? void 0 : _a.series) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : -1); },
|
getIdFromParseResponse: function (parseResponse) { var _a, _b, _c; return Number((_c = (_b = (_a = parseResponse === null || parseResponse === void 0 ? void 0 : parseResponse.data) === null || _a === void 0 ? void 0 : _a.series) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : -1); },
|
||||||
buildRefreshResquestData: function (id) { return JSON.stringify({ name: 'RefreshSeries', seriesId: id }); },
|
buildRefreshResquestData: function (id) { return JSON.stringify({ name: 'RefreshSeries', seriesId: id }); },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
args.jobLog('Going to force scan');
|
args.jobLog('Going to force scan');
|
||||||
args.jobLog("Refreshing ".concat(refreshType.appName, "..."));
|
args.jobLog("Refreshing ".concat(arrApp.name, "..."));
|
||||||
return [4 /*yield*/, getId(args, arr, arrHost, headers, originalFileName, refreshType)];
|
return [4 /*yield*/, getId(args, arrApp, originalFileName)];
|
||||||
case 1:
|
case 1:
|
||||||
id = _e.sent();
|
id = _e.sent();
|
||||||
if (!(id === -1 && currentFileName !== originalFileName)) return [3 /*break*/, 3];
|
if (!(id === -1 && currentFileName !== originalFileName)) return [3 /*break*/, 3];
|
||||||
return [4 /*yield*/, getId(args, arr, arrHost, headers, currentFileName, refreshType)];
|
return [4 /*yield*/, getId(args, arrApp, currentFileName)];
|
||||||
case 2:
|
case 2:
|
||||||
id = _e.sent();
|
id = _e.sent();
|
||||||
_e.label = 3;
|
_e.label = 3;
|
||||||
|
|
@ -190,15 +194,15 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
// Using command endpoint to queue a refresh task
|
// Using command endpoint to queue a refresh task
|
||||||
return [4 /*yield*/, args.deps.axios({
|
return [4 /*yield*/, args.deps.axios({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: "".concat(arrHost, "/api/v3/command"),
|
url: "".concat(arrApp.host, "/api/v3/command"),
|
||||||
headers: headers,
|
headers: headers,
|
||||||
data: refreshType.delegates.buildRefreshResquestData(id),
|
data: arrApp.delegates.buildRefreshResquestData(id),
|
||||||
})];
|
})];
|
||||||
case 4:
|
case 4:
|
||||||
// Using command endpoint to queue a refresh task
|
// Using command endpoint to queue a refresh task
|
||||||
_e.sent();
|
_e.sent();
|
||||||
refreshed = true;
|
refreshed = true;
|
||||||
args.jobLog("\u2714 ".concat(refreshType.content, " ").concat(id, " refreshed in ").concat(refreshType.appName, "."));
|
args.jobLog("\u2714 ".concat(arrApp.content, " '").concat(id, "' refreshed in ").concat(arrApp.name, "."));
|
||||||
_e.label = 5;
|
_e.label = 5;
|
||||||
case 5: return [2 /*return*/, {
|
case 5: return [2 /*return*/, {
|
||||||
outputFileObj: args.inputFileObj,
|
outputFileObj: args.inputFileObj,
|
||||||
|
|
|
||||||
|
|
@ -72,49 +72,47 @@ interface IHTTPHeaders {
|
||||||
'X-Api-Key': string,
|
'X-Api-Key': string,
|
||||||
Accept: string,
|
Accept: string,
|
||||||
}
|
}
|
||||||
interface IParsedRequestResult {
|
interface IParseResponse {
|
||||||
data: {
|
data: {
|
||||||
movie?: { id: number },
|
movie?: { id: number },
|
||||||
series?: { id: number },
|
series?: { id: number },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
interface IRefreshType {
|
interface IArrApp {
|
||||||
appName: string,
|
name: string,
|
||||||
|
host: string,
|
||||||
|
headers: IHTTPHeaders,
|
||||||
content: string,
|
content: string,
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseResponse: (parseRequestResult: IParsedRequestResult) => number,
|
getIdFromParseResponse: (parseResponse: IParseResponse) => number,
|
||||||
buildRefreshResquestData: (id: number) => string
|
buildRefreshResquestData: (id: number) => string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getId = async (
|
const getId = async (
|
||||||
args: IpluginInputArgs,
|
args: IpluginInputArgs,
|
||||||
arr: string,
|
arrApp: IArrApp,
|
||||||
arrHost: string, headers: IHTTPHeaders,
|
|
||||||
fileName: string,
|
fileName: string,
|
||||||
refreshType: IRefreshType,
|
|
||||||
)
|
)
|
||||||
: Promise<number> => {
|
: Promise<number> => {
|
||||||
const imdbId = /\b(tt|nm|co|ev|ch|ni)\d{7,10}\b/i.exec(fileName)?.at(0) ?? '';
|
const imdbId = /\b(tt|nm|co|ev|ch|ni)\d{7,10}\b/i.exec(fileName)?.at(0) ?? '';
|
||||||
let id = (imdbId !== '')
|
let id = (imdbId !== '')
|
||||||
? Number(
|
? Number((await args.deps.axios({
|
||||||
(await args.deps.axios({
|
method: 'get',
|
||||||
method: 'get',
|
url: `${arrApp.host}/api/v3/${arrApp.name === 'radarr' ? 'movie' : 'series'}/lookup?term=imdb:${imdbId}`,
|
||||||
url: `${arrHost}/api/v3/${arr === 'radarr' ? 'movie' : 'series'}/lookup?term=imdb:${imdbId}`,
|
headers: arrApp.headers,
|
||||||
headers,
|
})).data?.at(0)?.id ?? -1)
|
||||||
})).data?.at(0)?.id ?? -1,
|
|
||||||
)
|
|
||||||
: -1;
|
: -1;
|
||||||
args.jobLog(`${refreshType.content} ${id !== -1 ? `${id} found` : 'not found'} for imdb '${imdbId}'`);
|
args.jobLog(`${arrApp.content} ${id !== -1 ? `'${id}' found` : 'not found'} for imdb '${imdbId}'`);
|
||||||
if (id === -1) {
|
if (id === -1) {
|
||||||
id = refreshType.delegates.getIdFromParseResponse(
|
id = arrApp.delegates.getIdFromParseResponse(
|
||||||
(await args.deps.axios({
|
(await args.deps.axios({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: `${arrHost}/api/v3/parse?title=${encodeURIComponent(getFileName(fileName))}`,
|
url: `${arrApp.host}/api/v3/parse?title=${encodeURIComponent(getFileName(fileName))}`,
|
||||||
headers,
|
headers: arrApp.headers,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
args.jobLog(`${refreshType.content} ${id !== -1 ? `${id} found` : 'not found'} for '${getFileName(fileName)}'`);
|
args.jobLog(`${arrApp.content} ${id !== -1 ? `'${id}' found` : 'not found'} for '${getFileName(fileName)}'`);
|
||||||
}
|
}
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
@ -136,35 +134,39 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
'X-Api-Key': String(args.inputs.arr_api_key),
|
'X-Api-Key': String(args.inputs.arr_api_key),
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
};
|
};
|
||||||
const refreshType: IRefreshType = arr === 'radarr'
|
const arrApp: IArrApp = arr === 'radarr'
|
||||||
? {
|
? {
|
||||||
appName: 'Radarr',
|
name: arr,
|
||||||
|
host: arrHost,
|
||||||
|
headers,
|
||||||
content: 'Movie',
|
content: 'Movie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseResponse:
|
getIdFromParseResponse:
|
||||||
(parseRequestResult: IParsedRequestResult) => Number(parseRequestResult.data?.movie?.id ?? -1),
|
(parseResponse: IParseResponse) => Number(parseResponse?.data?.movie?.id ?? -1),
|
||||||
buildRefreshResquestData:
|
buildRefreshResquestData:
|
||||||
(id) => JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }),
|
(id) => JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
appName: 'Sonarr',
|
name: arr,
|
||||||
|
host: arrHost,
|
||||||
|
headers,
|
||||||
content: 'Serie',
|
content: 'Serie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseResponse:
|
getIdFromParseResponse:
|
||||||
(parseRequestResult: IParsedRequestResult) => Number(parseRequestResult.data?.series?.id ?? -1),
|
(parseResponse: IParseResponse) => Number(parseResponse?.data?.series?.id ?? -1),
|
||||||
buildRefreshResquestData:
|
buildRefreshResquestData:
|
||||||
(id) => JSON.stringify({ name: 'RefreshSeries', seriesId: id }),
|
(id) => JSON.stringify({ name: 'RefreshSeries', seriesId: id }),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
args.jobLog('Going to force scan');
|
args.jobLog('Going to force scan');
|
||||||
args.jobLog(`Refreshing ${refreshType.appName}...`);
|
args.jobLog(`Refreshing ${arrApp.name}...`);
|
||||||
|
|
||||||
let id = await getId(args, arr, arrHost, headers, originalFileName, refreshType);
|
let id = await getId(args, arrApp, originalFileName);
|
||||||
// Useful in some edge cases
|
// Useful in some edge cases
|
||||||
if (id === -1 && currentFileName !== originalFileName) {
|
if (id === -1 && currentFileName !== originalFileName) {
|
||||||
id = await getId(args, arr, arrHost, headers, currentFileName, refreshType);
|
id = await getId(args, arrApp, currentFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking that the file has been found
|
// Checking that the file has been found
|
||||||
|
|
@ -172,13 +174,13 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
// Using command endpoint to queue a refresh task
|
// Using command endpoint to queue a refresh task
|
||||||
await args.deps.axios({
|
await args.deps.axios({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: `${arrHost}/api/v3/command`,
|
url: `${arrApp.host}/api/v3/command`,
|
||||||
headers,
|
headers,
|
||||||
data: refreshType.delegates.buildRefreshResquestData(id),
|
data: arrApp.delegates.buildRefreshResquestData(id),
|
||||||
});
|
});
|
||||||
|
|
||||||
refreshed = true;
|
refreshed = true;
|
||||||
args.jobLog(`✔ ${refreshType.content} ${id} refreshed in ${refreshType.appName}.`);
|
args.jobLog(`✔ ${arrApp.content} '${id}' refreshed in ${arrApp.name}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue