use of org.opencastproject.mediapackage.Track 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.Track in project opencast by opencast.
the class TimelinePreviewsServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
switch(op) {
case TimelinePreview:
Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(0));
int imageCount = Integer.parseInt(arguments.get(1));
Attachment timelinePreviewsMpe = generatePreviewImages(job, track, imageCount);
return MediaPackageElementParser.getAsXml(timelinePreviewsMpe);
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
} catch (IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
use of org.opencastproject.mediapackage.Track in project opencast by opencast.
the class IBMWatsonTranscriptionService method process.
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
String result = "";
op = Operation.valueOf(operation);
switch(op) {
case StartTranscription:
String mpId = arguments.get(0);
Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(1));
createRecognitionsJob(mpId, track);
break;
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
return result;
}
use of org.opencastproject.mediapackage.Track in project opencast by opencast.
the class EventsEndpoint method getEventMedia.
@GET
@Path("{eventId}/media")
@Produces({ "application/json", "application/v1.0.0+json" })
public Response getEventMedia(@HeaderParam("Accept") String acceptHeader, @PathParam("eventId") String id) throws Exception {
ArrayList<TrackImpl> tracks = new ArrayList<>();
for (final Event event : indexService.getEvent(id, externalIndex)) {
final MediaPackage mp = indexService.getEventMediapackage(event);
for (Track track : mp.getTracks()) {
if (track instanceof TrackImpl) {
tracks.add((TrackImpl) track);
}
}
List<JValue> tracksJson = new ArrayList<>();
for (Track track : tracks) {
List<Field> fields = new ArrayList<>();
if (track.getChecksum() != null)
fields.add(f("checksum", v(track.getChecksum().toString())));
if (track.getDescription() != null)
fields.add(f("description", v(track.getDescription())));
if (track.getDuration() != null)
fields.add(f("duration", v(track.getDuration())));
if (track.getElementDescription() != null)
fields.add(f("element-description", v(track.getElementDescription())));
if (track.getFlavor() != null)
fields.add(f("flavor", v(track.getFlavor().toString())));
if (track.getIdentifier() != null)
fields.add(f("identifier", v(track.getIdentifier())));
if (track.getMimeType() != null)
fields.add(f("identifier", v(track.getMimeType().toString())));
fields.add(f("size", v(track.getSize())));
if (track.getStreams() != null) {
List<Field> streams = new ArrayList<>();
for (Stream stream : track.getStreams()) {
streams.add(f(stream.getIdentifier(), getJsonStream(stream)));
}
fields.add(f("streams", obj(streams)));
}
if (track.getTags() != null) {
List<JValue> tags = new ArrayList<>();
for (String tag : track.getTags()) {
tags.add(v(tag));
}
fields.add(f("tags", arr(tags)));
}
if (track.getURI() != null)
fields.add(f("uri", v(track.getURI().toString())));
tracksJson.add(obj(fields));
}
return ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(tracksJson));
}
return ApiResponses.notFound("Cannot find an event with id '%s'.", id);
}
use of org.opencastproject.mediapackage.Track in project opencast by opencast.
the class AbstractFeedGenerator method populateFeedEntry.
/**
* Populates the feed entry with metadata and the enclosures.
*
* @param entry
* the entry to enrich
* @param metadata
* the metadata
* @param enclosures
* the media enclosures
* @return the enriched item
*/
private FeedEntry populateFeedEntry(FeedEntry entry, SearchResultItem metadata, List<MediaPackageElement> enclosures) {
Date d = metadata.getDcCreated();
Date updatedDate = metadata.getModified();
String title = metadata.getDcTitle();
// Configure the iTunes extension
ITunesFeedEntryExtension iTunesEntry = new ITunesFeedEntryExtension();
iTunesEntry.setDuration(metadata.getDcExtent());
iTunesEntry.setBlocked(false);
iTunesEntry.setExplicit(false);
if (StringUtils.isNotBlank(metadata.getDcCreator()))
iTunesEntry.setAuthor(metadata.getDcCreator());
// TODO: Add iTunes keywords and subtitles
// iTunesEntry.setKeywords(keywords);
// iTunesEntry.setSubtitle(subtitle);
// Configure the DC extension
DublinCoreExtension dcExtension = new DublinCoreExtension();
dcExtension.setTitle(title);
dcExtension.setIdentifier(metadata.getId());
// Set contributor
if (!StringUtils.isEmpty(metadata.getDcContributor())) {
for (String contributor : metadata.getDcContributor().split(";;")) {
entry.addContributor(new PersonImpl(contributor));
dcExtension.addContributor(contributor);
}
}
// Set creator
if (!StringUtils.isEmpty(metadata.getDcCreator())) {
for (String creator : metadata.getDcCreator().split(";;")) {
if (iTunesEntry.getAuthor() == null)
iTunesEntry.setAuthor(creator);
entry.addAuthor(new PersonImpl(creator));
dcExtension.addCreator(creator);
}
}
// Set publisher
if (!StringUtils.isEmpty(metadata.getDcPublisher())) {
dcExtension.addPublisher(metadata.getDcPublisher());
}
// Set rights
if (!StringUtils.isEmpty(metadata.getDcAccessRights())) {
dcExtension.setRights(metadata.getDcAccessRights());
}
// Set description
if (!StringUtils.isEmpty(metadata.getDcDescription())) {
String summary = metadata.getDcDescription();
entry.setDescription(new ContentImpl(summary));
iTunesEntry.setSummary(summary);
dcExtension.setDescription(summary);
}
// Set the language
if (!StringUtils.isEmpty(metadata.getDcLanguage())) {
dcExtension.setLanguage(metadata.getDcLanguage());
}
// Set the publication date
if (d != null) {
entry.setPublishedDate(d);
dcExtension.setDate(d);
} else if (metadata.getModified() != null) {
entry.setPublishedDate(metadata.getModified());
dcExtension.setDate(metadata.getModified());
}
// Set the updated date
if (updatedDate == null)
updatedDate = d;
entry.setUpdatedDate(updatedDate);
// TODO: Finish dc support
// Set format
// if (!StringUtils.isEmpty(resultItem.getMediaType())) {
// dcExtension.setFormat(resultItem.getMediaType());
// }
// dcEntry.setCoverage(arg0);
// dcEntry.setRelation(arg0);
// dcEntry.setSource(arg0);
// dcEntry.setSubject(arg0);
// Set the cover image
String coverUrl = null;
if (!StringUtils.isEmpty(metadata.getCover())) {
coverUrl = metadata.getCover();
setImage(entry, coverUrl);
}
entry.addExtension(iTunesEntry);
entry.addExtension(dcExtension);
// Add the enclosures
for (MediaPackageElement element : enclosures) {
String trackMimeType = element.getMimeType().toString();
long trackLength = element.getSize();
if (trackLength <= 0 && element instanceof Track) {
// filesize unset so estimate from duration and bitrate
trackLength = 0;
if (((TrackImpl) element).hasVideo()) {
List<VideoStream> video = ((TrackImpl) element).getVideo();
if (video.get(0).getBitRate() != null) {
trackLength += metadata.getDcExtent() / 1000 * video.get(0).getBitRate() / 8;
}
}
if (((TrackImpl) element).hasAudio()) {
List<AudioStream> audio = ((TrackImpl) element).getAudio();
if (audio.get(0).getBitRate() != null) {
trackLength += metadata.getDcExtent() / 1000 * audio.get(0).getBitRate() / 8;
}
}
}
// order of magnitude correct
if (trackLength <= 0) {
trackLength = metadata.getDcExtent();
}
String trackFlavor = element.getFlavor().toString();
String trackUrl = null;
try {
trackUrl = element.getURI().toURL().toExternalForm();
} catch (MalformedURLException e) {
// Can't happen
}
Enclosure enclosure = new EnclosureImpl(trackUrl, trackMimeType, trackFlavor, trackLength);
entry.addEnclosure(enclosure);
}
return entry;
}
Aggregations