Skip to content

Commit

Permalink
Merge pull request #23 from Feramance/Shared-Scripts-update
Browse files Browse the repository at this point in the history
Final update - this should ensure backwards compatibility and allow for search by path or file name
  • Loading branch information
revenz authored May 31, 2024
2 parents 8ef8cb8 + bd1bc76 commit 0bee3cb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Scripts/Flow/Applications/Radarr/Radarr - Rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Radarr } from 'Shared/Radarr';
* This script will send a rename command to Radarr
* @author Shaun Agius
* @version 1.0.0
* @revision 2
* @revision 3
* @param {string} URI Radarr root URI and port (e.g. http://radarr:1234)
* @param {string} ApiKey API Key
* @output Item renamed
* @output Item not found
*/
function Script(URI, ApiKey) {
let radarr = new Radarr(URI, ApiKey);
let movie = radarr.getMovieByPath(Variables.file.Name);
let movie = radarr.getMovieByFile(Variables.file.Name);
if (!movie)
return 2;
Logger.ILog(`Renaming ${movie.title}`);
Expand Down
45 changes: 39 additions & 6 deletions Scripts/Shared/Radarr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Class that interacts with Radarr
* @name Radarr
* @revision 3
* @revision 4
* @minimumVersion 1.0.0.0
*/
export class Radarr
Expand Down Expand Up @@ -43,8 +43,42 @@ export class Radarr
}

/**
* Gets a movie from Radarr by its full path
* @param {string} path the full path of the movie to lookup
* Gets a movie from Radarr by its file name
* @param {string} file the file name of the movie to lookup
* @returns {object} a movie object if found, otherwise null
*/
getMovieByFile(file)
{
if (!file)
{
Logger.WLog('No file name passed in to find movie');
return null;
}
let movies = this.fetchJson('movie');
if (!movies?.length)
return null;

let cp = file.toLowerCase();
let movie = movies.filter(x =>
{
let mp = x.movieFile?.relativePath;
if (!mp)
return false;
return mp.split('.')[0].toLowerCase().includes(cp.split('.')[0]);
});
if (movie?.length)
{
movie = movie[0];
Logger.ILog('Found movie: ' + movie.title);
return movie;
}
Logger.WLog('Unable to find movie file name: ' + file);
return null;
}

/**
* Gets a movie from Radarr by its path
* @param {string} path the path of the movie to lookup
* @returns {object} a movie object if found, otherwise null
*/
getMovieByPath(path)
Expand All @@ -61,11 +95,10 @@ export class Radarr
let cp = path.toLowerCase();
let movie = movies.filter(x =>
{
let mp = x.movieFile?.relativePath.split('.')[0].toLowerCase();
let mp = x.movieFile?.path;
if (!mp)
return false;
Logger.ILog('Checking path: ' + mp);
return mp.includes(cp.split('.')[0]);
return mp.toLowerCase().includes(cp);
});
if (movie?.length)
{
Expand Down

0 comments on commit 0bee3cb

Please sign in to comment.