CropAssetCopyTool: extract all videos

This commit is contained in:
gexce
2017-08-17 17:29:23 +02:00
parent 129e1bbe87
commit 253d3fd8f1
@@ -6,7 +6,6 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.io.FileExistsException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
@@ -57,6 +56,9 @@ public class CropAssetCopyTool {
if (dryRun)
log.info("This is a dry run. No files are copied.");
if (skipLines > 0)
log.info("Skipping first " + skipLines + " lines");
readToolboxExport();
@@ -107,8 +109,7 @@ public class CropAssetCopyTool {
try {
zipFile = new ZipFile(videoFile.getAbsolutePath());
@SuppressWarnings("rawtypes")
List fileList = zipFile.getFileHeaders();
List<FileHeader> fileList = (List<FileHeader>) zipFile.getFileHeaders();
if (fileList.size() == 1) {
log.debug("Extracting " + videoFile.getAbsolutePath());
@@ -127,26 +128,21 @@ public class CropAssetCopyTool {
videosExtracted++;
}
else {
// XXX instead of copying the ZIP, extract only the video and link to the releases
log.info("Copy " + videoFile.getAbsolutePath() + " as ZIP");
if (!dryRun) {
File targetFile = FileUtils.getFile(videoTargetDir, videoFile.getName());
if (targetFile.exists())
throw new FileExistsException(targetFile);
FileUtils.copyFileToDirectory(videoFile, videoTargetDir);
for (FileHeader header : fileList) {
if (header.getFileName().indexOf('/') < 0) {
if (!dryRun)
zipFile.extractFile(header, videoTargetPath);
videosExtracted++;
break;
}
}
line[1] = videoFile.getName();
videosZipped++;
}
video++;
} catch (ZipException e) {
zipCorrupt++;
log.error("Skipping AssetID " + assetId + " - could not open ZIP file " + videoFile.getAbsolutePath());
log.error("Skipping line " + lineNo + ", AssetID " + assetId + " - could not open ZIP file " + videoFile.getAbsolutePath());
linesForDeletion.add(line);
}
}
@@ -181,17 +177,17 @@ public class CropAssetCopyTool {
if (!dryRun) {
try {
FileUtils.copyFile(file, targetFile);
FileUtils.copyFile(file, targetFile, false);
}
catch (IOException ioe) {
log.error("IOException: '" + ioe.getMessage() + "'");
log.error("Line " + lineNo + ", AssetID " + assetId + " - IOException: '" + ioe.getMessage() + "'");
ioe.printStackTrace();
}
}
}
}
else {
log.error("'" + filePath + "' not found");
log.error("Line " + lineNo + ", AssetID " + assetId + " - '" + filePath + "' not found");
noFile++;
}
}
@@ -244,7 +240,6 @@ public class CropAssetCopyTool {
}
public static void main(String[] args) {
try {
Layout layout = new PatternLayout("%d{ISO8601} - %p %m%n"); // "%d{ISO8601} - %p %m%n"
BasicConfigurator.configure(new ConsoleAppender(layout));