mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-15 02:05:54 -07:00
Added imdbid detection from file name to get the movie or serie id
This commit is contained in:
parent
cf974234ea
commit
e5638dda65
2 changed files with 178 additions and 175 deletions
|
|
@ -35,8 +35,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.plugin = exports.details = void 0;
|
exports.plugin = exports.details = void 0;
|
||||||
|
var path_1 = __importDefault(require("path"));
|
||||||
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||||
var details = function () { return ({
|
var details = function () { return ({
|
||||||
name: 'Notify Radarr or Sonarr',
|
name: 'Notify Radarr or Sonarr',
|
||||||
|
|
@ -100,110 +104,114 @@ var details = function () { return ({
|
||||||
],
|
],
|
||||||
}); };
|
}); };
|
||||||
exports.details = details;
|
exports.details = details;
|
||||||
|
var getId = function (args, arrHost, headers, fileName, refreshType) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
|
var imdbId, id, _a, _b, _c, _d;
|
||||||
|
var _e, _f, _g, _h;
|
||||||
|
return __generator(this, function (_j) {
|
||||||
|
switch (_j.label) {
|
||||||
|
case 0:
|
||||||
|
imdbId = (_f = (_e = /\b(tt|nm|co|ev|ch|ni)\d{7,10}\b/i.exec(fileName)) === null || _e === void 0 ? void 0 : _e.at(0)) !== null && _f !== void 0 ? _f : '';
|
||||||
|
if (!(imdbId !== '')) return [3 /*break*/, 2];
|
||||||
|
_b = Number;
|
||||||
|
return [4 /*yield*/, args.deps.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: "".concat(arrHost, "/api/v3/movie/lookup?terms=imdb:").concat(imdbId),
|
||||||
|
headers: headers,
|
||||||
|
})];
|
||||||
|
case 1:
|
||||||
|
_a = _b.apply(void 0, [(_h = (_g = (_j.sent()).data) === null || _g === void 0 ? void 0 : _g.id) !== null && _h !== void 0 ? _h : -1]);
|
||||||
|
return [3 /*break*/, 3];
|
||||||
|
case 2:
|
||||||
|
_a = -1;
|
||||||
|
_j.label = 3;
|
||||||
|
case 3:
|
||||||
|
id = _a;
|
||||||
|
if (!(id === -1)) return [3 /*break*/, 5];
|
||||||
|
_d = (_c = refreshType.delegates).getIdFromParseResponse;
|
||||||
|
return [4 /*yield*/, args.deps.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: "".concat(arrHost, "/api/v3/parse?title=").concat(encodeURIComponent((0, fileUtils_1.getFileName)(fileName))),
|
||||||
|
headers: headers,
|
||||||
|
})];
|
||||||
|
case 4:
|
||||||
|
id = _d.apply(_c, [(_j.sent())]);
|
||||||
|
_j.label = 5;
|
||||||
|
case 5:
|
||||||
|
args.jobLog("".concat(refreshType.content, " ").concat(id !== -1 ? "".concat(id, " found") : 'not found', " for '").concat(fileName, "', imdb '").concat(imdbId, "'"));
|
||||||
|
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, _a, arr, arr_api_key, arr_host, arrHost, fileNames, refresh, refreshTypes, refreshed;
|
var lib, refreshed, arr, arr_host, arrHost, absoluteFileDir, fileNames, headers, refreshType, id;
|
||||||
var _b, _c, _d, _e;
|
var _a, _b, _c, _d, _e, _f;
|
||||||
return __generator(this, function (_f) {
|
return __generator(this, function (_g) {
|
||||||
switch (_f.label) {
|
switch (_g.label) {
|
||||||
case 0:
|
case 0:
|
||||||
lib = require('../../../../../methods/lib')();
|
lib = require('../../../../../methods/lib')();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
_a = args.inputs, arr = _a.arr, arr_api_key = _a.arr_api_key;
|
refreshed = false;
|
||||||
|
arr = String(args.inputs.arr);
|
||||||
arr_host = String(args.inputs.arr_host).trim();
|
arr_host = String(args.inputs.arr_host).trim();
|
||||||
arrHost = arr_host.endsWith('/') ? arr_host.slice(0, -1) : arr_host;
|
arrHost = arr_host.endsWith('/') ? arr_host.slice(0, -1) : arr_host;
|
||||||
|
absoluteFileDir = (0, fileUtils_1.getFileAbosluteDir)((_b = (_a = args.originalLibraryFile) === null || _a === void 0 ? void 0 : _a._id) !== null && _b !== void 0 ? _b : '');
|
||||||
fileNames = {
|
fileNames = {
|
||||||
originalFileName: (0, fileUtils_1.getFileName)((_c = (_b = args.originalLibraryFile) === null || _b === void 0 ? void 0 : _b._id) !== null && _c !== void 0 ? _c : ''),
|
originalFileName: path_1.default.join(absoluteFileDir, (0, fileUtils_1.getFileName)((_d = (_c = args.originalLibraryFile) === null || _c === void 0 ? void 0 : _c._id) !== null && _d !== void 0 ? _d : '')),
|
||||||
currentFileName: (0, fileUtils_1.getFileName)((_e = (_d = args.inputFileObj) === null || _d === void 0 ? void 0 : _d._id) !== null && _e !== void 0 ? _e : ''),
|
currentFileName: path_1.default.join(absoluteFileDir, (0, fileUtils_1.getFileName)((_f = (_e = args.inputFileObj) === null || _e === void 0 ? void 0 : _e._id) !== null && _f !== void 0 ? _f : '')),
|
||||||
};
|
};
|
||||||
refresh = function (refreshType) { return __awaiter(void 0, void 0, void 0, function () {
|
headers = {
|
||||||
var refreshed, headers, getId, fileName, id, refreshResquestConfig;
|
'Content-Type': 'application/json',
|
||||||
return __generator(this, function (_a) {
|
'X-Api-Key': String(args.inputs.arr_api_key),
|
||||||
switch (_a.label) {
|
Accept: 'application/json',
|
||||||
case 0:
|
};
|
||||||
args.jobLog('Going to force scan');
|
refreshType = arr === 'radarr'
|
||||||
args.jobLog("Refreshing ".concat(refreshType.appName, "..."));
|
? {
|
||||||
refreshed = false;
|
|
||||||
headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Api-Key': arr_api_key,
|
|
||||||
Accept: 'application/json',
|
|
||||||
};
|
|
||||||
getId = function (fileName) { return __awaiter(void 0, void 0, void 0, function () {
|
|
||||||
var parseRequestConfig, parseRequestResult, id;
|
|
||||||
return __generator(this, function (_a) {
|
|
||||||
switch (_a.label) {
|
|
||||||
case 0:
|
|
||||||
parseRequestConfig = {
|
|
||||||
method: 'get',
|
|
||||||
url: "".concat(arrHost, "/api/v3/parse?title=").concat(encodeURIComponent(fileName)),
|
|
||||||
headers: headers,
|
|
||||||
};
|
|
||||||
return [4 /*yield*/, args.deps.axios(parseRequestConfig)];
|
|
||||||
case 1:
|
|
||||||
parseRequestResult = _a.sent();
|
|
||||||
id = refreshType.delegates.getIdFromParseRequestResult(parseRequestResult);
|
|
||||||
args.jobLog(id !== -1
|
|
||||||
? "Found ".concat(refreshType.contentName, " ").concat(id, " with a file named '").concat(fileName, "'")
|
|
||||||
: "Didn't find ".concat(refreshType.contentName, " with a file named '").concat(fileName, "' in ").concat(arrHost, "."));
|
|
||||||
return [2 /*return*/, id];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}); };
|
|
||||||
fileName = fileNames.originalFileName;
|
|
||||||
return [4 /*yield*/, getId(fileName)];
|
|
||||||
case 1:
|
|
||||||
id = _a.sent();
|
|
||||||
if (!(id === -1 && fileNames.currentFileName !== fileNames.originalFileName)) return [3 /*break*/, 3];
|
|
||||||
fileName = fileNames.currentFileName;
|
|
||||||
return [4 /*yield*/, getId(fileName)];
|
|
||||||
case 2:
|
|
||||||
id = _a.sent();
|
|
||||||
_a.label = 3;
|
|
||||||
case 3:
|
|
||||||
if (!(id !== -1)) return [3 /*break*/, 5];
|
|
||||||
refreshResquestConfig = {
|
|
||||||
method: 'post',
|
|
||||||
url: "".concat(arrHost, "/api/v3/command"),
|
|
||||||
headers: headers,
|
|
||||||
data: refreshType.delegates.buildRefreshResquestData(id),
|
|
||||||
};
|
|
||||||
return [4 /*yield*/, args.deps.axios(refreshResquestConfig)];
|
|
||||||
case 4:
|
|
||||||
_a.sent();
|
|
||||||
refreshed = true;
|
|
||||||
args.jobLog("\u2714 Refreshed ".concat(refreshType.contentName, " ").concat(id, " in ").concat(refreshType.appName, "."));
|
|
||||||
_a.label = 5;
|
|
||||||
case 5: return [2 /*return*/, refreshed];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}); };
|
|
||||||
refreshTypes = {
|
|
||||||
radarr: {
|
|
||||||
appName: 'Radarr',
|
appName: 'Radarr',
|
||||||
contentName: 'movie',
|
content: 'Movie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseRequestResult: function (parseRequestResult) { var _a, _b, _c, _d; return Number((_d = (_c = (_b = (_a = parseRequestResult.data) === null || _a === void 0 ? void 0 : _a.movie) === null || _b === void 0 ? void 0 : _b.movieFile) === null || _c === void 0 ? void 0 : _c.movieId) !== null && _d !== void 0 ? _d : -1); },
|
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); },
|
||||||
buildRefreshResquestData: function (id) { return JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }); },
|
buildRefreshResquestData: function (id) { return JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }); },
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
sonarr: {
|
: {
|
||||||
appName: 'Sonarr',
|
appName: 'Sonarr',
|
||||||
contentName: 'serie',
|
content: 'Serie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseRequestResult: 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 (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); },
|
||||||
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');
|
||||||
return [4 /*yield*/, refresh(arr === 'radarr' ? refreshTypes.radarr : refreshTypes.sonarr)];
|
args.jobLog("Refreshing ".concat(refreshType.appName, "..."));
|
||||||
|
return [4 /*yield*/, getId(args, arrHost, headers, fileNames.originalFileName, refreshType)];
|
||||||
case 1:
|
case 1:
|
||||||
refreshed = _f.sent();
|
id = _g.sent();
|
||||||
return [2 /*return*/, {
|
if (!(id === -1 && fileNames.currentFileName !== fileNames.originalFileName)) return [3 /*break*/, 3];
|
||||||
outputFileObj: args.inputFileObj,
|
return [4 /*yield*/, getId(args, arrHost, headers, fileNames.currentFileName, refreshType)];
|
||||||
outputNumber: refreshed ? 1 : 2,
|
case 2:
|
||||||
variables: args.variables,
|
id = _g.sent();
|
||||||
}];
|
_g.label = 3;
|
||||||
|
case 3:
|
||||||
|
if (!(id !== -1)) return [3 /*break*/, 5];
|
||||||
|
// Using command endpoint to queue a refresh task
|
||||||
|
return [4 /*yield*/, args.deps.axios({
|
||||||
|
method: 'post',
|
||||||
|
url: "".concat(arrHost, "/api/v3/command"),
|
||||||
|
headers: headers,
|
||||||
|
data: refreshType.delegates.buildRefreshResquestData(id),
|
||||||
|
})];
|
||||||
|
case 4:
|
||||||
|
// Using command endpoint to queue a refresh task
|
||||||
|
_g.sent();
|
||||||
|
refreshed = true;
|
||||||
|
args.jobLog("\u2714 Refreshed ".concat(refreshType.content, " ").concat(id, " in ").concat(refreshType.appName, "."));
|
||||||
|
_g.label = 5;
|
||||||
|
case 5: return [2 /*return*/, {
|
||||||
|
outputFileObj: args.inputFileObj,
|
||||||
|
outputNumber: refreshed ? 1 : 2,
|
||||||
|
variables: args.variables,
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}); };
|
}); };
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
import path from 'path';
|
||||||
|
import { getFileAbosluteDir, getFileName } from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
IpluginInputArgs,
|
IpluginInputArgs,
|
||||||
|
|
@ -67,127 +68,121 @@ const details = (): IpluginDetails => ({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
interface IFileNames {
|
interface IHTTPHeaders {
|
||||||
originalFileName: string,
|
'Content-Type': string,
|
||||||
currentFileName: string
|
'X-Api-Key': string,
|
||||||
|
Accept: string,
|
||||||
}
|
}
|
||||||
interface IParsedRequestResult {
|
interface IParsedRequestResult {
|
||||||
data: {
|
data: {
|
||||||
movie?: {
|
movie?: { id: number },
|
||||||
movieFile: {
|
series?: { id: number },
|
||||||
movieId: number
|
|
||||||
},
|
|
||||||
},
|
|
||||||
series?: {
|
|
||||||
id: number
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
interface IRefreshDelegates {
|
interface IRefreshDelegates {
|
||||||
getIdFromParseRequestResult: (parseRequestResult: IParsedRequestResult) => number,
|
getIdFromParseResponse: (parseRequestResult: IParsedRequestResult) => number,
|
||||||
buildRefreshResquestData: (id: number) => string
|
buildRefreshResquestData: (id: number) => string
|
||||||
}
|
}
|
||||||
interface IRefreshType {
|
interface IRefreshType {
|
||||||
appName: string,
|
appName: string,
|
||||||
contentName: string,
|
content: string,
|
||||||
delegates: IRefreshDelegates
|
delegates: IRefreshDelegates
|
||||||
}
|
}
|
||||||
interface IRefreshTypes {
|
|
||||||
radarr: IRefreshType,
|
const getId = async (
|
||||||
sonarr: IRefreshType
|
args: IpluginInputArgs,
|
||||||
}
|
arrHost: string, headers: IHTTPHeaders,
|
||||||
|
fileName: string,
|
||||||
|
refreshType: IRefreshType,
|
||||||
|
)
|
||||||
|
: Promise<number> => {
|
||||||
|
const imdbId = /\b(tt|nm|co|ev|ch|ni)\d{7,10}\b/i.exec(fileName)?.at(0) ?? '';
|
||||||
|
let id = (imdbId !== '')
|
||||||
|
? Number(
|
||||||
|
(await args.deps.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: `${arrHost}/api/v3/movie/lookup?terms=imdb:${imdbId}`,
|
||||||
|
headers,
|
||||||
|
})).data?.id ?? -1,
|
||||||
|
)
|
||||||
|
: -1;
|
||||||
|
if (id === -1) {
|
||||||
|
id = refreshType.delegates.getIdFromParseResponse(
|
||||||
|
(await args.deps.axios({
|
||||||
|
method: 'get',
|
||||||
|
url: `${arrHost}/api/v3/parse?title=${encodeURIComponent(getFileName(fileName))}`,
|
||||||
|
headers,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
args.jobLog(`${refreshType.content} ${id !== -1 ? `${id} found` : 'not found'} for '${fileName}', imdb '${imdbId}'`);
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
|
||||||
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
const lib = require('../../../../../methods/lib')();
|
const lib = require('../../../../../methods/lib')();
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-param-reassign
|
||||||
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
args.inputs = lib.loadDefaultValues(args.inputs, details);
|
||||||
|
|
||||||
const { arr, arr_api_key } = args.inputs;
|
// Variables initialization
|
||||||
|
let refreshed = false;
|
||||||
|
const arr = String(args.inputs.arr);
|
||||||
const arr_host = String(args.inputs.arr_host).trim();
|
const arr_host = String(args.inputs.arr_host).trim();
|
||||||
const arrHost = arr_host.endsWith('/') ? arr_host.slice(0, -1) : arr_host;
|
const arrHost = arr_host.endsWith('/') ? arr_host.slice(0, -1) : arr_host;
|
||||||
const fileNames: IFileNames = {
|
const absoluteFileDir = getFileAbosluteDir(args.originalLibraryFile?._id ?? '');
|
||||||
originalFileName: getFileName(args.originalLibraryFile?._id ?? ''),
|
const fileNames = {
|
||||||
currentFileName: getFileName(args.inputFileObj?._id ?? ''),
|
originalFileName: path.join(absoluteFileDir, getFileName(args.originalLibraryFile?._id ?? '')),
|
||||||
|
currentFileName: path.join(absoluteFileDir, getFileName(args.inputFileObj?._id ?? '')),
|
||||||
};
|
};
|
||||||
|
const headers: IHTTPHeaders = {
|
||||||
const refresh = async (refreshType: IRefreshType)
|
'Content-Type': 'application/json',
|
||||||
: Promise<boolean> => {
|
'X-Api-Key': String(args.inputs.arr_api_key),
|
||||||
args.jobLog('Going to force scan');
|
Accept: 'application/json',
|
||||||
args.jobLog(`Refreshing ${refreshType.appName}...`);
|
|
||||||
|
|
||||||
let refreshed = false;
|
|
||||||
const headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Api-Key': arr_api_key,
|
|
||||||
Accept: 'application/json',
|
|
||||||
};
|
|
||||||
|
|
||||||
const getId = async (fileName: string)
|
|
||||||
: Promise<number> => {
|
|
||||||
// Using parse endpoint to get the movie/serie's id.
|
|
||||||
const parseRequestConfig = {
|
|
||||||
method: 'get',
|
|
||||||
url: `${arrHost}/api/v3/parse?title=${encodeURIComponent(fileName)}`,
|
|
||||||
headers,
|
|
||||||
};
|
|
||||||
const parseRequestResult = await args.deps.axios(parseRequestConfig);
|
|
||||||
const id = refreshType.delegates.getIdFromParseRequestResult(parseRequestResult);
|
|
||||||
args.jobLog(id !== -1
|
|
||||||
? `Found ${refreshType.contentName} ${id} with a file named '${fileName}'`
|
|
||||||
: `Didn't find ${refreshType.contentName} with a file named '${fileName}' in ${arrHost}.`);
|
|
||||||
return id;
|
|
||||||
};
|
|
||||||
|
|
||||||
let fileName = fileNames.originalFileName;
|
|
||||||
let id = await getId(fileName);
|
|
||||||
// In case there has been a name change and the arr app already noticed it.
|
|
||||||
if (id === -1 && fileNames.currentFileName !== fileNames.originalFileName) {
|
|
||||||
fileName = fileNames.currentFileName;
|
|
||||||
id = await getId(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Checking that the file has been found.
|
|
||||||
if (id !== -1) {
|
|
||||||
// Using refresh command endpoint to force rescan.
|
|
||||||
const refreshResquestConfig = {
|
|
||||||
method: 'post',
|
|
||||||
url: `${arrHost}/api/v3/command`,
|
|
||||||
headers,
|
|
||||||
data: refreshType.delegates.buildRefreshResquestData(id),
|
|
||||||
};
|
|
||||||
await args.deps.axios(refreshResquestConfig);
|
|
||||||
|
|
||||||
refreshed = true;
|
|
||||||
args.jobLog(`✔ Refreshed ${refreshType.contentName} ${id} in ${refreshType.appName}.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return refreshed;
|
|
||||||
};
|
};
|
||||||
|
const refreshType: IRefreshType = arr === 'radarr'
|
||||||
const refreshTypes: IRefreshTypes = {
|
? {
|
||||||
radarr: {
|
|
||||||
appName: 'Radarr',
|
appName: 'Radarr',
|
||||||
contentName: 'movie',
|
content: 'Movie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseRequestResult:
|
getIdFromParseResponse:
|
||||||
(parseRequestResult) => Number(parseRequestResult.data?.movie?.movieFile?.movieId ?? -1),
|
(parseRequestResult: IParsedRequestResult) => Number(parseRequestResult.data?.movie?.id ?? -1),
|
||||||
buildRefreshResquestData:
|
buildRefreshResquestData:
|
||||||
(id) => JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }),
|
(id) => JSON.stringify({ name: 'RefreshMovie', movieIds: [id] }),
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
sonarr: {
|
: {
|
||||||
appName: 'Sonarr',
|
appName: 'Sonarr',
|
||||||
contentName: 'serie',
|
content: 'Serie',
|
||||||
delegates: {
|
delegates: {
|
||||||
getIdFromParseRequestResult:
|
getIdFromParseResponse:
|
||||||
(parseRequestResult) => Number(parseRequestResult.data?.series?.id ?? -1),
|
(parseRequestResult: IParsedRequestResult) => Number(parseRequestResult.data?.series?.id ?? -1),
|
||||||
buildRefreshResquestData:
|
buildRefreshResquestData:
|
||||||
(id) => JSON.stringify({ name: 'RefreshSeries', seriesId: id }),
|
(id) => JSON.stringify({ name: 'RefreshSeries', seriesId: id }),
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
};
|
|
||||||
|
|
||||||
const refreshed = await refresh(arr === 'radarr' ? refreshTypes.radarr : refreshTypes.sonarr);
|
args.jobLog('Going to force scan');
|
||||||
|
args.jobLog(`Refreshing ${refreshType.appName}...`);
|
||||||
|
|
||||||
|
let id = await getId(args, arrHost, headers, fileNames.originalFileName, refreshType);
|
||||||
|
// Useful in some edge cases
|
||||||
|
if (id === -1 && fileNames.currentFileName !== fileNames.originalFileName) {
|
||||||
|
id = await getId(args, arrHost, headers, fileNames.currentFileName, refreshType);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checking that the file has been found
|
||||||
|
if (id !== -1) {
|
||||||
|
// Using command endpoint to queue a refresh task
|
||||||
|
await args.deps.axios({
|
||||||
|
method: 'post',
|
||||||
|
url: `${arrHost}/api/v3/command`,
|
||||||
|
headers,
|
||||||
|
data: refreshType.delegates.buildRefreshResquestData(id),
|
||||||
|
});
|
||||||
|
|
||||||
|
refreshed = true;
|
||||||
|
args.jobLog(`✔ Refreshed ${refreshType.content} ${id} in ${refreshType.appName}.`);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outputFileObj: args.inputFileObj,
|
outputFileObj: args.inputFileObj,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue