1
0
Fork 0

ease the plex scan api and cache

add new radarr lookup
This commit is contained in:
xeviff 2023-05-05 20:36:58 +02:00
parent f206289dba
commit aa7c331728
6 changed files with 59 additions and 31 deletions

View File

@ -6,7 +6,7 @@
<groupId>tv.mangrana</groupId> <groupId>tv.mangrana</groupId>
<artifactId>mangrana-commons</artifactId> <artifactId>mangrana-commons</artifactId>
<version>3.1.5</version> <version>4.1.0</version>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>

View File

@ -32,7 +32,7 @@ public class PlexCommandLauncher {
public PlexCommandLauncher(CommonConfigFileLoader<?> config) { public PlexCommandLauncher(CommonConfigFileLoader<?> config) {
this.config = config; this.config = config;
this.logger = new EasyLogger(); this.logger = new EasyLogger();
this.sectionResolver = new PlexLibrarySectionsResolver(this, config); this.sectionResolver = new PlexLibrarySectionsResolver(this);
} }
// public static void main(String[] args) throws IncorrectWorkingReferencesException { // public static void main(String[] args) throws IncorrectWorkingReferencesException {
@ -40,28 +40,7 @@ public class PlexCommandLauncher {
// new PlexCommandLauncher(new CommonConfigFileLoader()).scanByPath(toRefresh); // new PlexCommandLauncher(new CommonConfigFileLoader()).scanByPath(toRefresh);
// } // }
public boolean scanSerieByPath(String fullDestinationPath) { boolean scanByPath(String plexPathToRefresh, String plexMountPath) {
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 ok = true; boolean ok = true;
String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh, plexMountPath); String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh, plexMountPath);
if (plexRefreshURL==null) return false; if (plexRefreshURL==null) return false;

View File

@ -16,23 +16,28 @@ import javax.xml.xpath.XPathFactory;
public class PlexLibrarySectionsResolver { public class PlexLibrarySectionsResolver {
private final PlexCommandLauncher commandLauncher; 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.commandLauncher = commandLauncher;
this.config = config; }
private void initSectionsIfNecessary() {
if (sectionsInfo==null) {
sectionsInfo = commandLauncher.retrieveSectionsInfo();
}
} }
public String resolveSectionByPath(String fullDestinationPath, String plexMountPath) { public String resolveSectionByPath(String fullDestinationPath, String plexMountPath) {
String keyFolder = fullDestinationPath.replaceFirst(plexMountPath,"").split("/")[1]; String keyFolder = fullDestinationPath.replaceFirst(plexMountPath,"").split("/")[1];
Document xmlDocument = commandLauncher.retrieveSectionsInfo(); initSectionsIfNecessary();
XPath xPath = XPathFactory.newInstance().newXPath(); XPath xPath = XPathFactory.newInstance().newXPath();
String startingLocationText = plexMountPath.concat("/").concat(keyFolder).concat("/"); String startingLocationText = plexMountPath.concat("/").concat(keyFolder).concat("/");
String directoryNodeOfLocation = getDirectoryKeyValue(xmlDocument, xPath, startingLocationText); String directoryNodeOfLocation = getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText);
if (directoryNodeOfLocation == null) { if (directoryNodeOfLocation == null) {
startingLocationText = plexMountPath.concat("/").concat(keyFolder); startingLocationText = plexMountPath.concat("/").concat(keyFolder);
Output.log("but going to retry with {0}", startingLocationText); Output.log("but going to retry with {0}", startingLocationText);
return getDirectoryKeyValue(xmlDocument, xPath, startingLocationText); return getDirectoryKeyValue(sectionsInfo, xPath, startingLocationText);
} else } else
return directoryNodeOfLocation; return directoryNodeOfLocation;
} }

View File

@ -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;
}
}
}

View File

@ -36,7 +36,6 @@ public interface RadarrAPIInterface extends APIInterface {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
List<MovieResource> movieLookupByTMDBid(@QueryParam("tmdbId") int tmdbId, @QueryParam("apikey") String apikey); List<MovieResource> movieLookupByTMDBid(@QueryParam("tmdbId") int tmdbId, @QueryParam("apikey") String apikey);
@POST @POST
@Path("/command") @Path("/command")
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@ -52,4 +51,8 @@ public interface RadarrAPIInterface extends APIInterface {
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
void relocateMovie(MovieResource movie, @PathParam("id") int movieId, @QueryParam("moveFiles") boolean moveFiles, @QueryParam("apikey") String apikey); 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<MovieResource> movieLookupByTitle(@QueryParam("term") String term, @QueryParam("apikey") String apikey);
} }

View File

@ -54,4 +54,7 @@ public class RadarrApiGateway {
proxy.relocateMovie(movie, movie.getId(), true, apiKey); proxy.relocateMovie(movie, movie.getId(), true, apiKey);
} }
public List<MovieResource> movieLookupByTitle (String title) {
return proxy.movieLookupByTitle(title, apiKey);
}
} }