Search in sources :

Example 71 with Track

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());
}
Also used : Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 72 with Track

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);
    }
}
Also used : Attachment(org.opencastproject.mediapackage.Attachment) Track(org.opencastproject.mediapackage.Track) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) TimelinePreviewsException(org.opencastproject.timelinepreviews.api.TimelinePreviewsException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) FileNotFoundException(java.io.FileNotFoundException) UnknownFileTypeException(org.opencastproject.util.UnknownFileTypeException)

Example 73 with Track

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;
}
Also used : Track(org.opencastproject.mediapackage.Track)

Example 74 with Track

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);
}
Also used : Field(com.entwinemedia.fn.data.json.Field) MetadataField(org.opencastproject.metadata.dublincore.MetadataField) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) JValue(com.entwinemedia.fn.data.json.JValue) ArrayList(java.util.ArrayList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) AudioStream(org.opencastproject.mediapackage.AudioStream) Stream(org.opencastproject.mediapackage.Stream) VideoStream(org.opencastproject.mediapackage.VideoStream) Track(org.opencastproject.mediapackage.Track) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 75 with Track

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) VideoStream(org.opencastproject.mediapackage.VideoStream) Enclosure(org.opencastproject.feed.api.Enclosure) Date(java.util.Date) AudioStream(org.opencastproject.mediapackage.AudioStream) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Track(org.opencastproject.mediapackage.Track)

Aggregations

Track (org.opencastproject.mediapackage.Track)154 Test (org.junit.Test)56 Job (org.opencastproject.job.api.Job)56 MediaPackage (org.opencastproject.mediapackage.MediaPackage)50 URI (java.net.URI)40 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)34 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)34 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)34 HashMap (java.util.HashMap)29 ArrayList (java.util.ArrayList)27 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)24 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)21 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)20 NotFoundException (org.opencastproject.util.NotFoundException)20 IOException (java.io.IOException)19 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)17 Attachment (org.opencastproject.mediapackage.Attachment)16 EncodingProfile (org.opencastproject.composer.api.EncodingProfile)15 Catalog (org.opencastproject.mediapackage.Catalog)15 File (java.io.File)14