mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-16 10:45:53 -07:00
Force rename with radarr/sonarr : added file move after rename
This commit is contained in:
parent
87578facad
commit
c3ad020b4b
2 changed files with 73 additions and 37 deletions
|
|
@ -35,8 +35,13 @@ 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 fileMoveOrCopy_1 = __importDefault(require("../../../../FlowHelpers/1.0.0/fileMoveOrCopy"));
|
||||||
|
var fileUtils_1 = require("../../../../FlowHelpers/1.0.0/fileUtils");
|
||||||
var details = function () { return ({
|
var details = function () { return ({
|
||||||
name: 'Force File Rename Radarr or Sonarr',
|
name: 'Force File Rename Radarr or Sonarr',
|
||||||
description: 'Force Radarr or Sonarr to rename a file according to the naming policy',
|
description: 'Force Radarr or Sonarr to rename a file according to the naming policy',
|
||||||
|
|
@ -96,32 +101,31 @@ var details = function () { return ({
|
||||||
}); };
|
}); };
|
||||||
exports.details = details;
|
exports.details = details;
|
||||||
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, fileName, arrHost, headers, rename, existingPath, newPath, episodeNumber_1;
|
var lib, _a, arr, arr_api_key, arr_host, arrHost, fileName, rename, existingPath, newPath, episodeNumber_1, outputFileObj, destinationPath;
|
||||||
var _b, _c;
|
var _b, _c;
|
||||||
var _d, _e;
|
return __generator(this, function (_d) {
|
||||||
return __generator(this, function (_f) {
|
switch (_d.label) {
|
||||||
switch (_f.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;
|
_a = args.inputs, arr = _a.arr, arr_api_key = _a.arr_api_key;
|
||||||
arr_host = String(args.inputs.arr_host).trim();
|
arr_host = String(args.inputs.arr_host).trim();
|
||||||
fileName = ((_e = (_d = args.originalLibraryFile) === null || _d === void 0 ? void 0 : _d.meta) === null || _e === void 0 ? void 0 : _e.FileName) || '';
|
|
||||||
arrHost = arr_host.endsWith('/') ? arr_host.slice(0, -1) : arr_host;
|
arrHost = arr_host.endsWith('/') ? arr_host.slice(0, -1) : arr_host;
|
||||||
headers = {
|
fileName = (0, fileUtils_1.getFileName)(args.inputFileObj._id);
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Api-Key': arr_api_key,
|
|
||||||
Accept: 'application/json',
|
|
||||||
};
|
|
||||||
rename = function (delegates) { return __awaiter(void 0, void 0, void 0, function () {
|
rename = function (delegates) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var existingPath, newPath, parseRequestConfig, parseRequestResult, id, previewRenameRequestConfig, previewRenameRequestResult, fileToRename, renameRequestConfig;
|
var existingPath, newPath, headers, parseRequestConfig, parseRequestResult, id, previewRenameRequestConfig, previewRenameRequestResult, fileToRename, renameRequestConfig;
|
||||||
return __generator(this, function (_a) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0:
|
case 0:
|
||||||
args.jobLog('Going to force rename');
|
args.jobLog('Going to force rename');
|
||||||
args.jobLog("Renaming ".concat(arr === 'radarr' ? 'Radarr' : 'Sonarr', "..."));
|
args.jobLog("Renaming ".concat(arr === 'radarr' ? 'Radarr' : 'Sonarr', "..."));
|
||||||
newPath = '';
|
existingPath = '', newPath = '';
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Api-Key': arr_api_key,
|
||||||
|
Accept: 'application/json',
|
||||||
|
};
|
||||||
parseRequestConfig = {
|
parseRequestConfig = {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: "".concat(arrHost, "/api/v3/parse?title=").concat(encodeURIComponent(fileName)),
|
url: "".concat(arrHost, "/api/v3/parse?title=").concat(encodeURIComponent(fileName)),
|
||||||
|
|
@ -154,7 +158,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
args.jobLog("\u2714 Renamed ".concat(arr === 'radarr' ? 'movie' : 'serie', " ").concat(id, " in ").concat(arr === 'radarr' ? 'Radarr' : 'Sonarr', " : '").concat(existingPath, "' => '").concat(newPath, "'."));
|
args.jobLog("\u2714 Renamed ".concat(arr === 'radarr' ? 'movie' : 'serie', " ").concat(id, " in ").concat(arr === 'radarr' ? 'Radarr' : 'Sonarr', " : '").concat(existingPath, "' => '").concat(newPath, "'."));
|
||||||
return [3 /*break*/, 5];
|
return [3 /*break*/, 5];
|
||||||
case 4:
|
case 4:
|
||||||
args.jobLog("\u2714 No rename necessary.");
|
args.jobLog('✔ No rename necessary.');
|
||||||
_a.label = 5;
|
_a.label = 5;
|
||||||
case 5: return [2 /*return*/, { existingPath: existingPath, newPath: newPath }];
|
case 5: return [2 /*return*/, { existingPath: existingPath, newPath: newPath }];
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +184,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
}
|
}
|
||||||
})];
|
})];
|
||||||
case 1:
|
case 1:
|
||||||
(_b = _f.sent(), existingPath = _b.existingPath, newPath = _b.newPath);
|
(_b = _d.sent(), existingPath = _b.existingPath, newPath = _b.newPath);
|
||||||
return [3 /*break*/, 5];
|
return [3 /*break*/, 5];
|
||||||
case 2:
|
case 2:
|
||||||
if (!(arr === 'sonarr')) return [3 /*break*/, 4];
|
if (!(arr === 'sonarr')) return [3 /*break*/, 4];
|
||||||
|
|
@ -193,6 +197,7 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
},
|
},
|
||||||
getFileToRename: function (previewRenameRequestResult) {
|
getFileToRename: function (previewRenameRequestResult) {
|
||||||
var _a, _b;
|
var _a, _b;
|
||||||
|
args.jobLog(JSON.stringify(previewRenameRequestResult));
|
||||||
return (((_b = (_a = previewRenameRequestResult.data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) ?
|
return (((_b = (_a = previewRenameRequestResult.data) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) ?
|
||||||
previewRenameRequestResult.data.find(function (episFile) { var _a, _b; return (((_b = (_a = episFile.episodeNumbers) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) ? episFile.episodeNumbers[0] === episodeNumber_1 : false; })
|
previewRenameRequestResult.data.find(function (episFile) { var _a, _b; return (((_b = (_a = episFile.episodeNumbers) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) ? episFile.episodeNumbers[0] === episodeNumber_1 : false; })
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
@ -206,15 +211,28 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
}
|
}
|
||||||
})];
|
})];
|
||||||
case 3:
|
case 3:
|
||||||
(_c = _f.sent(), existingPath = _c.existingPath, newPath = _c.newPath);
|
(_c = _d.sent(), existingPath = _c.existingPath, newPath = _c.newPath);
|
||||||
return [3 /*break*/, 5];
|
return [3 /*break*/, 5];
|
||||||
case 4:
|
case 4:
|
||||||
args.jobLog('No arr specified in plugin inputs.');
|
args.jobLog('No arr specified in plugin inputs.');
|
||||||
_f.label = 5;
|
_d.label = 5;
|
||||||
case 5: return [2 /*return*/, {
|
case 5:
|
||||||
outputFileObj: {
|
outputFileObj = args.inputFileObj;
|
||||||
_id: args.inputFileObj._id.replace(existingPath, newPath)
|
if (!(existingPath !== newPath)) return [3 /*break*/, 7];
|
||||||
},
|
destinationPath = "".concat((0, fileUtils_1.getFileAbosluteDir)(args.inputFileObj._id), "/").concat((0, fileUtils_1.getFileName)(newPath));
|
||||||
|
return [4 /*yield*/, (0, fileMoveOrCopy_1.default)({
|
||||||
|
operation: 'move',
|
||||||
|
sourcePath: args.inputFileObj._id,
|
||||||
|
destinationPath: destinationPath,
|
||||||
|
args: args,
|
||||||
|
})];
|
||||||
|
case 6:
|
||||||
|
_d.sent();
|
||||||
|
args.jobLog("\u2714 File moved : '".concat(args.inputFileObj._id, "' => '").concat(destinationPath, "'."));
|
||||||
|
outputFileObj = { _id: destinationPath };
|
||||||
|
_d.label = 7;
|
||||||
|
case 7: return [2 /*return*/, {
|
||||||
|
outputFileObj: outputFileObj,
|
||||||
outputNumber: 1,
|
outputNumber: 1,
|
||||||
variables: args.variables,
|
variables: args.variables,
|
||||||
}];
|
}];
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
import fileMoveOrCopy from '../../../../FlowHelpers/1.0.0/fileMoveOrCopy';
|
||||||
|
import {
|
||||||
|
getFileAbosluteDir, getFileName,
|
||||||
|
} from '../../../../FlowHelpers/1.0.0/fileUtils';
|
||||||
import {
|
import {
|
||||||
IpluginDetails,
|
IpluginDetails,
|
||||||
IpluginInputArgs,
|
IpluginInputArgs,
|
||||||
|
|
@ -69,16 +73,8 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
const { arr, arr_api_key } = args.inputs;
|
const { arr, arr_api_key } = args.inputs;
|
||||||
const arr_host = String(args.inputs.arr_host).trim();
|
const arr_host = String(args.inputs.arr_host).trim();
|
||||||
|
|
||||||
const fileName = args.originalLibraryFile?.meta?.FileName || '';
|
|
||||||
|
|
||||||
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 fileName = getFileName(args.inputFileObj._id);
|
||||||
const headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Api-Key': arr_api_key,
|
|
||||||
Accept: 'application/json',
|
|
||||||
};
|
|
||||||
|
|
||||||
interface IRenameDelegates {
|
interface IRenameDelegates {
|
||||||
getId: (parseRequestResult: any) => any,
|
getId: (parseRequestResult: any) => any,
|
||||||
|
|
@ -92,7 +88,13 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
args.jobLog('Going to force rename');
|
args.jobLog('Going to force rename');
|
||||||
args.jobLog(`Renaming ${arr === 'radarr' ? 'Radarr' : 'Sonarr'}...`);
|
args.jobLog(`Renaming ${arr === 'radarr' ? 'Radarr' : 'Sonarr'}...`);
|
||||||
|
|
||||||
let existingPath, newPath = '';
|
let existingPath = '', newPath = '';
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Api-Key': arr_api_key,
|
||||||
|
Accept: 'application/json',
|
||||||
|
};
|
||||||
|
|
||||||
// Using parse endpoint to get the movie/serie's id.
|
// Using parse endpoint to get the movie/serie's id.
|
||||||
const parseRequestConfig = {
|
const parseRequestConfig = {
|
||||||
|
|
@ -127,7 +129,7 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
|
|
||||||
args.jobLog(`✔ Renamed ${arr === 'radarr' ? 'movie' : 'serie'} ${id} in ${arr === 'radarr' ? 'Radarr' : 'Sonarr'} : '${existingPath}' => '${newPath}'.`);
|
args.jobLog(`✔ Renamed ${arr === 'radarr' ? 'movie' : 'serie'} ${id} in ${arr === 'radarr' ? 'Radarr' : 'Sonarr'} : '${existingPath}' => '${newPath}'.`);
|
||||||
} else
|
} else
|
||||||
args.jobLog(`✔ No rename necessary.`);
|
args.jobLog('✔ No rename necessary.');
|
||||||
|
|
||||||
return { existingPath, newPath };
|
return { existingPath, newPath };
|
||||||
};
|
};
|
||||||
|
|
@ -157,10 +159,12 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
episodeNumber = parseRequestResult.data.parsedEpisodeInfo.episodeNumbers[0];
|
episodeNumber = parseRequestResult.data.parsedEpisodeInfo.episodeNumbers[0];
|
||||||
return `${arrHost}/api/v3/rename?seriesId=${id}&seasonNumber=${parseRequestResult.data.parsedEpisodeInfo.seasonNumber}`;
|
return `${arrHost}/api/v3/rename?seriesId=${id}&seasonNumber=${parseRequestResult.data.parsedEpisodeInfo.seasonNumber}`;
|
||||||
},
|
},
|
||||||
getFileToRename: (previewRenameRequestResult) =>
|
getFileToRename: (previewRenameRequestResult) => {
|
||||||
((previewRenameRequestResult.data?.length ?? 0) > 0) ?
|
args.jobLog(JSON.stringify(previewRenameRequestResult));
|
||||||
|
return ((previewRenameRequestResult.data?.length ?? 0) > 0) ?
|
||||||
previewRenameRequestResult.data.find((episFile: { episodeNumbers: number[]; }) => ((episFile.episodeNumbers?.length ?? 0) > 0) ? episFile.episodeNumbers[0] === episodeNumber : false)
|
previewRenameRequestResult.data.find((episFile: { episodeNumbers: number[]; }) => ((episFile.episodeNumbers?.length ?? 0) > 0) ? episFile.episodeNumbers[0] === episodeNumber : false)
|
||||||
: undefined,
|
: undefined
|
||||||
|
},
|
||||||
getRenameResquestConfigData: (id, fileToRename) => {
|
getRenameResquestConfigData: (id, fileToRename) => {
|
||||||
return {
|
return {
|
||||||
name: 'RenameFiles',
|
name: 'RenameFiles',
|
||||||
|
|
@ -173,10 +177,24 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
args.jobLog('No arr specified in plugin inputs.');
|
args.jobLog('No arr specified in plugin inputs.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If file has been renamed, move the transcoded file accordingly
|
||||||
|
let outputFileObj: {_id : string} = args.inputFileObj;
|
||||||
|
if (existingPath !== newPath) {
|
||||||
|
const destinationPath = `${getFileAbosluteDir(args.inputFileObj._id)}/${getFileName(newPath)}`;
|
||||||
|
|
||||||
|
await fileMoveOrCopy({
|
||||||
|
operation: 'move',
|
||||||
|
sourcePath: args.inputFileObj._id,
|
||||||
|
destinationPath: destinationPath,
|
||||||
|
args,
|
||||||
|
});
|
||||||
|
args.jobLog(`✔ File moved : '${args.inputFileObj._id}' => '${destinationPath}'.`);
|
||||||
|
|
||||||
|
outputFileObj = { _id: destinationPath };
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
outputFileObj: {
|
outputFileObj: outputFileObj,
|
||||||
_id: args.inputFileObj._id.replace(existingPath, newPath)
|
|
||||||
},
|
|
||||||
outputNumber: 1,
|
outputNumber: 1,
|
||||||
variables: args.variables,
|
variables: args.variables,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue