Skip to content

Commit

Permalink
Merge pull request #665 from NASA-PDS/issue_664
Browse files Browse the repository at this point in the history
Add product metadata check audio/video files
  • Loading branch information
jordanpadams committed Jun 26, 2023
2 parents 18852e1 + 284f6ac commit 17a9a64
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ POSSIBILITY OF SUCH DAMAGE.
<artifactId>opensearch-rest-high-level-client</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.mp4parser</groupId>
<artifactId>isoparser</artifactId>
<version>1.9.56</version>
</dependency>
</dependencies>

<!-- Inherit from parent -->
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/gov/nasa/pds/tools/validate/ProblemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ public enum ProblemType {

UNLABELED_FILE("warning.file.not_referenced_in_label"),

NON_JPEG_FILE("warning.file.not_jpeg_compliant"),
NOT_MP4_FILE("error.file.not_mp4_m4a_compliant"),

NON_PNG_FILE("warning.file.not_png_compliant"),
NON_JPEG_FILE("error.file.not_jpeg_compliant"),

NON_PNG_FILE("error.file.not_png_compliant"),

NON_HTML_FILE("warning.file.not_html_mimetype"),

Expand Down
61 changes: 61 additions & 0 deletions src/main/java/gov/nasa/pds/tools/validate/content/AudioVideo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package gov.nasa.pds.tools.validate.content;

import gov.nasa.pds.tools.label.ExceptionType;
import gov.nasa.pds.tools.validate.ProblemDefinition;
import gov.nasa.pds.tools.validate.ProblemListener;
import gov.nasa.pds.tools.validate.ProblemType;
import gov.nasa.pds.tools.validate.ValidationProblem;
import gov.nasa.pds.tools.validate.ValidationTarget;
import java.net.URL;
import org.apache.commons.io.FilenameUtils;
import org.mp4parser.IsoFile;
import org.mp4parser.boxes.iso14496.part12.MovieBox;
import org.mp4parser.boxes.iso14496.part12.TrackBox;

public class AudioVideo {
final private ProblemListener listener;
final private URL urlRef;
final private ValidationTarget target;
public AudioVideo (ProblemListener listener, ValidationTarget target, URL urlRef) {
this.listener = listener;
this.target = target;
this.urlRef = urlRef;
}
public void checkMetadata (boolean audio, boolean video) {
try {
boolean a = false,v = false;
IsoFile content = new IsoFile(this.urlRef.getPath());
MovieBox movie = content.getMovieBox();
if (movie == null) {
this.listener.addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.ERROR, ProblemType.NOT_MP4_FILE,
"Does not look like an MP4/M4A because no boxes found within: " + urlRef.toString()),
target));
} else {
for (TrackBox track : movie.getBoxes(TrackBox.class)) {
a |= "soun".equals(track.getMediaBox().getHandlerBox().getHandlerType());
v |= "vide".equals(track.getMediaBox().getHandlerBox().getHandlerType());
}
}
content.close();
if (a != audio) {
this.listener.addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.ERROR, ProblemType.NOT_MP4_FILE,
"Does not look like an MP4/M4A because expected audio but found none: " + urlRef.toString()),
target));
}
if (v != video) {
this.listener.addProblem(new ValidationProblem(
new ProblemDefinition(ExceptionType.ERROR, ProblemType.NOT_MP4_FILE,
"Does not look like an MP4/M4A because expected video but found none: " + urlRef.toString()),
target));
}
} catch (Exception e) {
ProblemDefinition def =
new ProblemDefinition(ExceptionType.ERROR, ProblemType.INTERNAL_ERROR,
"Error occurred while processing MP4/M4A file content for "
+ FilenameUtils.getName(urlRef.toString()) + ": " + e.getMessage());
this.listener.addProblem(new ValidationProblem(def, this.target));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import gov.nasa.pds.tools.validate.ProblemType;
import gov.nasa.pds.tools.validate.ValidationProblem;
import gov.nasa.pds.tools.validate.ValidationTarget;
import gov.nasa.pds.tools.validate.content.AudioVideo;
import gov.nasa.pds.tools.validate.rule.AbstractValidationRule;
import gov.nasa.pds.tools.validate.rule.ValidationTest;
import net.sf.saxon.om.DocumentInfo;
Expand Down Expand Up @@ -270,6 +271,9 @@ private boolean validate(DocumentInfo xml) {
}
if ("encoding_standard_id".equals(child.getLocalPart())) {
encodingStandardId = child.getStringValue();
if (this.fileMapping.get(name).equals("")) {
this.fileMapping.put (name, encodingStandardId);
}
}
if ("file_name".equals(child.getLocalPart())) {
name = child.getStringValue();
Expand Down Expand Up @@ -459,6 +463,12 @@ private boolean validateFileAreaDefinitionAndContent(String fileName, TinyNodeIm
.addProblem(new ValidationProblem(def, target, fileObject.getLineNumber(), -1));
return false;
}
} else if (doctype.equalsIgnoreCase("MP4/H.264/AAC")){
new AudioVideo(this.getListener(), target, urlRef).checkMetadata (true, true);
} else if (doctype.equalsIgnoreCase("MP4/H.264")){
new AudioVideo(this.getListener(), target, urlRef).checkMetadata (false, true);
} else if (doctype.equalsIgnoreCase("M4A/AAC") || doctype.equalsIgnoreCase("WAV")){
new AudioVideo(this.getListener(), target, urlRef).checkMetadata (true, false);
} else if (!doctype.equalsIgnoreCase("UTF-8 Text")
&& !doctype.equalsIgnoreCase("7-Bit ASCII Text")
&& !doctype.equalsIgnoreCase("Rich Text")) {
Expand Down Expand Up @@ -798,7 +808,7 @@ private void handleJPEG(ValidationTarget target, URL fileRef, TinyNodeImpl fileO
urlRef = new URL(parent, jpegName);
}
LOG.error("handleJPEG:" + urlRef.toString() + " is not valid JPEG file");
ProblemDefinition def = new ProblemDefinition(ExceptionType.WARNING,
ProblemDefinition def = new ProblemDefinition(ExceptionType.ERROR,
ProblemType.NON_JPEG_FILE, urlRef.toString() + " is not valid JPEG file");
getListener().addProblem(new ValidationProblem(def, target, lineNumber, -1));
}
Expand Down Expand Up @@ -842,7 +852,7 @@ private void handlePNG(ValidationTarget target, URL fileRef, TinyNodeImpl fileOb
urlRef = new URL(parent, pngName);
}
LOG.error("handlePNG:" + urlRef.toString() + " is not valid PNG file");
ProblemDefinition def = new ProblemDefinition(ExceptionType.WARNING, ProblemType.NON_PNG_FILE,
ProblemDefinition def = new ProblemDefinition(ExceptionType.ERROR, ProblemType.NON_PNG_FILE,
urlRef.toString() + " is not valid PNG file");
getListener().addProblem(new ValidationProblem(def, target, lineNumber, -1));
}
Expand Down

0 comments on commit 17a9a64

Please sign in to comment.