Search in sources :

Example 6 with Checksum

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);
    }
}
Also used : AudioStream(org.opencastproject.mediapackage.AudioStream) Checksum(org.opencastproject.util.Checksum) VideoStream(org.opencastproject.mediapackage.VideoStream) URI(java.net.URI) Track(org.opencastproject.mediapackage.Track) MimeType(org.opencastproject.util.MimeType) Test(org.junit.Test)

Example 7 with Checksum

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());
    }
}
Also used : Checksum(org.opencastproject.util.Checksum) URI(java.net.URI) Track(org.opencastproject.mediapackage.Track) MimeType(org.opencastproject.util.MimeType) Test(org.junit.Test)

Example 8 with Checksum

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());
    }
}
Also used : UnsupportedElementException(org.opencastproject.mediapackage.UnsupportedElementException) Checksum(org.opencastproject.util.Checksum) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MimeType(org.opencastproject.util.MimeType) Catalog(org.opencastproject.mediapackage.Catalog)

Aggregations

Checksum (org.opencastproject.util.Checksum)8 URI (java.net.URI)7 MimeType (org.opencastproject.util.MimeType)6 URISyntaxException (java.net.URISyntaxException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 XPathExpressionException (javax.xml.xpath.XPathExpressionException)4 UnsupportedElementException (org.opencastproject.mediapackage.UnsupportedElementException)4 NodeList (org.w3c.dom.NodeList)4 Test (org.junit.Test)3 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)3 Track (org.opencastproject.mediapackage.Track)3 Catalog (org.opencastproject.mediapackage.Catalog)2 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 XPathException (javax.xml.xpath.XPathException)1 AudioStream (org.opencastproject.mediapackage.AudioStream)1 PublicationImpl (org.opencastproject.mediapackage.PublicationImpl)1 VideoStream (org.opencastproject.mediapackage.VideoStream)1 AttachmentImpl (org.opencastproject.mediapackage.attachment.AttachmentImpl)1 AudioStreamImpl (org.opencastproject.mediapackage.track.AudioStreamImpl)1