CropAssetCopyTool

This commit is contained in:
gexce
2017-08-17 13:27:06 +02:00
parent 31e365af05
commit 907ccf3643
@@ -24,6 +24,10 @@ public class CropAssetCopyTool {
private static Logger log = Logger.getLogger(CropAssetCopyTool.class); private static Logger log = Logger.getLogger(CropAssetCopyTool.class);
private static boolean dryRun = true;
private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15.csv"; private static String toolboxExportFilePath = "C:\\Temp\\Migration CS - SQL Server\\export-2017-08-15.csv";
private static String assetPath = "D:\\Toolbox\\Assets"; private static String assetPath = "D:\\Toolbox\\Assets";
private static String videoPath = "D:\\Toolbox\\Movies\\"; private static String videoPath = "D:\\Toolbox\\Movies\\";
@@ -37,15 +41,17 @@ public class CropAssetCopyTool {
private CsvParserSettings parserSettings = new CsvParserSettings(); private CsvParserSettings parserSettings = new CsvParserSettings();
private List<String[]> inputRows; private List<String[]> inputRows;
public CropAssetCopyTool() throws ZipException, IOException { public CropAssetCopyTool() throws IOException {
readToolboxExport(); readToolboxExport();
int lineNo = 0; int lineNo = 0;
int noFile = 0;
int noContent = 0; int noContent = 0;
int wrongSize = 0; int wrongSize = 0;
int video = 0; int video = 0;
int videosExtracted = 0; int videosExtracted = 0;
int videosZipped = 0; int videosZipped = 0;
int zipCorrupt = 0;
for (String[] line : inputRows) { for (String[] line : inputRows) {
lineNo++; lineNo++;
@@ -63,32 +69,41 @@ public class CropAssetCopyTool {
if (fileLength < 1) { if (fileLength < 1) {
noContent++; noContent++;
log.warn("Skipping '" + filePath + "' (AssetID " + assetId + "), no content"); log.warn("Skipping '" + filePath + "' (AssetID " + assetId + "), no content");
// TODO update spreadsheet?
} }
else if (expectedSize != fileLength) { else if (expectedSize != fileLength) {
File videoFile = new File(videoPath + assetId + ".zip"); File videoFile = new File(videoPath + assetId + ".zip");
if (videoFile.exists()) { if (videoFile.exists()) {
ZipFile zipFile = new ZipFile(videoFile.getAbsolutePath());
ZipFile zipFile;
try {
zipFile = new ZipFile(videoFile.getAbsolutePath());
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
List fileList = zipFile.getFileHeaders(); List fileList = zipFile.getFileHeaders();
if (fileList.size() == 1) { if (fileList.size() == 1) {
log.info("Extracting " + videoFile.getAbsolutePath()); log.info("Extracting " + videoFile.getAbsolutePath());
// zipFile.extractAll(videoTargetPath);
// if (!dryRun) {
// FileHeader header = (FileHeader) fileList.get(0); zipFile.extractAll(videoTargetPath);
// File srcFile = new File(videoTargetPath + "\\" + header.getFileName());
// File destFile = new File(videoTargetPath + "\\" + targetName); FileHeader header = (FileHeader) fileList.get(0);
// log.info("AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath()); File srcFile = new File(videoTargetPath + "\\" + header.getFileName());
// File destFile = new File(videoTargetPath + "\\" + targetName);
// FileUtils.moveFile(srcFile, destFile); log.info("AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath());
FileUtils.moveFile(srcFile, destFile);
}
videosExtracted++; videosExtracted++;
} }
else { else {
log.info("Copy " + videoFile.getAbsolutePath() + " as ZIP"); log.info("Copy " + videoFile.getAbsolutePath() + " as ZIP");
// FileUtils.copyFileToDirectory(videoFile, videoTargetDir); if (!dryRun)
FileUtils.copyFileToDirectory(videoFile, videoTargetDir);
// TODO update spreadsheet // TODO update spreadsheet
@@ -96,10 +111,15 @@ public class CropAssetCopyTool {
} }
video++; video++;
} catch (ZipException e) {
log.error("Skipping AssetID " + assetId + " - could not open ZIP file " + videoFile.getAbsolutePath());
}
} }
else { else {
wrongSize++; wrongSize++;
log.warn("Wrong file size for " + assetId + ": " + expectedSize + " != " + fileLength + " (" + targetName + ")"); log.warn("Wrong file size for " + assetId + ": " + expectedSize + " != " + fileLength + " (" + targetName + ")");
zipCorrupt++;
} }
} }
else { else {
@@ -108,17 +128,20 @@ public class CropAssetCopyTool {
} }
} }
else { else {
log.error("'" + filePath + "' is not a file"); log.error("'" + filePath + "' not found");
noFile++;
} }
} }
log.info("Lines processed: " + lineNo); log.info("Lines processed: " + lineNo);
log.info("Skipped: File not found: " + noFile);
log.info("Skipped: No content: " + noContent); log.info("Skipped: No content: " + noContent);
log.info("Wrong size: " + wrongSize); log.info("Wrong size: " + wrongSize);
log.info("Videos: " + video); log.info("Videos: " + video);
log.info(" Extracted: " + videosExtracted); log.info(" Extracted: " + videosExtracted);
log.info(" Zipped: " + videosZipped); log.info(" Zipped: " + videosZipped);
log.info(" Corrupt: " + zipCorrupt);
// copy files by ID // copy files by ID