Search in sources :

Example 46 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class PublishEngageWorkflowOperationHandler method mergePackages.

/**
 * MH-10216, Copied from the original RepublishWorkflowOperationHandler
 *
 * Merges the updated mediapackage with the one that is currently published in a way where the updated elements
 * replace existing ones in the published mediapackage based on their flavor.
 * <p>
 * If <code>publishedMp</code> is <code>null</code>, this method returns the updated mediapackage without any
 * modifications.
 *
 * @param updatedMp
 *          the updated media package
 * @param publishedMp
 *          the mediapackage that is currently published
 * @return the merged mediapackage
 */
protected MediaPackage mergePackages(MediaPackage updatedMp, MediaPackage publishedMp) {
    if (publishedMp == null)
        return updatedMp;
    MediaPackage mergedMediaPackage = (MediaPackage) updatedMp.clone();
    for (MediaPackageElement element : publishedMp.elements()) {
        String type = element.getElementType().toString().toLowerCase();
        if (updatedMp.getElementsByFlavor(element.getFlavor()).length == 0) {
            logger.info("Merging {} '{}' into the updated mediapackage", type, element.getIdentifier());
            mergedMediaPackage.add((MediaPackageElement) element.clone());
        } else {
            logger.info(String.format("Overwriting existing %s '%s' with '%s' in the updated mediapackage", type, element.getIdentifier(), updatedMp.getElementsByFlavor(element.getFlavor())[0].getIdentifier()));
        }
    }
    return mergedMediaPackage;
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 47 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class AbstractOaiPmhDatabase method updateEntity.

public void updateEntity(OaiPmhEntity entity, MediaPackage mediaPackage, String repository) throws OaiPmhDatabaseException {
    entity.setOrganization(getSecurityService().getOrganization().getId());
    entity.setDeleted(false);
    entity.setRepositoryId(repository);
    entity.setMediaPackageId(mediaPackage.getIdentifier().toString());
    entity.setMediaPackageXML(MediaPackageParser.getAsXml(mediaPackage));
    entity.setSeries(mediaPackage.getSeries());
    entity.removeAllMediaPackageElements();
    for (MediaPackageElement mpe : mediaPackage.getElements()) {
        if (mpe.getFlavor() == null) {
            logger.debug("A flavor must be set on media package elements for publishing");
            continue;
        }
        if (mpe.getElementType() != MediaPackageElement.Type.Catalog && mpe.getElementType() != MediaPackageElement.Type.Attachment) {
            logger.debug("Only catalog and attachment types are currently supported");
            continue;
        }
        if (mpe.getMimeType() == null || !mpe.getMimeType().eq(MimeTypes.XML)) {
            logger.debug("Only media package elements with mime type XML are supported");
            continue;
        }
        String catalogXml = null;
        try (InputStream in = getWorkspace().read(mpe.getURI())) {
            catalogXml = IOUtils.toString(in, "UTF-8");
        } catch (Throwable e) {
            logger.warn("Unable to load catalog {} from media package {}", mpe.getIdentifier(), mediaPackage.getIdentifier().compact(), e);
            continue;
        }
        if (catalogXml == null || StringUtils.isBlank(catalogXml) || !XmlUtil.parseNs(catalogXml).isRight()) {
            logger.warn("The catalog {} from media package {} isn't a well formatted XML document", mpe.getIdentifier(), mediaPackage.getIdentifier().compact());
            continue;
        }
        entity.addMediaPackageElement(new OaiPmhElementEntity(mpe.getElementType().name(), mpe.getFlavor().toString(), catalogXml));
    }
}
Also used : OaiPmhElementEntity(org.opencastproject.oaipmh.persistence.OaiPmhElementEntity) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) InputStream(java.io.InputStream)

Example 48 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class ToolsEndpoint method getVideoEditor.

@GET
@Path("{mediapackageid}/editor.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getVideoEditor", description = "Returns all the information required to get the editor tool started", returnDescription = "JSON object", pathParameters = { @RestParameter(name = "mediapackageid", description = "The id of the media package", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Media package found", responseCode = SC_OK), @RestResponse(description = "Media package not found", responseCode = SC_NOT_FOUND) })
public Response getVideoEditor(@PathParam("mediapackageid") final String mediaPackageId) throws IndexServiceException, NotFoundException {
    if (!isEditorAvailable(mediaPackageId))
        return R.notFound();
    // Select tracks
    final Event event = getEvent(mediaPackageId).get();
    final MediaPackage mp = index.getEventMediapackage(event);
    List<MediaPackageElement> previewPublications = getPreviewElementsFromPublication(getInternalPublication(mp));
    // Collect previews and tracks
    List<JValue> jPreviews = new ArrayList<>();
    List<JValue> jTracks = new ArrayList<>();
    for (MediaPackageElement element : previewPublications) {
        final URI elementUri;
        if (urlSigningService.accepts(element.getURI().toString())) {
            try {
                String clientIP = null;
                if (signWithClientIP) {
                    clientIP = securityService.getUserIP();
                }
                elementUri = new URI(urlSigningService.sign(element.getURI().toString(), expireSeconds, null, clientIP));
            } catch (URISyntaxException e) {
                logger.error("Error while trying to sign the preview urls because: {}", getStackTrace(e));
                throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
            } catch (UrlSigningException e) {
                logger.error("Error while trying to sign the preview urls because: {}", getStackTrace(e));
                throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
            }
        } else {
            elementUri = element.getURI();
        }
        jPreviews.add(obj(f("uri", v(elementUri.toString())), f("flavor", v(element.getFlavor().getType()))));
        if (!Type.Track.equals(element.getElementType()))
            continue;
        JObject jTrack = obj(f("id", v(element.getIdentifier())), f("flavor", v(element.getFlavor().getType())));
        // Check if there's a waveform for the current track
        Opt<Attachment> optWaveform = getWaveformForTrack(mp, element);
        if (optWaveform.isSome()) {
            final URI waveformUri;
            if (urlSigningService.accepts(element.getURI().toString())) {
                try {
                    waveformUri = new URI(urlSigningService.sign(optWaveform.get().getURI().toString(), expireSeconds, null, null));
                } catch (URISyntaxException e) {
                    logger.error("Error while trying to serialize the waveform urls because: {}", getStackTrace(e));
                    throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
                } catch (UrlSigningException e) {
                    logger.error("Error while trying to sign the preview urls because: {}", getStackTrace(e));
                    throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
                }
            } else {
                waveformUri = optWaveform.get().getURI();
            }
            jTracks.add(jTrack.merge(obj(f("waveform", v(waveformUri.toString())))));
        } else {
            jTracks.add(jTrack);
        }
    }
    // Get existing segments
    List<JValue> jSegments = new ArrayList<>();
    for (Tuple<Long, Long> segment : getSegments(mp)) {
        jSegments.add(obj(f(START_KEY, v(segment.getA())), f(END_KEY, v(segment.getB()))));
    }
    // Get workflows
    List<JValue> jWorkflows = new ArrayList<>();
    for (WorkflowDefinition workflow : getEditingWorkflows()) {
        jWorkflows.add(obj(f("id", v(workflow.getId())), f("name", v(workflow.getTitle(), Jsons.BLANK))));
    }
    return RestUtils.okJson(obj(f("title", v(mp.getTitle(), Jsons.BLANK)), f("date", v(event.getRecordingStartDate(), Jsons.BLANK)), f("series", obj(f("id", v(event.getSeriesId(), Jsons.BLANK)), f("title", v(event.getSeriesName(), Jsons.BLANK)))), f("presenters", arr($(event.getPresenters()).map(Functions.stringToJValue))), f("previews", arr(jPreviews)), f(TRACKS_KEY, arr(jTracks)), f("duration", v(mp.getDuration())), f(SEGMENTS_KEY, arr(jSegments)), f("workflows", arr(jWorkflows))));
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) Attachment(org.opencastproject.mediapackage.Attachment) URISyntaxException(java.net.URISyntaxException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) URI(java.net.URI) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) JValue(com.entwinemedia.fn.data.json.JValue) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) JObject(com.entwinemedia.fn.data.json.JObject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 49 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class LiveScheduleServiceImpl method retract.

void retract(MediaPackage mp) throws LiveScheduleException {
    try {
        List<Job> jobs = new ArrayList<Job>();
        Set<String> elementIds = new HashSet<String>();
        // Remove media package from the search index
        String mpId = mp.getIdentifier().compact();
        logger.info("Removing LIVE media package {} from the search index", mpId);
        jobs.add(searchService.delete(mpId));
        // Retract elements
        for (MediaPackageElement mpe : mp.getElements()) {
            if (!MediaPackageElement.Type.Publication.equals(mpe.getElementType()))
                elementIds.add(mpe.getIdentifier());
        }
        jobs.add(downloadDistributionService.retract(CHANNEL_ID, mp, elementIds));
        if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess())
            throw new LiveScheduleException("Removing live media package from search did not complete successfully");
    } catch (LiveScheduleException e) {
        throw e;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) Job(org.opencastproject.job.api.Job) URISyntaxException(java.net.URISyntaxException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) HashSet(java.util.HashSet)

Example 50 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class LiveScheduleServiceImpl method buildStreamingTrack.

Track buildStreamingTrack(String uriString, MediaPackageElementFlavor flavor, String mimeType, String resolution, long duration) throws URISyntaxException {
    URI uri = new URI(uriString);
    MediaPackageElementBuilder elementBuilder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
    MediaPackageElement element = elementBuilder.elementFromURI(uri, MediaPackageElement.Type.Track, flavor);
    TrackImpl track = (TrackImpl) element;
    // Set duration and mime type
    track.setDuration(duration);
    track.setLive(true);
    track.setMimeType(MimeTypes.parseMimeType(mimeType));
    VideoStreamImpl video = new VideoStreamImpl("video-" + flavor.getType() + "-" + flavor.getSubtype());
    // Set video resolution
    String[] dimensions = resolution.split("x");
    video.setFrameWidth(Integer.parseInt(dimensions[0]));
    video.setFrameHeight(Integer.parseInt(dimensions[1]));
    track.addStream(video);
    logger.debug("Creating live track element of flavor {}, resolution {}, and url {}", new Object[] { flavor, resolution, uriString });
    return track;
}
Also used : MediaPackageElementBuilder(org.opencastproject.mediapackage.MediaPackageElementBuilder) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) VideoStreamImpl(org.opencastproject.mediapackage.track.VideoStreamImpl) URI(java.net.URI)

Aggregations

MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)153 MediaPackage (org.opencastproject.mediapackage.MediaPackage)72 NotFoundException (org.opencastproject.util.NotFoundException)50 Job (org.opencastproject.job.api.Job)49 URI (java.net.URI)48 IOException (java.io.IOException)39 ArrayList (java.util.ArrayList)39 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)39 Test (org.junit.Test)36 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)27 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)25 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)24 File (java.io.File)21 Track (org.opencastproject.mediapackage.Track)21 DistributionException (org.opencastproject.distribution.api.DistributionException)20 InputStream (java.io.InputStream)19 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)19 HashSet (java.util.HashSet)18 URISyntaxException (java.net.URISyntaxException)16 Path (javax.ws.rs.Path)16