mirror of
https://github.com/gabehf/Tdarr_Plugins.git
synced 2026-03-16 10:45:53 -07:00
Rename with radarr/sonarr Flow plugin now updates the file id
This commit is contained in:
parent
aa79f27f5a
commit
4be4bc7169
2 changed files with 43 additions and 16 deletions
|
|
@ -96,7 +96,7 @@ 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;
|
var lib, _a, arr, arr_api_key, arr_host, fileName, arrHost, headers, rename, existingPath, newPath, episodeNumber_1, newFileId;
|
||||||
var _b, _c;
|
var _b, _c;
|
||||||
return __generator(this, function (_d) {
|
return __generator(this, function (_d) {
|
||||||
switch (_d.label) {
|
switch (_d.label) {
|
||||||
|
|
@ -113,12 +113,12 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
'X-Api-Key': arr_api_key,
|
'X-Api-Key': arr_api_key,
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
};
|
};
|
||||||
args.jobLog('Going to force rename');
|
|
||||||
rename = function (getId, getPreviewRenameResquestUrl, getRenameResquestData) { return __awaiter(void 0, void 0, void 0, function () {
|
rename = function (getId, getPreviewRenameResquestUrl, getRenameResquestData) { return __awaiter(void 0, void 0, void 0, function () {
|
||||||
var parseRequestConfig, parseRequestResult, id, previewRenameRequestConfig, previewRenameRequestResult, renameRequestConfig;
|
var parseRequestConfig, parseRequestResult, id, previewRenameRequestConfig, previewRenameRequestResult, 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("Renaming ".concat(arr === 'radarr' ? 'Radarr' : 'Sonarr', "..."));
|
args.jobLog("Renaming ".concat(arr === 'radarr' ? 'Radarr' : 'Sonarr', "..."));
|
||||||
parseRequestConfig = {
|
parseRequestConfig = {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
|
|
@ -151,12 +151,15 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}); };
|
}); };
|
||||||
|
newPath = '';
|
||||||
if (!(arr === 'radarr')) return [3 /*break*/, 2];
|
if (!(arr === 'radarr')) return [3 /*break*/, 2];
|
||||||
return [4 /*yield*/, rename(function (parseRequestResult) { return parseRequestResult.data.movie.movieFile.movieId; }, function (id, parseRequestResult) { return "".concat(arrHost, "/api/v3/rename?movieId=").concat(id); }, function (id, previewRenameRequestResult) {
|
return [4 /*yield*/, rename(function (parseRequestResult) { return parseRequestResult.data.movie.movieFile.movieId; }, function (id, parseRequestResult) { return "".concat(arrHost, "/api/v3/rename?movieId=").concat(id); }, function (id, previewRenameRequestResult) {
|
||||||
|
var movieFile = previewRenameRequestResult.data[0];
|
||||||
|
(existingPath = movieFile.existingPath, newPath = movieFile.newPath);
|
||||||
return {
|
return {
|
||||||
name: 'RenameFiles',
|
name: 'RenameFiles',
|
||||||
movieId: id,
|
movieId: id,
|
||||||
files: previewRenameRequestResult.data.map(function (movieFile) { return movieFile.movieFileId; })
|
files: [movieFile.movieFileId]
|
||||||
};
|
};
|
||||||
})];
|
})];
|
||||||
case 1:
|
case 1:
|
||||||
|
|
@ -164,11 +167,17 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
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];
|
||||||
return [4 /*yield*/, rename(function (parseRequestResult) { return parseRequestResult.data.series.id; }, function (id, parseRequestResult) { return "".concat(arrHost, "/api/v3/rename?seriesId=").concat(id, "&seasonNumber=").concat(parseRequestResult.data.parsedEpisodeInfo.seasonNumber); }, function (id, previewRenameRequestResult) {
|
episodeNumber_1 = 0;
|
||||||
|
return [4 /*yield*/, rename(function (parseRequestResult) { return parseRequestResult.data.series.id; }, function (id, parseRequestResult) {
|
||||||
|
episodeNumber_1 = parseRequestResult.data.parsedEpisodeInfo.episodeNumbers[0];
|
||||||
|
return "".concat(arrHost, "/api/v3/rename?seriesId=").concat(id, "&seasonNumber=").concat(parseRequestResult.data.parsedEpisodeInfo.seasonNumber);
|
||||||
|
}, function (id, previewRenameRequestResult) {
|
||||||
|
var episodeFile = previewRenameRequestResult.find(function (episFile) { return episFile.episodeNumbers[0] === episodeNumber_1; });
|
||||||
|
(existingPath = episodeFile.existingPath, newPath = episodeFile.newPath);
|
||||||
return {
|
return {
|
||||||
name: 'RenameFiles',
|
name: 'RenameFiles',
|
||||||
seriesId: id,
|
seriesId: id,
|
||||||
files: previewRenameRequestResult.data.map(function (episodeFile) { return episodeFile.episodeFileId; })
|
files: [episodeFile.episodeFileId]
|
||||||
};
|
};
|
||||||
})];
|
})];
|
||||||
case 3:
|
case 3:
|
||||||
|
|
@ -177,11 +186,16 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
|
||||||
case 4:
|
case 4:
|
||||||
args.jobLog('No arr specified in plugin inputs.');
|
args.jobLog('No arr specified in plugin inputs.');
|
||||||
_d.label = 5;
|
_d.label = 5;
|
||||||
case 5: return [2 /*return*/, {
|
case 5:
|
||||||
outputFileObj: args.inputFileObj,
|
newFileId = args.inputFileObj.replace(existingPath, newPath);
|
||||||
outputNumber: 1,
|
args.jobLog("New file iid ".concat(newFileId));
|
||||||
variables: args.variables,
|
return [2 /*return*/, {
|
||||||
}];
|
outputFileObj: {
|
||||||
|
_id: newFileId
|
||||||
|
},
|
||||||
|
outputNumber: 1,
|
||||||
|
variables: args.variables,
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}); };
|
}); };
|
||||||
|
|
|
||||||
|
|
@ -80,13 +80,13 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
};
|
};
|
||||||
|
|
||||||
args.jobLog('Going to force rename');
|
|
||||||
|
|
||||||
const rename = async (
|
const rename = async (
|
||||||
getId: (parseRequestResult: any) => any,
|
getId: (parseRequestResult: any) => any,
|
||||||
getPreviewRenameResquestUrl: (id: any, parseRequestResult: any) => any,
|
getPreviewRenameResquestUrl: (id: any, parseRequestResult: any) => any,
|
||||||
getRenameResquestData: (id: any, previewRenameRequestResult: any) => any)
|
getRenameResquestData: (id: any, previewRenameRequestResult: any) => any)
|
||||||
: Promise<void> => {
|
: Promise<void> => {
|
||||||
|
args.jobLog('Going to force rename');
|
||||||
|
|
||||||
args.jobLog(`Renaming ${arr === 'radarr' ? 'Radarr' : 'Sonarr'}...`);
|
args.jobLog(`Renaming ${arr === 'radarr' ? 'Radarr' : 'Sonarr'}...`);
|
||||||
|
|
||||||
// Using parse endpoint to get the movie/serie's id.
|
// Using parse endpoint to get the movie/serie's id.
|
||||||
|
|
@ -118,27 +118,36 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
args.jobLog(`✔ Renamed ${arr === 'radarr' ? 'movie' : 'serie'} ${id} in ${arr === 'radarr' ? 'Radarr' : 'Sonarr'}.`);
|
args.jobLog(`✔ Renamed ${arr === 'radarr' ? 'movie' : 'serie'} ${id} in ${arr === 'radarr' ? 'Radarr' : 'Sonarr'}.`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let existingPath, newPath = '';
|
||||||
if (arr === 'radarr') {
|
if (arr === 'radarr') {
|
||||||
await rename(
|
await rename(
|
||||||
(parseRequestResult) => parseRequestResult.data.movie.movieFile.movieId,
|
(parseRequestResult) => parseRequestResult.data.movie.movieFile.movieId,
|
||||||
(id, parseRequestResult) => `${arrHost}/api/v3/rename?movieId=${id}`,
|
(id, parseRequestResult) => `${arrHost}/api/v3/rename?movieId=${id}`,
|
||||||
(id, previewRenameRequestResult) => {
|
(id, previewRenameRequestResult) => {
|
||||||
|
const movieFile = previewRenameRequestResult.data[0];
|
||||||
|
({ existingPath, newPath } = movieFile);
|
||||||
return {
|
return {
|
||||||
name: 'RenameFiles',
|
name: 'RenameFiles',
|
||||||
movieId: id,
|
movieId: id,
|
||||||
files: previewRenameRequestResult.data.map((movieFile: { movieFileId: any; }) => movieFile.movieFileId)
|
files: [movieFile.movieFileId]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else if (arr === 'sonarr') {
|
} else if (arr === 'sonarr') {
|
||||||
|
let episodeNumber = 0;
|
||||||
await rename(
|
await rename(
|
||||||
(parseRequestResult) => parseRequestResult.data.series.id,
|
(parseRequestResult) => parseRequestResult.data.series.id,
|
||||||
(id, parseRequestResult) => `${arrHost}/api/v3/rename?seriesId=${id}&seasonNumber=${parseRequestResult.data.parsedEpisodeInfo.seasonNumber}`,
|
(id, parseRequestResult) => {
|
||||||
|
episodeNumber = parseRequestResult.data.parsedEpisodeInfo.episodeNumbers[0];
|
||||||
|
return `${arrHost}/api/v3/rename?seriesId=${id}&seasonNumber=${parseRequestResult.data.parsedEpisodeInfo.seasonNumber}`;
|
||||||
|
},
|
||||||
(id, previewRenameRequestResult) => {
|
(id, previewRenameRequestResult) => {
|
||||||
|
const episodeFile = previewRenameRequestResult.find((episFile: { episodeNumbers: number[]; }) => episFile.episodeNumbers[0] === episodeNumber);
|
||||||
|
({ existingPath, newPath } = episodeFile);
|
||||||
return {
|
return {
|
||||||
name: 'RenameFiles',
|
name: 'RenameFiles',
|
||||||
seriesId: id,
|
seriesId: id,
|
||||||
files: previewRenameRequestResult.data.map((episodeFile: { episodeFileId: any; }) => episodeFile.episodeFileId)
|
files: [episodeFile.episodeFileId]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -146,8 +155,12 @@ const plugin = async (args: IpluginInputArgs): Promise<IpluginOutputArgs> => {
|
||||||
args.jobLog('No arr specified in plugin inputs.');
|
args.jobLog('No arr specified in plugin inputs.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newFileId = args.inputFileObj.replace(existingPath, newPath);
|
||||||
|
args.jobLog(`New file iid ${newFileId}`);
|
||||||
return {
|
return {
|
||||||
outputFileObj: args.inputFileObj,
|
outputFileObj: {
|
||||||
|
_id: newFileId
|
||||||
|
},
|
||||||
outputNumber: 1,
|
outputNumber: 1,
|
||||||
variables: args.variables,
|
variables: args.variables,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue