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 boolean dryRun = true;
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 videoPath = "D:\\Toolbox\\Movies\\";
@@ -37,15 +41,17 @@ public class CropAssetCopyTool {
private CsvParserSettings parserSettings = new CsvParserSettings();
private List<String[]> inputRows;
public CropAssetCopyTool() throws ZipException, IOException {
public CropAssetCopyTool() throws IOException {
readToolboxExport();
int lineNo = 0;
int noFile = 0;
int noContent = 0;
int wrongSize = 0;
int video = 0;
int videosExtracted = 0;
int videosZipped = 0;
int zipCorrupt = 0;
for (String[] line : inputRows) {
lineNo++;
@@ -63,43 +69,57 @@ public class CropAssetCopyTool {
if (fileLength < 1) {
noContent++;
log.warn("Skipping '" + filePath + "' (AssetID " + assetId + "), no content");
// TODO update spreadsheet?
}
else if (expectedSize != fileLength) {
File videoFile = new File(videoPath + assetId + ".zip");
if (videoFile.exists()) {
ZipFile zipFile = new ZipFile(videoFile.getAbsolutePath());
@SuppressWarnings("rawtypes")
List fileList = zipFile.getFileHeaders();
ZipFile zipFile;
try {
zipFile = new ZipFile(videoFile.getAbsolutePath());
if (fileList.size() == 1) {
log.info("Extracting " + videoFile.getAbsolutePath());
// zipFile.extractAll(videoTargetPath);
//
// FileHeader header = (FileHeader) fileList.get(0);
// File srcFile = new File(videoTargetPath + "\\" + header.getFileName());
// File destFile = new File(videoTargetPath + "\\" + targetName);
// log.info("AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath());
//
// FileUtils.moveFile(srcFile, destFile);
@SuppressWarnings("rawtypes")
List fileList = zipFile.getFileHeaders();
videosExtracted++;
if (fileList.size() == 1) {
log.info("Extracting " + videoFile.getAbsolutePath());
if (!dryRun) {
zipFile.extractAll(videoTargetPath);
FileHeader header = (FileHeader) fileList.get(0);
File srcFile = new File(videoTargetPath + "\\" + header.getFileName());
File destFile = new File(videoTargetPath + "\\" + targetName);
log.info("AssetID " + assetId + ": Moving " + srcFile.getAbsolutePath() + " to " + destFile.getAbsolutePath());
FileUtils.moveFile(srcFile, destFile);
}
videosExtracted++;
}
else {
log.info("Copy " + videoFile.getAbsolutePath() + " as ZIP");
if (!dryRun)
FileUtils.copyFileToDirectory(videoFile, videoTargetDir);
// TODO update spreadsheet
videosZipped++;
}
video++;
} catch (ZipException e) {
log.error("Skipping AssetID " + assetId + " - could not open ZIP file " + videoFile.getAbsolutePath());
}
else {
log.info("Copy " + videoFile.getAbsolutePath() + " as ZIP");
// FileUtils.copyFileToDirectory(videoFile, videoTargetDir);
// TODO update spreadsheet
videosZipped++;
}
video++;
}
else {
wrongSize++;
log.warn("Wrong file size for " + assetId + ": " + expectedSize + " != " + fileLength + " (" + targetName + ")");
zipCorrupt++;
}
}
else {
@@ -108,17 +128,20 @@ public class CropAssetCopyTool {
}
}
else {
log.error("'" + filePath + "' is not a file");
log.error("'" + filePath + "' not found");
noFile++;
}
}
log.info("Lines processed: " + lineNo);
log.info("Skipped: File not found: " + noFile);
log.info("Skipped: No content: " + noContent);
log.info("Wrong size: " + wrongSize);
log.info("Videos: " + video);
log.info(" Extracted: " + videosExtracted);
log.info(" Zipped: " + videosZipped);
log.info(" Corrupt: " + zipCorrupt);
// copy files by ID