@ -43,8 +43,8 @@ exports.plugin = exports.details = void 0;
var fileMoveOrCopy _1 = _ _importDefault ( require ( "../../../../FlowHelpers/1.0.0/fileMoveOrCopy" ) ) ;
var fileMoveOrCopy _1 = _ _importDefault ( require ( "../../../../FlowHelpers/1.0.0/fileMoveOrCopy" ) ) ;
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 : ' Force File Rename Radarr or Sonarr ',
name : ' Apply Radarr or Sonarr naming policy ',
description : ' Force Radarr or Sonarr to rename a file according to the naming policy ',
description : ' Apply Radarr or Sonarr naming policy to a file. This plugin should be called after the original file has been replaced and Radarr or Sonarr has been notified. Radarr or Sonarr should also be notified after this plugin. ',
style : {
style : {
borderColor : 'green' ,
borderColor : 'green' ,
} ,
} ,
@ -101,10 +101,9 @@ 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 , arrHost , fileName , rename , existingPath , newPath , episodeNumber _1 , outputFileObj , destinationPath ;
var lib , _a , arr , arr _api _key , arr _host , arrHost , fileName , rename , destinationPath , episodeNumber _1 ;
var _b , _c ;
return _ _generator ( this , function ( _b ) {
return _ _generator ( this , function ( _d ) {
switch ( _b . label ) {
switch ( _d . 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
@ -114,13 +113,13 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
arrHost = arr _host . endsWith ( '/' ) ? arr _host . slice ( 0 , - 1 ) : arr _host ;
arrHost = arr _host . endsWith ( '/' ) ? arr _host . slice ( 0 , - 1 ) : arr _host ;
fileName = ( 0 , fileUtils _1 . getFileName ) ( args . inputFileObj . _id ) ;
fileName = ( 0 , fileUtils _1 . getFileName ) ( args . inputFileObj . _id ) ;
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, new Path, headers , parseRequestConfig , parseRequestResult , id , previewRenameRequestConfig , previewRenameRequestResult , fileToRename , renameRequestConfig ;
var destination Path, headers , parseRequestConfig , parseRequestResult , id , previewRenameRequestConfig , previewRenameRequestResult , fileToRename ;
return _ _generator ( this , function ( _a ) {
return _ _generator ( this , function ( _a ) {
switch ( _a . label ) {
switch ( _a . label ) {
case 0 :
case 0 :
destinationPath = '' ;
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' , "..." ) ) ;
existingPath = '' , newPath = '' ;
headers = {
headers = {
'Content-Type' : 'application/json' ,
'Content-Type' : 'application/json' ,
'X-Api-Key' : arr _api _key ,
'X-Api-Key' : arr _api _key ,
@ -145,26 +144,25 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
previewRenameRequestResult = _a . sent ( ) ;
previewRenameRequestResult = _a . sent ( ) ;
fileToRename = delegates . getFileToRename ( previewRenameRequestResult ) ;
fileToRename = delegates . getFileToRename ( previewRenameRequestResult ) ;
if ( ! ( fileToRename !== undefined ) ) return [ 3 /*break*/ , 4 ] ;
if ( ! ( fileToRename !== undefined ) ) return [ 3 /*break*/ , 4 ] ;
( existingPath = fileToRename . existingPath , newPath = fileToRename . newPath ) ;
destinationPath = "" . concat ( ( 0 , fileUtils _1 . getFileAbosluteDir ) ( args . inputFileObj . _id ) , "/" ) . concat ( ( 0 , fileUtils _1 . getFileName ) ( fileToRename . newPath ) , "." ) . concat ( ( 0 , fileUtils _1 . getContainer ) ( fileToRename . newPath ) ) ;
renameRequestConfig = {
return [ 4 /*yield*/ , ( 0 , fileMoveOrCopy _1 . default ) ( {
method : 'post' ,
operation : 'move' ,
url : "" . concat ( arrHost , "/api/v3/command" ) ,
sourcePath : args . inputFileObj . _id ,
headers : headers ,
destinationPath : destinationPath ,
data : JSON . stringify ( delegates . getRenameResquestConfigData ( id , fileToRename ) )
args : args ,
} ;
} ) ] ;
return [ 4 /*yield*/ , args . deps . axios ( renameRequestConfig ) ] ;
case 3 :
case 3 :
_a . sent ( ) ;
_a . sent ( ) ;
args . jobLog ( "\u2714 Renamed " . concat ( arr === 'radarr' ? 'movie' : 'serie' , " " ) . concat ( id , " in ") . concat ( arr === 'radarr' ? 'Radarr' : 'Sonarr' , " : '" ) . concat ( existingPath , "' => '" ) . concat ( new Path, "'." ) ) ;
args . jobLog ( "\u2714 Renamed " . concat ( arr === 'radarr' ? 'movie' : 'serie' , " " ) . concat ( id , " : '") . concat ( args . inputFileObj . _id , "' => '" ) . concat ( destination Path, "'." ) ) ;
return [ 3 /*break*/ , 5 ] ;
return [ 3 /*break*/ , 5 ] ;
case 4 :
case 4 :
args . jobLog ( '✔ 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*/ , destinationPath ] ;
}
}
} ) ;
} ) ;
} ) ; } ;
} ) ; } ;
new Path = '' ;
destination Path = '' ;
if ( ! ( arr === 'radarr' ) ) return [ 3 /*break*/ , 2 ] ;
if ( ! ( arr === 'radarr' ) ) return [ 3 /*break*/ , 2 ] ;
return [ 4 /*yield*/ , rename ( {
return [ 4 /*yield*/ , rename ( {
getId : function ( parseRequestResult ) { return parseRequestResult . data . movie . movieFile . movieId ; } ,
getId : function ( parseRequestResult ) { return parseRequestResult . data . movie . movieFile . movieId ; } ,
@ -174,17 +172,10 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
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 [ 0 ]
previewRenameRequestResult . data [ 0 ]
: undefined ;
: undefined ;
} ,
getRenameResquestConfigData : function ( id , fileToRename ) {
return {
name : 'RenameFiles' ,
movieId : id ,
files : [ fileToRename . movieFileId ]
} ;
}
}
} ) ] ;
} ) ] ;
case 1 :
case 1 :
( _b = _d . sent ( ) , existingPath = _b . existingPath , newPath = _b . newPath ) ;
destinationPath = _b . sent ( ) ;
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 ] ;
@ -200,38 +191,16 @@ var plugin = function (args) { return __awaiter(void 0, void 0, void 0, function
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 ;
} ,
getRenameResquestConfigData : function ( id , fileToRename ) {
return {
name : 'RenameFiles' ,
seriesId : id ,
files : [ fileToRename . episodeFileId ]
} ;
}
}
} ) ] ;
} ) ] ;
case 3 :
case 3 :
( _c = _d . sent ( ) , existingPath = _c . existingPath , newPath = _c . newPath ) ;
destinationPath = _b . sent ( ) ;
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.' ) ;
_d . label = 5 ;
_b . label = 5 ;
case 5 :
case 5 : return [ 2 /*return*/ , {
outputFileObj = args . inputFileObj ;
outputFileObj : destinationPath !== '' ? { _id : destinationPath } : args . inputFileObj ,
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 ,
} ] ;
} ] ;