Search in sources :

Example 36 with Publication

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

the class YouTubeV3PublicationServiceImpl method retract.

/**
 * Retracts the mediapackage from YouTube.
 *
 * @param job
 *          the associated job
 * @param mediaPackage
 *          the mediapackage
 * @throws PublicationException
 *           if retract did not work
 */
private Publication retract(final Job job, final MediaPackage mediaPackage) throws PublicationException {
    logger.info("Retract video from YouTube: {}", mediaPackage);
    Publication youtube = null;
    for (Publication publication : mediaPackage.getPublications()) {
        if (CHANNEL_NAME.equals(publication.getChannel())) {
            youtube = publication;
            break;
        }
    }
    if (youtube == null) {
        return null;
    }
    final YouTubePublicationAdapter contextStrategy = new YouTubePublicationAdapter(mediaPackage, workspace);
    final String episodeName = contextStrategy.getEpisodeName();
    try {
        retract(mediaPackage.getSeriesTitle(), episodeName);
    } catch (final Exception e) {
        logger.error("Failure retracting YouTube media {}", e.getMessage());
        throw new PublicationException("YouTube media retract failed on job: " + ToStringBuilder.reflectionToString(job, ToStringStyle.MULTI_LINE_STYLE), e);
    }
    return youtube;
}
Also used : PublicationException(org.opencastproject.publication.api.PublicationException) Publication(org.opencastproject.mediapackage.Publication) PublicationException(org.opencastproject.publication.api.PublicationException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 37 with Publication

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

the class DuplicateEventWorkflowOperationHandler method copyPublication.

private void copyPublication(Publication sourcePublication, MediaPackage source, MediaPackage destination, List<String> removeTags, List<String> addTags, List<String> overrideTags, List<URI> temporaryFiles) throws WorkflowOperationException {
    final String newPublicationId = UUID.randomUUID().toString();
    final Publication newPublication = PublicationImpl.publication(newPublicationId, InternalPublicationChannel.CHANNEL_ID, null, null);
    // re-distribute elements of publication to internal publication channel
    final Collection<MediaPackageElement> sourcePubElements = new HashSet<>();
    sourcePubElements.addAll(Arrays.asList(sourcePublication.getAttachments()));
    sourcePubElements.addAll(Arrays.asList(sourcePublication.getCatalogs()));
    sourcePubElements.addAll(Arrays.asList(sourcePublication.getTracks()));
    for (final MediaPackageElement e : sourcePubElements) {
        try {
            // We first have to copy the media package element into the workspace
            final MediaPackageElement element = (MediaPackageElement) e.clone();
            try (InputStream inputStream = workspace.read(element.getURI())) {
                final URI tmpUri = workspace.put(destination.getIdentifier().toString(), element.getIdentifier(), FilenameUtils.getName(element.getURI().toString()), inputStream);
                temporaryFiles.add(tmpUri);
                element.setIdentifier(null);
                element.setURI(tmpUri);
            }
            // Now we can distribute it to the new media package
            // Element has to be added before it can be distributed
            destination.add(element);
            final Job job = distributionService.distribute(InternalPublicationChannel.CHANNEL_ID, destination, element.getIdentifier());
            final MediaPackageElement distributedElement = JobUtil.payloadAsMediaPackageElement(serviceRegistry).apply(job);
            destination.remove(element);
            updateTags(distributedElement, removeTags, addTags, overrideTags);
            PublicationImpl.addElementToPublication(newPublication, distributedElement);
        } catch (Exception exception) {
            throw new WorkflowOperationException(exception);
        }
    }
    // Using an altered copy of the source publication's URI is a bit hacky,
    // but it works without knowing the URI pattern...
    String publicationUri = sourcePublication.getURI().toString();
    publicationUri = publicationUri.replace(source.getIdentifier().toString(), destination.getIdentifier().toString());
    publicationUri = publicationUri.replace(sourcePublication.getIdentifier(), newPublicationId);
    newPublication.setURI(URI.create(publicationUri));
    destination.add(newPublication);
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) InputStream(java.io.InputStream) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Publication(org.opencastproject.mediapackage.Publication) Job(org.opencastproject.job.api.Job) URI(java.net.URI) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) HashSet(java.util.HashSet)

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