parent
f206289dba
commit
aa7c331728
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
|||
|
||||
<groupId>tv.mangrana</groupId>
|
||||
<artifactId>mangrana-commons</artifactId>
|
||||
<version>3.1.5</version>
|
||||
<version>4.1.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,7 +36,6 @@ public interface RadarrAPIInterface extends APIInterface {
|
|||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
List<MovieResource> 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<MovieResource> movieLookupByTitle(@QueryParam("term") String term, @QueryParam("apikey") String apikey);
|
||||
}
|
|
@ -54,4 +54,7 @@ public class RadarrApiGateway {
|
|||
proxy.relocateMovie(movie, movie.getId(), true, apiKey);
|
||||
}
|
||||
|
||||
public List<MovieResource> movieLookupByTitle (String title) {
|
||||
return proxy.movieLookupByTitle(title, apiKey);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue