diff --git a/pom.xml b/pom.xml
index 601258a..98400a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
tv.mangrana
mangrana-commons
- 3.1.5
+ 4.1.0
8
diff --git a/src/main/java/tv/mangrana/plex/url/PlexCommandLauncher.java b/src/main/java/tv/mangrana/plex/url/PlexCommandLauncher.java
index c3a166d..9f149fd 100644
--- a/src/main/java/tv/mangrana/plex/url/PlexCommandLauncher.java
+++ b/src/main/java/tv/mangrana/plex/url/PlexCommandLauncher.java
@@ -32,7 +32,7 @@ public class PlexCommandLauncher {
public PlexCommandLauncher(CommonConfigFileLoader> config) {
this.config = config;
this.logger = new EasyLogger();
- this.sectionResolver = new PlexLibrarySectionsResolver(this, config);
+ this.sectionResolver = new PlexLibrarySectionsResolver(this);
}
// public static void main(String[] args) throws IncorrectWorkingReferencesException {
@@ -40,28 +40,7 @@ public class PlexCommandLauncher {
// new PlexCommandLauncher(new CommonConfigFileLoader()).scanByPath(toRefresh);
// }
- public boolean scanSerieByPath(String fullDestinationPath) {
- try {
- String sonarrPathStarter = config.getConfig(SONARR_PATHS_STARTER);
- String plexMountPath = config.getConfig(PLEX_SERIES_PATHS_STARTER);
- String path2Refresh = fullDestinationPath.replaceFirst(sonarrPathStarter, plexMountPath);
- return scanByPath(path2Refresh, plexMountPath);
- } catch (Exception e) {
- return false;
- }
- }
- public boolean scanMovieByPath(String fullDestinationPath) {
- try {
- String radarrPathStarter = config.getConfig(RADARR_PATHS_STARTER);
- String plexMountPath = config.getConfig(PLEX_MOVIES_PATHS_STARTER);
- String pathToRefresh = fullDestinationPath.replaceFirst(radarrPathStarter, plexMountPath);
- return scanByPath(pathToRefresh, plexMountPath);
- } catch (Exception e) {
- return false;
- }
- }
-
- private boolean scanByPath(String plexPathToRefresh, String plexMountPath) {
+ boolean scanByPath(String plexPathToRefresh, String plexMountPath) {
boolean ok = true;
String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh, plexMountPath);
if (plexRefreshURL==null) return false;
diff --git a/src/main/java/tv/mangrana/plex/url/PlexLibrarySectionsResolver.java b/src/main/java/tv/mangrana/plex/url/PlexLibrarySectionsResolver.java
index f035496..737405f 100644
--- a/src/main/java/tv/mangrana/plex/url/PlexLibrarySectionsResolver.java
+++ b/src/main/java/tv/mangrana/plex/url/PlexLibrarySectionsResolver.java
@@ -16,23 +16,28 @@ import javax.xml.xpath.XPathFactory;
public class PlexLibrarySectionsResolver {
private final PlexCommandLauncher commandLauncher;
- private final CommonConfigFileLoader> config;
+ private Document sectionsInfo;
- public PlexLibrarySectionsResolver(PlexCommandLauncher commandLauncher, CommonConfigFileLoader> config) {
+ public PlexLibrarySectionsResolver(PlexCommandLauncher commandLauncher) {
this.commandLauncher = commandLauncher;
- this.config = config;
+ }
+
+ private void initSectionsIfNecessary() {
+ if (sectionsInfo==null) {
+ sectionsInfo = commandLauncher.retrieveSectionsInfo();
+ }
}
public String resolveSectionByPath(String fullDestinationPath, String plexMountPath) {
String keyFolder = fullDestinationPath.replaceFirst(plexMountPath,"").split("/")[1];
- Document xmlDocument = commandLauncher.retrieveSectionsInfo();
+ initSectionsIfNecessary();
XPath xPath = XPathFactory.newInstance().newXPath();
String startingLocationText = plexMountPath.concat("/").concat(keyFolder).concat("/");
- String directoryNodeOfLocation = getDirectoryKeyValue(xmlDocument, xPath, startingLocationText);
+ String directoryNodeOfLocation = getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText);
if (directoryNodeOfLocation == null) {
startingLocationText = plexMountPath.concat("/").concat(keyFolder);
Output.log("but going to retry with {0}", startingLocationText);
- return getDirectoryKeyValue(xmlDocument, xPath, startingLocationText);
+ return getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText);
} else
return directoryNodeOfLocation;
}
diff --git a/src/main/java/tv/mangrana/plex/url/PlexRefresher.java b/src/main/java/tv/mangrana/plex/url/PlexRefresher.java
new file mode 100644
index 0000000..9f7d960
--- /dev/null
+++ b/src/main/java/tv/mangrana/plex/url/PlexRefresher.java
@@ -0,0 +1,38 @@
+package tv.mangrana.plex.url;
+
+import tv.mangrana.config.CommonConfigFileLoader;
+
+import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.*;
+
+public class PlexRefresher {
+
+ private final PlexCommandLauncher commandLauncher;
+ private final CommonConfigFileLoader> config;
+
+ public PlexRefresher(CommonConfigFileLoader> config) {
+ this.commandLauncher = new PlexCommandLauncher(config);
+ this.config = config;
+ }
+
+ public boolean scanSerieByPath(String fullDestinationPath) {
+ try {
+ String sonarrPathStarter = config.getConfig(SONARR_PATHS_STARTER);
+ String plexMountPath = config.getConfig(PLEX_SERIES_PATHS_STARTER);
+ String path2Refresh = fullDestinationPath.replaceFirst(sonarrPathStarter, plexMountPath);
+ return commandLauncher.scanByPath(path2Refresh, plexMountPath);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public boolean scanMovieByPath(String fullDestinationPath) {
+ try {
+ String radarrPathStarter = config.getConfig(RADARR_PATHS_STARTER);
+ String plexMountPath = config.getConfig(PLEX_MOVIES_PATHS_STARTER);
+ String pathToRefresh = fullDestinationPath.replaceFirst(radarrPathStarter, plexMountPath);
+ return commandLauncher.scanByPath(pathToRefresh, plexMountPath);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+}
diff --git a/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrAPIInterface.java b/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrAPIInterface.java
index 14efdd0..7946609 100644
--- a/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrAPIInterface.java
+++ b/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrAPIInterface.java
@@ -36,7 +36,6 @@ public interface RadarrAPIInterface extends APIInterface {
@Produces({ MediaType.APPLICATION_JSON })
List movieLookupByTMDBid(@QueryParam("tmdbId") int tmdbId, @QueryParam("apikey") String apikey);
-
@POST
@Path("/command")
@Consumes({ MediaType.APPLICATION_JSON })
@@ -52,4 +51,8 @@ public interface RadarrAPIInterface extends APIInterface {
@Consumes({ MediaType.APPLICATION_JSON })
void relocateMovie(MovieResource movie, @PathParam("id") int movieId, @QueryParam("moveFiles") boolean moveFiles, @QueryParam("apikey") String apikey);
+ @GET
+ @Path("/movie/lookup")
+ @Produces({ MediaType.APPLICATION_JSON })
+ List movieLookupByTitle(@QueryParam("term") String term, @QueryParam("apikey") String apikey);
}
\ No newline at end of file
diff --git a/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrApiGateway.java b/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrApiGateway.java
index f1ace0b..110eb32 100644
--- a/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrApiGateway.java
+++ b/src/main/java/tv/mangrana/radarr/api/client/gateway/RadarrApiGateway.java
@@ -54,4 +54,7 @@ public class RadarrApiGateway {
proxy.relocateMovie(movie, movie.getId(), true, apiKey);
}
+ public List movieLookupByTitle (String title) {
+ return proxy.movieLookupByTitle(title, apiKey);
+ }
}