use of org.opencastproject.util.Checksum in project opencast by opencast.
the class MediaInspectionServiceImplTest method testEnrichment.
@Test
public void testEnrichment() throws Exception {
final URI trackUri = getResource("/test.mp4");
for (MediaInspector mi : init(trackUri)) {
Track track = mi.inspectTrack(trackUri, Options.NO_OPTION);
// make changes to metadata
Checksum cs = track.getChecksum();
track.setChecksum(null);
MimeType mt = mimeType("video", "flash");
track.setMimeType(mt);
// test the enrich scenario
Track newTrack = (Track) mi.enrich(track, false, Options.NO_OPTION);
VideoStream[] videoStreams = TrackSupport.byType(newTrack.getStreams(), VideoStream.class);
assertTrue(videoStreams[0].getFrameCount().longValue() > 0);
AudioStream[] audioStreams = TrackSupport.byType(newTrack.getStreams(), AudioStream.class);
assertTrue(audioStreams[0].getFrameCount().longValue() > 0);
assertEquals(newTrack.getChecksum(), cs);
assertEquals(newTrack.getMimeType(), mt);
assertNotNull(newTrack.getDuration());
assertTrue(newTrack.getDuration() > 0);
// test the override scenario
newTrack = (Track) mi.enrich(track, true, Options.NO_OPTION);
assertEquals(newTrack.getChecksum(), cs);
assertNotSame(newTrack.getMimeType(), mt);
assertTrue(newTrack.getDuration() > 0);
}
for (MediaInspector mi : init(trackUri)) {
Track track = mi.inspectTrack(trackUri, Options.NO_OPTION);
// make changes to metadata
Checksum cs = track.getChecksum();
track.setChecksum(null);
MimeType mt = mimeType("video", "flash");
track.setMimeType(mt);
// test the enrich scenario
Track newTrack = (Track) mi.enrich(track, false, Options.NO_OPTION);
VideoStream[] videoStreams = TrackSupport.byType(newTrack.getStreams(), VideoStream.class);
assertTrue(videoStreams[0].getFrameCount().longValue() > 0);
AudioStream[] audioStreams = TrackSupport.byType(newTrack.getStreams(), AudioStream.class);
assertTrue(audioStreams[0].getFrameCount().longValue() > 0);
assertEquals(newTrack.getChecksum(), cs);
assertEquals(newTrack.getMimeType(), mt);
assertNotNull(newTrack.getDuration());
assertTrue(newTrack.getDuration() > 0);
// test the override scenario
newTrack = (Track) mi.enrich(track, true, Options.NO_OPTION);
assertEquals(newTrack.getChecksum(), cs);
assertNotSame(newTrack.getMimeType(), mt);
assertTrue(newTrack.getDuration() > 0);
}
}
use of org.opencastproject.util.Checksum in project opencast by opencast.
the class MediaInspectionServiceImplTest method testEnrichmentEmptyContainer.
@Test
public void testEnrichmentEmptyContainer() throws Exception {
final URI trackUri = getResource("/nostreams.mp4");
for (MediaInspector mi : init(trackUri)) {
Track track = mi.inspectTrack(trackUri, Options.NO_OPTION);
// make changes to metadata
Checksum cs = track.getChecksum();
track.setChecksum(null);
MimeType mt = mimeType("video", "flash");
track.setMimeType(mt);
// test the enrich scenario
Track newTrack = (Track) mi.enrich(track, false, Options.NO_OPTION);
assertEquals(newTrack.getChecksum(), cs);
assertEquals(newTrack.getMimeType(), mt);
assertNull(newTrack.getDuration());
// test the override scenario
newTrack = (Track) mi.enrich(track, true, Options.NO_OPTION);
assertEquals(newTrack.getChecksum(), cs);
assertNotSame(newTrack.getMimeType(), mt);
assertNull(newTrack.getDuration());
}
}
use of org.opencastproject.util.Checksum in project opencast by opencast.
the class CatalogBuilderPlugin method elementFromManifest.
/**
* {@inheritDoc}
*
* @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#elementFromManifest(org.w3c.dom.Node,
* org.opencastproject.mediapackage.MediaPackageSerializer)
*/
@Override
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer) throws UnsupportedElementException {
String id = null;
String flavor = null;
URI url = null;
long size = -1;
Checksum checksum = null;
MimeType mimeType = null;
String reference = null;
try {
// id
id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);
// url
url = serializer.decodeURI(new URI(xpath.evaluate("url/text()", elementNode).trim()));
// flavor
flavor = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
// reference
reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);
// size
String documentSize = xpath.evaluate("size/text()", elementNode).trim();
if (!"".equals(documentSize))
size = Long.parseLong(documentSize);
// checksum
String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
checksum = Checksum.create(checksumType.trim(), checksumValue.trim());
// mimetype
String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
if (StringUtils.isNotEmpty(mimeTypeValue))
mimeType = MimeTypes.parseMimeType(mimeTypeValue);
// create the catalog
Catalog dc = CatalogImpl.fromURI(url);
if (StringUtils.isNotEmpty(id))
dc.setIdentifier(id);
// Add url
dc.setURI(url);
// Add flavor
if (flavor != null)
dc.setFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
// Add reference
if (StringUtils.isNotEmpty(reference))
dc.referTo(MediaPackageReferenceImpl.fromString(reference));
// Set size
if (size > 0)
dc.setSize(size);
// Set checksum
if (checksum != null)
dc.setChecksum(checksum);
// Set Mimetype
if (mimeType != null)
dc.setMimeType(mimeType);
// Tags
NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
for (int i = 0; i < tagNodes.getLength(); i++) {
dc.addTag(tagNodes.item(i).getTextContent());
}
return dc;
} catch (XPathExpressionException e) {
throw new UnsupportedElementException("Error while reading catalog information from manifest: " + e.getMessage());
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
} catch (URISyntaxException e) {
throw new UnsupportedElementException("Error while reading dublin core catalog " + url + ": " + e.getMessage());
}
}
Aggregations