use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class AnimateWorkflowOperationHandler method getMetadata.
private Map<String, String> getMetadata(MediaPackage mediaPackage) {
Map<String, String> metadata = new HashMap<>();
// get episode metadata
MediaPackageElementFlavor[] flavors = { MediaPackageElements.EPISODE, MediaPackageElements.SERIES };
for (MediaPackageElementFlavor flavor : flavors) {
// Get metadata catalogs
for (Catalog catalog : mediaPackage.getCatalogs(flavor)) {
DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog);
for (Map.Entry<EName, List<DublinCoreValue>> entry : dc.getValues().entrySet()) {
String key = String.format("%s.%s", flavor.getSubtype(), entry.getKey().getLocalName());
String value = entry.getValue().get(0).getValue();
metadata.put(key, value);
logger.debug("metadata: {} -> {}", key, value);
}
}
}
return metadata;
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class AnimateWorkflowOperationHandlerTest method setUp.
@Before
public void setUp() throws Exception {
handler = new AnimateWorkflowOperationHandler() {
@Override
protected JobBarrier.Result waitForStatus(Job... jobs) throws IllegalStateException, IllegalArgumentException {
JobBarrier.Result result = EasyMock.createNiceMock(JobBarrier.Result.class);
EasyMock.expect(result.isSuccess()).andReturn(true).anyTimes();
EasyMock.replay(result);
return result;
}
};
file = new File(getClass().getResource("/dc-episode.xml").toURI());
MediaPackage mediaPackage = new MediaPackageBuilderImpl().createNew();
mediaPackage.setIdentifier(new IdImpl("123-456"));
InputStream in = new FileInputStream(file);
Catalog catalog = DublinCores.read(in);
catalog.setFlavor(MediaPackageElements.EPISODE);
// catalog.setURI(getClass().getResource("/dc-episode.xml").toURI());
mediaPackage.add(catalog);
instance = EasyMock.createNiceMock(WorkflowOperationInstanceImpl.class);
EasyMock.expect(instance.getConfiguration("target-flavor")).andReturn("a/b").anyTimes();
EasyMock.expect(instance.getConfiguration("target-tags")).andReturn("a,b,c").anyTimes();
workflow = EasyMock.createMock(WorkflowInstanceImpl.class);
EasyMock.expect(workflow.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflow.getCurrentOperation()).andReturn(instance).anyTimes();
Job job = new JobImpl(0);
job.setPayload(file.getAbsolutePath());
AnimateService animateService = EasyMock.createMock(AnimateService.class);
EasyMock.expect(animateService.animate(anyObject(), anyObject(), anyObject())).andReturn(job);
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.put(anyString(), anyString(), anyString(), anyObject())).andReturn(file.toURI()).anyTimes();
EasyMock.expect(workspace.read(anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dc-episode.xml")).anyTimes();
workspace.cleanup(anyObject(Id.class));
EasyMock.expectLastCall();
workspace.delete(anyObject(URI.class));
EasyMock.expectLastCall();
job = new JobImpl(1);
job.setPayload(MediaPackageElementParser.getAsXml(new TrackImpl()));
MediaInspectionService mediaInspectionService = EasyMock.createMock(MediaInspectionService.class);
EasyMock.expect(mediaInspectionService.enrich(anyObject(), anyBoolean())).andReturn(job).once();
EasyMock.replay(animateService, workspace, workflow, mediaInspectionService);
handler.setAnimateService(animateService);
handler.setMediaInspectionService(mediaInspectionService);
handler.setWorkspace(workspace);
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class InspectWorkflowOperationHandlerTest method testInspectOperationDCMetadata.
@Test
public void testInspectOperationDCMetadata() throws Exception {
WorkflowOperationResult result = getWorkflowOperationResult(mp);
Catalog cat = result.getMediaPackage().getCatalogs()[0];
// dublincore check: also checked with strict mock calls
Assert.assertEquals(NEW_DC_URL, cat.getURI().toString());
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class InspectWorkflowOperationHandlerTest method testInspectOperationTrackMetadata.
@Test
public void testInspectOperationTrackMetadata() throws Exception {
for (Catalog c : mp.getCatalogs()) {
mp.remove(c);
}
WorkflowOperationResult result = getWorkflowOperationResult(mp);
Track trackNew = result.getMediaPackage().getTracks()[0];
// check track metadata
Assert.assertNotNull(trackNew.getChecksum());
Assert.assertNotNull(trackNew.getMimeType());
Assert.assertNotNull(trackNew.getDuration());
Assert.assertNotNull(trackNew.getStreams());
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class TextAnalyzerServiceImpl method extract.
/**
* Starts text extraction on the image and returns a receipt containing the final result in the form of an
* Mpeg7Catalog.
*
* @param image
* the element to analyze
* @param block
* <code>true</code> to make this operation synchronous
* @return a receipt containing the resulting mpeg-7 catalog
* @throws TextAnalyzerException
*/
private Catalog extract(Job job, Attachment image) throws TextAnalyzerException, MediaPackageException {
final Attachment attachment = image;
final URI imageUrl = attachment.getURI();
File imageFile = null;
try {
Mpeg7CatalogImpl mpeg7 = Mpeg7CatalogImpl.newInstance();
logger.info("Starting text extraction from {}", imageUrl);
try {
imageFile = workspace.get(imageUrl);
} catch (NotFoundException e) {
throw new TextAnalyzerException("Image " + imageUrl + " not found in workspace", e);
} catch (IOException e) {
throw new TextAnalyzerException("Unable to access " + imageUrl + " in workspace", e);
}
VideoText[] videoTexts = analyze(imageFile, image.getIdentifier());
// Create a temporal decomposition
MediaTime mediaTime = new MediaTimeImpl(0, 0);
Video avContent = mpeg7.addVideoContent(image.getIdentifier(), mediaTime, null);
TemporalDecomposition<VideoSegment> temporalDecomposition = (TemporalDecomposition<VideoSegment>) avContent.getTemporalDecomposition();
// Add a segment
VideoSegment videoSegment = temporalDecomposition.createSegment("segment-0");
videoSegment.setMediaTime(mediaTime);
// Add the video text to the spacio temporal decomposition of the segment
SpatioTemporalDecomposition spatioTemporalDecomposition = videoSegment.createSpatioTemporalDecomposition(true, false);
for (VideoText videoText : videoTexts) {
spatioTemporalDecomposition.addVideoText(videoText);
}
logger.info("Text extraction of {} finished, {} lines found", attachment.getURI(), videoTexts.length);
URI uri;
InputStream in;
try {
in = mpeg7CatalogService.serialize(mpeg7);
} catch (IOException e) {
throw new TextAnalyzerException("Error serializing mpeg7", e);
}
try {
uri = workspace.putInCollection(COLLECTION_ID, job.getId() + ".xml", in);
} catch (IOException e) {
throw new TextAnalyzerException("Unable to put mpeg7 into the workspace", e);
}
Catalog catalog = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(Catalog.TYPE, MediaPackageElements.TEXTS);
catalog.setURI(uri);
logger.debug("Created MPEG7 catalog for {}", imageUrl);
return catalog;
} catch (Exception e) {
logger.warn("Error extracting text from " + imageUrl, e);
if (e instanceof TextAnalyzerException) {
throw (TextAnalyzerException) e;
} else {
throw new TextAnalyzerException(e);
}
} finally {
try {
workspace.delete(imageUrl);
} catch (Exception e) {
logger.warn("Unable to delete temporary text analysis image {}: {}", imageUrl, e);
}
}
}
Aggregations