From: vasary.daniel Date: Thu, 29 Jul 2021 19:00:22 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=79e62bebf3b40d14b80e702a548f8db0232314c3;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32287 --- diff --git a/server/user.jobengine.executors/src/user/jobengine/server/steps/shared/PBQuery.java b/server/user.jobengine.executors/src/user/jobengine/server/steps/shared/PBQuery.java index a550521c..2b50e30d 100644 --- a/server/user.jobengine.executors/src/user/jobengine/server/steps/shared/PBQuery.java +++ b/server/user.jobengine.executors/src/user/jobengine/server/steps/shared/PBQuery.java @@ -5,16 +5,23 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringReader; import java.net.URL; +import java.nio.file.CopyOption; +import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import javax.xml.parsers.DocumentBuilder; @@ -71,6 +78,10 @@ public class PBQuery { public static final String GETMEDIAUSAGEBYUTRANGE = "/getMediaUsageByUTRange"; public static final String GETCUSTOMVIEW = "/getCustomView"; + private static final Path subtitleRoot = Paths.get("X:\\PB_ARCH"); + private static final Path missingSubsRoot = Paths.get("R:\\BeachPool"); + private Set subsDirectoriesList; + private static Document toDocument(String xml) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; @@ -137,6 +148,7 @@ public class PBQuery { this.secondaryUserName = secondaryUserName; this.secondaryPassword = secondaryPassword; this.rangeForwardHours = rangeForwardHours; + this.subsDirectoriesList = readSubtileDirectoriesList(subtitleRoot); } private void putEarliest(Map result, String mediaName, String usageTime) { @@ -306,8 +318,17 @@ public class PBQuery { if (StringUtils.isBlank(mediaName)) continue; - if (!StringUtils.equals("Subtitle", mediaType)) - logger.info(subtitleMarker, "querySortableMedias: {}", mediaName); + if (StringUtils.equals("Subtitle", mediaType)) { + logger.info(this.subtitleMarker, "Missing subtitle: {}", mediaName); + + try { + this.copyMissingSubtitle(mediaName + ".stl"); + } catch (Exception e) { + logger.error(this.subtitleMarker, e.getMessage()); + } + + continue; + } if (!StringUtils.equals("Video", mediaType)) continue; @@ -339,4 +360,54 @@ public class PBQuery { return result; } + private Set readSubtileDirectoriesList(Path root) { + Set result = new HashSet<>(); + DirectoryStream stream = null; + try { + stream = Files.newDirectoryStream(Paths.get(root.toString())); + Iterator dirIterator = stream.iterator(); + + while (dirIterator.hasNext()) { + Path path = dirIterator.next(); + if (Files.isDirectory(path)) { + result.add(path); + logger.info(this.subtitleMarker, "Detected subtitle root {}", path); + } + } + } catch (Exception e) { + logger.error(this.subtitleMarker, e.getMessage()); + } finally { + try { + if (stream != null) + stream.close(); + } catch (IOException e) { + } + + } + return result; + } + + private void copyMissingSubtitle(String subtitleName) throws Exception { + boolean found = false; + for (Path subtitleDir : this.subsDirectoriesList) { + Path source = Paths.get(subtitleDir.toString(), new String[] { subtitleName }); + if (source.toFile().exists()) { + found = true; + logger.info(this.subtitleMarker, "Found missing {}", source); + Path target = Paths.get(missingSubsRoot.toString(), new String[] { subtitleName }); + if (target.toFile().exists()) + logger.info(this.subtitleMarker, "Missing subtitle {} already exists, overriding", target); + Files.copy(source, target, new CopyOption[] { StandardCopyOption.REPLACE_EXISTING }); + boolean isContentEquals = Arrays.equals(Files.readAllBytes(source), Files.readAllBytes(target)); + if (isContentEquals) { + logger.info(this.subtitleMarker, "Successfully copied {}", target); + break; + } + logger.error(this.subtitleMarker, "Source {} and target {} content are not equals", source, target); + break; + } + } + if (!found) + logger.warn(this.subtitleMarker, "Can't find missing {}", subtitleName); + } }