1
0
Fork 0

refinements and bugfixes

This commit is contained in:
xeviff 2023-04-25 15:18:46 +02:00
parent 21daae0340
commit e719a8dd4f
6 changed files with 25 additions and 34 deletions

View File

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

View File

@ -9,7 +9,7 @@ public class LocalEnvironmentManager {
static LocalMode mode;
static {
mode = LocalMode.PC;
mode = LocalMode.CONTABO;
}
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;
}

View File

@ -77,14 +77,13 @@ public class JobFileManager {
return addSubElement(jobsFolder, RESUME_FILE);
}
private static String getJobsFolder() {
public static String getJobsFolder() {
return LocalEnvironmentManager.isLocal()
? addSubElement(rootFolder(LocalEnvironmentManager.getRootPath()), getLocalJobsFolder())
? addSubElement(rootFolder(LocalEnvironmentManager.getLocalRootPath()), getLocalJobsFolderName())
: rootFolder(JOBS_FOLDER);
}
static String getLocalJobsFolder() {
static String getLocalJobsFolderName() {
return CONTABO.equals(getLocalMode())
? CONTABO_JOBS_FOLDER
: JOBS_FOLDER;

View File

@ -42,22 +42,28 @@ public class PlexCommandLauncher {
public boolean scanSerieByPath(String fullDestinationPath) {
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) {
return false;
}
}
public boolean scanMovieByPath(String fullDestinationPath) {
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) {
return false;
}
}
private boolean scanByPath(String plexPathToRefresh) {
private boolean scanByPath(String plexPathToRefresh, String plexMountPath) {
boolean ok = true;
String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh);
String plexRefreshURL = getPlexRefreshURL(plexPathToRefresh, plexMountPath);
if (plexRefreshURL==null) return false;
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
@ -78,17 +84,6 @@ public class PlexCommandLauncher {
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() {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
String plexSectionsURL = getPlexSectionsURL();
@ -118,9 +113,9 @@ public class PlexCommandLauncher {
return null;
}
private String getPlexRefreshURL(String fullDestinationPath) {
private String getPlexRefreshURL(String fullDestinationPath, String plexMountPath) {
try {
String sectionId = sectionResolver.resolveSectionByPath(fullDestinationPath);
String sectionId = sectionResolver.resolveSectionByPath(fullDestinationPath, plexMountPath);
if (sectionId==null) return null;
String host = config.getConfig(PLEX_HOST);
String uriFormat = config.getConfig(PLEX_SECTION_REFRESH_URI);

View File

@ -1,20 +1,18 @@
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 org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import tv.mangrana.config.CommonConfigFileLoader;
import tv.mangrana.utils.Output;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import static tv.mangrana.config.CommonConfigFileLoader.CommonProjectConfiguration.PLEX_SERIES_PATHS_STARTER;
public class PlexLibrarySectionsResolver {
private final PlexCommandLauncher commandLauncher;
@ -25,15 +23,14 @@ public class PlexLibrarySectionsResolver {
this.config = config;
}
public String resolveSectionByPath(String fullDestinationPath) {
final String plexPathStarter = config.getConfig(PLEX_SERIES_PATHS_STARTER);
String keyFolder = fullDestinationPath.replaceFirst(plexPathStarter,"").split("/")[1];
public String resolveSectionByPath(String fullDestinationPath, String plexMountPath) {
String keyFolder = fullDestinationPath.replaceFirst(plexMountPath,"").split("/")[1];
Document xmlDocument = commandLauncher.retrieveSectionsInfo();
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);
if (directoryNodeOfLocation == null) {
startingLocationText = plexPathStarter.concat("/").concat(keyFolder);
startingLocationText = plexMountPath.concat("/").concat(keyFolder);
Output.log("but going to retry with {0}", startingLocationText);
return getDirectoryKeyValue(xmlDocument, xPath, startingLocationText);
} else

View File

@ -7,7 +7,7 @@ import java.util.List;
public class RefreshMoviesCommand {
@JsonProperty("name")
private final String name = "MoviesSearch";
private final String name = "RefreshMovie";
@JsonProperty("movieIds")
private final List<Integer> moviesIds;