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;
}
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);
}
Aggregations