Search in sources :

Example 6 with Publication

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

the class RetractYouTubeWorkflowOperationHandler method start.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(WorkflowInstance, JobContext)
 */
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    MediaPackage mediaPackage = workflowInstance.getMediaPackage();
    try {
        logger.info("Retracting media package {} from youtube publication channel", mediaPackage);
        // Wait for youtube retraction to finish
        Job retractJob = publicationService.retract(mediaPackage);
        if (!waitForStatus(retractJob).isSuccess())
            throw new WorkflowOperationException("The youtube retract job did not complete successfully");
        logger.debug("Retraction from youtube operation complete");
        // Remove the retracted elements from the mediapackage
        Job job = serviceRegistry.getJob(retractJob.getId());
        if (job.getPayload() != null) {
            logger.info("Removing youtube publication element from media package {}", mediaPackage);
            Publication retractedElement = (Publication) MediaPackageElementParser.getFromXml(job.getPayload());
            mediaPackage.remove(retractedElement);
            logger.debug("Remove youtube publication element '{}' complete", retractedElement);
        } else {
            logger.info("No youtube publication found to retract in mediapackage {}!", mediaPackage);
            return createResult(mediaPackage, Action.CONTINUE);
        }
        return createResult(mediaPackage, Action.CONTINUE);
    } catch (Throwable t) {
        throw new WorkflowOperationException(t);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Publication(org.opencastproject.mediapackage.Publication) Job(org.opencastproject.job.api.Job)

Example 7 with Publication

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

the class AssetManagerUpdateHandler method execute.

@Override
protected void execute(MessageItem messageItem) {
    AssetManagerItem item = (AssetManagerItem) messageItem;
    String mpId = item.getId();
    try {
        logger.debug("Asset Manager message handler START for mp {} event type {} in thread {}", mpId, item.getType(), Thread.currentThread().getId());
        switch(item.getType()) {
            case Update:
                if (item instanceof TakeSnapshot) {
                    // Check class just in case
                    TakeSnapshot snapshotItem = (TakeSnapshot) item;
                    // If no episopde dc, there's nothing to do.
                    if (snapshotItem.getEpisodeDublincore().isNone())
                        break;
                    // notifications, only when getting scheduler notifications
                    for (Publication pub : snapshotItem.getMediapackage().getPublications()) {
                        if (LiveScheduleService.CHANNEL_ID.equals(pub.getChannel()))
                            liveScheduleService.createOrUpdateLiveEvent(mpId, snapshotItem.getEpisodeDublincore().get());
                    }
                }
                break;
            case Delete:
                if (item instanceof DeleteEpisode)
                    // Episode is being deleted
                    liveScheduleService.deleteLiveEvent(mpId);
                // No action needed when a snapshot is deleted
                break;
            default:
                throw new IllegalArgumentException("Unhandled type of AssetManagerItem");
        }
    } catch (Exception e) {
        logger.warn(String.format("Exception occurred for mp %s, event type %s", mpId, item.getType()), e);
    } finally {
        logger.debug("Asset Manager message handler END for mp {} event type {} in thread {}", mpId, item.getType(), Thread.currentThread().getId());
    }
}
Also used : TakeSnapshot(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.TakeSnapshot) AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) Publication(org.opencastproject.mediapackage.Publication) DeleteEpisode(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.DeleteEpisode)

Example 8 with Publication

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

the class LiveScheduleServiceImplTest method testAddLivePublicationChannel.

@Test
public void testAddLivePublicationChannel() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    replayServices();
    service.addLivePublicationChannel(org, mp);
    Publication[] publications = mp.getPublications();
    Assert.assertEquals(1, publications.length);
    Assert.assertEquals(LiveScheduleService.CHANNEL_ID, publications[0].getChannel());
    Assert.assertEquals("text/html", publications[0].getMimeType().toString());
    Assert.assertEquals(ENGAGE_URL + PATH_TO_PLAYER + "?id=" + MP_ID, publications[0].getURI().toString());
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Publication(org.opencastproject.mediapackage.Publication) URI(java.net.URI) Test(org.junit.Test)

Example 9 with Publication

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

the class LiveScheduleServiceImplTest method testRemoveLivePublicationChannel.

@Test
public void testRemoveLivePublicationChannel() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp-with-live.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    replayServices();
    service.removeLivePublicationChannel(mp);
    Publication[] publications = mp.getPublications();
    Assert.assertEquals(0, publications.length);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Publication(org.opencastproject.mediapackage.Publication) URI(java.net.URI) Test(org.junit.Test)

Example 10 with Publication

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

the class ToolsEndpoint method createSmilCuttingCatalog.

/**
 * Creates a SMIL cutting catalog based on the passed editing information and the media package.
 *
 * @param editingInfo
 *          the editing information
 * @param mediaPackage
 *          the media package
 * @return a SMIL catalog
 * @throws SmilException
 *           if creating the SMIL catalog failed
 */
Smil createSmilCuttingCatalog(final EditingInfo editingInfo, final MediaPackage mediaPackage) throws SmilException {
    // Create initial SMIL catalog
    SmilResponse smilResponse = smilService.createNewSmil(mediaPackage);
    // Add tracks to the SMIL catalog
    ArrayList<Track> tracks = new ArrayList<>();
    for (final String trackId : editingInfo.getConcatTracks()) {
        Track track = mediaPackage.getTrack(trackId);
        if (track == null) {
            Opt<Track> trackOpt = getInternalPublication(mediaPackage).toStream().bind(new Fn<Publication, List<Track>>() {

                @Override
                public List<Track> apply(Publication a) {
                    return Arrays.asList(a.getTracks());
                }
            }).filter(new Fn<Track, Boolean>() {

                @Override
                public Boolean apply(Track a) {
                    return trackId.equals(a.getIdentifier());
                }
            }).head();
            if (trackOpt.isNone())
                throw new IllegalStateException(format("The track '%s' doesn't exist in media package '%s'", trackId, mediaPackage));
            track = trackOpt.get();
        }
        tracks.add(track);
    }
    for (Tuple<Long, Long> segment : editingInfo.getConcatSegments()) {
        smilResponse = smilService.addParallel(smilResponse.getSmil());
        final String parentId = smilResponse.getEntity().getId();
        final Long duration = segment.getB() - segment.getA();
        smilResponse = smilService.addClips(smilResponse.getSmil(), parentId, tracks.toArray(new Track[tracks.size()]), segment.getA(), duration);
    }
    return smilResponse.getSmil();
}
Also used : ArrayList(java.util.ArrayList) Fn(com.entwinemedia.fn.Fn) Publication(org.opencastproject.mediapackage.Publication) SmilResponse(org.opencastproject.smil.api.SmilResponse) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) LinkedList(java.util.LinkedList) Track(org.opencastproject.mediapackage.Track)

Aggregations

Publication (org.opencastproject.mediapackage.Publication)37 MediaPackage (org.opencastproject.mediapackage.MediaPackage)21 ArrayList (java.util.ArrayList)17 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)15 Job (org.opencastproject.job.api.Job)12 URI (java.net.URI)11 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)9 HashSet (java.util.HashSet)8 SimpleElementSelector (org.opencastproject.mediapackage.selector.SimpleElementSelector)7 PublicationException (org.opencastproject.publication.api.PublicationException)7 Test (org.junit.Test)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 Ignore (org.junit.Ignore)4 DistributionException (org.opencastproject.distribution.api.DistributionException)4 Attachment (org.opencastproject.mediapackage.Attachment)4 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)4 PublicationImpl (org.opencastproject.mediapackage.PublicationImpl)4 Track (org.opencastproject.mediapackage.Track)4 NotFoundException (org.opencastproject.util.NotFoundException)4 Event (org.opencastproject.index.service.impl.index.event.Event)3