refinements and bugfixes
This commit is contained in:
parent
21daae0340
commit
e719a8dd4f
2
pom.xml
2
pom.xml
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
<groupId>tv.mangrana</groupId>
|
<groupId>tv.mangrana</groupId>
|
||||||
<artifactId>mangrana-commons</artifactId>
|
<artifactId>mangrana-commons</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>3.1.3</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class LocalEnvironmentManager {
|
||||||
|
|
||||||
static LocalMode mode;
|
static LocalMode mode;
|
||||||
static {
|
static {
|
||||||
mode = LocalMode.PC;
|
mode = LocalMode.CONTABO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String PROJECT_ROOT = System.getProperty("user.dir");
|
public static final String PROJECT_ROOT = System.getProperty("user.dir");
|
||||||
|
@ -23,7 +23,7 @@ public class LocalEnvironmentManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRootPath() {
|
public static String getLocalRootPath() {
|
||||||
return mode.equals(LocalMode.PC) ? PROJECT_ROOT : REMOTE_ACCESS_FOLDER_FROM_MAC;
|
return mode.equals(LocalMode.PC) ? PROJECT_ROOT : REMOTE_ACCESS_FOLDER_FROM_MAC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,14 +77,13 @@ public class JobFileManager {
|
||||||
return addSubElement(jobsFolder, RESUME_FILE);
|
return addSubElement(jobsFolder, RESUME_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getJobsFolder() {
|
public static String getJobsFolder() {
|
||||||
return LocalEnvironmentManager.isLocal()
|
return LocalEnvironmentManager.isLocal()
|
||||||
? addSubElement(rootFolder(LocalEnvironmentManager.getRootPath()), getLocalJobsFolder())
|
? addSubElement(rootFolder(LocalEnvironmentManager.getLocalRootPath()), getLocalJobsFolderName())
|
||||||
: rootFolder(JOBS_FOLDER);
|
: rootFolder(JOBS_FOLDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String getLocalJobsFolderName() {
|
||||||
static String getLocalJobsFolder() {
|
|
||||||
return CONTABO.equals(getLocalMode())
|
return CONTABO.equals(getLocalMode())
|
||||||
? CONTABO_JOBS_FOLDER
|
? CONTABO_JOBS_FOLDER
|
||||||
: JOBS_FOLDER;
|
: JOBS_FOLDER;
|
||||||
|
|
|
@ -42,22 +42,28 @@ public class PlexCommandLauncher {
|
||||||
|
|
||||||
public boolean scanSerieByPath(String fullDestinationPath) {
|
public boolean scanSerieByPath(String fullDestinationPath) {
|
||||||
try {
|
try {
|
||||||
return scanByPath(getPlexSeriePath2Refresh(fullDestinationPath));
|
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) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean scanMovieByPath(String fullDestinationPath) {
|
public boolean scanMovieByPath(String fullDestinationPath) {
|
||||||
try {
|
try {
|
||||||
return scanByPath(getPlexMoviePath2Refresh(fullDestinationPath));
|
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) {
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean scanByPath(String plexPathToRefresh) {
|
private boolean scanByPath(String plexPathToRefresh, String plexMountPath) {
|
||||||
boolean ok = true;
|
boolean ok = true;
|
||||||
String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh);
|
String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh, plexMountPath);
|
||||||
if (plexRefreshURL==null) return false;
|
if (plexRefreshURL==null) return false;
|
||||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||||
|
|
||||||
|
@ -78,17 +84,6 @@ public class PlexCommandLauncher {
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPlexSeriePath2Refresh(String fullDestinationPath) {
|
|
||||||
String sonarrPathStarter = config.getConfig(SONARR_PATHS_STARTER);
|
|
||||||
String seriesPlexDockerPathStarter = config.getConfig(PLEX_SERIES_PATHS_STARTER);
|
|
||||||
return fullDestinationPath.replaceFirst(sonarrPathStarter, seriesPlexDockerPathStarter);
|
|
||||||
}
|
|
||||||
public String getPlexMoviePath2Refresh(String fullDestinationPath) {
|
|
||||||
String radarrPathStarter = config.getConfig(RADARR_PATHS_STARTER);
|
|
||||||
String moviesPlexDockerPathStarter = config.getConfig(PLEX_MOVIES_PATHS_STARTER);
|
|
||||||
return fullDestinationPath.replaceFirst(radarrPathStarter, moviesPlexDockerPathStarter);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Document retrieveSectionsInfo() {
|
public Document retrieveSectionsInfo() {
|
||||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||||
String plexSectionsURL = getPlexSectionsURL();
|
String plexSectionsURL = getPlexSectionsURL();
|
||||||
|
@ -118,9 +113,9 @@ public class PlexCommandLauncher {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPlexRefreshURL(String fullDestinationPath) {
|
private String getPlexRefreshURL(String fullDestinationPath, String plexMountPath) {
|
||||||
try {
|
try {
|
||||||
String sectionId = sectionResolver.resolveSectionByPath(fullDestinationPath);
|
String sectionId = sectionResolver.resolveSectionByPath(fullDestinationPath, plexMountPath);
|
||||||
if (sectionId==null) return null;
|
if (sectionId==null) return null;
|
||||||
String host = config.getConfig(PLEX_HOST);
|
String host = config.getConfig(PLEX_HOST);
|
||||||
String uriFormat = config.getConfig(PLEX_SECTION_REFRESH_URI);
|
String uriFormat = config.getConfig(PLEX_SECTION_REFRESH_URI);
|
||||||
|
|
|
@ -1,20 +1,18 @@
|
||||||
package tv.mangrana.plex.url;
|
package tv.mangrana.plex.url;
|
||||||
|
|
||||||
|
|
||||||
import tv.mangrana.config.CommonConfigFileLoader;
|
|
||||||
import tv.mangrana.utils.Output;
|
|
||||||
import com.sun.org.apache.xerces.internal.dom.DeferredElementImpl;
|
import com.sun.org.apache.xerces.internal.dom.DeferredElementImpl;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
import tv.mangrana.config.CommonConfigFileLoader;
|
||||||
|
import tv.mangrana.utils.Output;
|
||||||
|
|
||||||
import javax.xml.xpath.XPath;
|
import javax.xml.xpath.XPath;
|
||||||
import javax.xml.xpath.XPathConstants;
|
import javax.xml.xpath.XPathConstants;
|
||||||
import javax.xml.xpath.XPathExpressionException;
|
import javax.xml.xpath.XPathExpressionException;
|
||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
|
|
||||||
import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.PLEX_SERIES_PATHS_STARTER;
|
|
||||||
|
|
||||||
public class PlexLibrarySectionsResolver {
|
public class PlexLibrarySectionsResolver {
|
||||||
|
|
||||||
private final PlexCommandLauncher commandLauncher;
|
private final PlexCommandLauncher commandLauncher;
|
||||||
|
@ -25,15 +23,14 @@ public class PlexLibrarySectionsResolver {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String resolveSectionByPath(String fullDestinationPath) {
|
public String resolveSectionByPath(String fullDestinationPath, String plexMountPath) {
|
||||||
final String plexPathStarter = config.getConfig(PLEX_SERIES_PATHS_STARTER);
|
String keyFolder = fullDestinationPath.replaceFirst(plexMountPath,"").split("/")[1];
|
||||||
String keyFolder = fullDestinationPath.replaceFirst(plexPathStarter,"").split("/")[1];
|
|
||||||
Document xmlDocument = commandLauncher.retrieveSectionsInfo();
|
Document xmlDocument = commandLauncher.retrieveSectionsInfo();
|
||||||
XPath xPath = XPathFactory.newInstance().newXPath();
|
XPath xPath = XPathFactory.newInstance().newXPath();
|
||||||
String startingLocationText = plexPathStarter.concat("/").concat(keyFolder).concat("/");
|
String startingLocationText = plexMountPath.concat("/").concat(keyFolder).concat("/");
|
||||||
String directoryNodeOfLocation = getDirectoryKeyValue(xmlDocument, xPath, startingLocationText);
|
String directoryNodeOfLocation = getDirectoryKeyValue(xmlDocument, xPath, startingLocationText);
|
||||||
if (directoryNodeOfLocation == null) {
|
if (directoryNodeOfLocation == null) {
|
||||||
startingLocationText = plexPathStarter.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(xmlDocument, xPath, startingLocationText);
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class RefreshMoviesCommand {
|
public class RefreshMoviesCommand {
|
||||||
@JsonProperty("name")
|
@JsonProperty("name")
|
||||||
private final String name = "MoviesSearch";
|
private final String name = "RefreshMovie";
|
||||||
|
|
||||||
@JsonProperty("movieIds")
|
@JsonProperty("movieIds")
|
||||||
private final List<Integer> moviesIds;
|
private final List<Integer> moviesIds;
|
||||||
|
|
Loading…
Reference in New Issue