Skip to content

Commit

Permalink
Merge pull request #22 from Feramance/Shared-Scripts-update
Browse files Browse the repository at this point in the history
Bug fix - Using folder name in path is ideal for cases of titles with special characters
  • Loading branch information
revenz authored May 30, 2024
2 parents d5982d0 + 2625110 commit 1644409
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
7 changes: 3 additions & 4 deletions Scripts/Flow/Applications/Radarr/Radarr - Rename.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Radarr } from 'Shared/Radarr';
/**
* This script will search the active queue and blocklist and research
* For use alongside this strategy https://fileflows.com/docs/guides/sonarr-radarr
* This script will send a rename command to Radarr
* @author Shaun Agius
* @version 1.0.0
* @revision 1
* @revision 2
* @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.folder.Name);
let movie = radarr.getMovieByPath(Variables.file.Name);
if (!movie)
return 2;
Logger.ILog(`Renaming ${movie.title}`);
Expand Down
9 changes: 5 additions & 4 deletions Scripts/Flow/Applications/Sonarr/Sonarr - Rename.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Sonarr } from 'Shared/Sonarr';
/**
* This script will search the active queue and blocklist and research
* For use alongside this strategy https://fileflows.com/docs/guides/sonarr-radarr
* This script will send a rename command to Sonarr
* @author Shaun Agius
* @version 1.0.0
* @revision 1
* @revision 2
* @param {string} URI Sonarr root URI and port (e.g. http://sonarr:1234)
* @param {string} ApiKey API Key
* @output Item renamed
* @output Item not found
*/
function Script(URI, ApiKey) {
let sonarr = new Sonarr(URI, ApiKey);
let series = sonarr.getShowByPath(Variables.folder.FullName);
let rx = /([A-Za-z\(\) [0-9]*\[tvdbid\-[0-9]*\])/g
let folder = rx.exec(Variables.folder.FullName)
let series = sonarr.getShowByPath(folder[1]);
if (!series)
return 2;
Logger.ILog(`Renaming ${series.title}`);
Expand Down
9 changes: 6 additions & 3 deletions Scripts/Shared/Radarr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// path: Scripts/Shared/Radarr.js

/**
* Class that interacts with Radarr
* @name Radarr
* @revision 2
* @revision 3
* @minimumVersion 1.0.0.0
*/
export class Radarr
Expand Down Expand Up @@ -59,10 +61,11 @@ export class Radarr
let cp = path.toLowerCase();
let movie = movies.filter(x =>
{
let mp = x.movieFile?.path;
let mp = x.movieFile?.relativePath.split('.')[0].toLowerCase();
if (!mp)
return false;
return cp.includes(x.title.toLowerCase());
Logger.ILog('Checking path: ' + mp);
return mp.includes(cp.split('.')[0]);
});
if (movie?.length)
{
Expand Down
12 changes: 7 additions & 5 deletions Scripts/Shared/Sonarr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// path: Scripts/Shared/Sonarr.js

/**
* Class that interacts with Sonarr
* @name Sonarr
* @revision 2
* @revision 3
* @minimumVersion 1.0.0.0
*/
export class Sonarr
Expand Down Expand Up @@ -83,10 +85,10 @@ export class Sonarr
let cp = path.toString().toLowerCase();
let show = shows.filter(x =>
{
let sp = x.path;
let sp = x.path.toLowerCase();
if (!sp)
return false;
return cp.includes(x.title.toLowerCase());
return sp.includes(path);
});
if (show?.length)
{
Expand Down Expand Up @@ -146,10 +148,10 @@ export class Sonarr
let cp = path.toString().toLowerCase();
let showfile = files.filter(x =>
{
let sp = x.path;
let sp = x.path.toLowerCase();
if (!sp)
return false;
return cp.includes(x.title.toLowerCase());
return sp.includes(path);
});
if (showfile?.length)
{
Expand Down

0 comments on commit 1644409

Please sign in to comment.