use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class EventsLoader method addDublinCoreCatalog.
private MediaPackage addDublinCoreCatalog(InputStream in, MediaPackageElementFlavor flavor, MediaPackage mediaPackage) throws IOException {
try {
String elementId = UUID.randomUUID().toString();
URI catalogUrl = workspace.put(mediaPackage.getIdentifier().compact(), elementId, "dublincore.xml", in);
logger.info("Adding catalog with flavor {} to mediapackage {}", flavor, mediaPackage);
MediaPackageElement mpe = mediaPackage.add(catalogUrl, MediaPackageElement.Type.Catalog, flavor);
mpe.setIdentifier(elementId);
mpe.setChecksum(Checksum.create(ChecksumType.DEFAULT_TYPE, workspace.get(catalogUrl)));
return mediaPackage;
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class AbstractAssetManager method storeAssets.
/**
* Store all elements of <code>pmp</code> under the given version.
*/
private void storeAssets(final PartialMediaPackage pmp, final Version version) throws Exception {
final String mpId = pmp.getMediaPackage().getIdentifier().toString();
final String orgId = getCurrentOrgId();
for (final MediaPackageElement e : pmp.getElements()) {
logger.debug(format("Archiving %s %s %s", e.getFlavor(), e.getMimeType(), e.getURI()));
final StoragePath storagePath = StoragePath.mk(orgId, mpId, version, e.getIdentifier());
final Opt<StoragePath> existingAssetOpt = findAssetInVersions(e.getChecksum().toString());
if (existingAssetOpt.isSome()) {
final StoragePath existingAsset = existingAssetOpt.get();
logger.debug("Content of asset {} with checksum {} has been archived before", existingAsset.getMediaPackageElementId(), e.getChecksum());
if (!getAssetStore().copy(existingAsset, storagePath)) {
throw new AssetManagerException(format("An asset with checksum %s has already been archived but trying to copy or link asset %s to it failed", e.getChecksum(), existingAsset));
}
} else {
final Opt<Long> size = e.getSize() > 0 ? Opt.some(e.getSize()) : Opt.<Long>none();
getAssetStore().put(storagePath, Source.mk(e.getURI(), size, Opt.nul(e.getMimeType())));
}
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionService method retractElement.
/**
* Retracts the mediapackage with the given identifier from the distribution channel.
*
* @param channelId
* the channel id
* @param mediapackage
* the mediapackage
* @param elementId
* the element identifier
* @return the retracted element or <code>null</code> if the element was not retracted
*/
protected MediaPackageElement[] retractElement(String channelId, final MediaPackage mediapackage, String elementId) throws DistributionException {
notNull(mediapackage, "mediapackage");
notNull(elementId, "elementId");
notNull(channelId, "channelId");
// Make sure the element exists
final MediaPackageElement element = mediapackage.getElementById(elementId);
if (element == null)
throw new IllegalStateException("No element " + elementId + " found in mediapackage" + mediapackage.getIdentifier());
logger.debug("Start element retraction for element \"{}\" with URI {}", elementId, element.getURI());
ArrayList<MediaPackageElement> retractedElements = new ArrayList<MediaPackageElement>();
// Has this element been distributed?
if (element == null || (!(element instanceof TrackImpl)))
return null;
try {
// Get the distribution path on the disk for this mediapackage element
File elementFile = getDistributionFile(channelId, mediapackage, element);
final File smilFile = getSmilFile(element, mediapackage, channelId);
logger.debug("delete elementFile {}", elementFile);
// or has been removed otherwise
if (elementFile == null || !elementFile.exists()) {
logger.warn("Deleting element file: File does not exist. Perhaps was it already deleted?: {}", elementFile);
retractedElements.add(element);
return retractedElements.toArray(new MediaPackageElement[0]);
} else {
// If a SMIL file is referenced by this element, delete first all the elements within
if (elementFile.equals(smilFile)) {
Document smilXml = getSmilDocument(smilFile);
NodeList videoList = smilXml.getElementsByTagName("video");
for (int i = 0; i < videoList.getLength(); i++) {
if (videoList.item(i) instanceof Element) {
String smilPathStr = ((Element) videoList.item(i)).getAttribute("src");
// Patch the streaming tags
if (smilPathStr.contains("mp4:"))
smilPathStr = smilPathStr.replace("mp4:", "");
if (!smilPathStr.endsWith(".mp4"))
smilPathStr += ".mp4";
elementFile = smilFile.toPath().resolveSibling(smilPathStr).toFile();
deleteElementFile(elementFile);
}
}
if (smilFile.isFile() && !smilFile.delete()) {
logger.warn("The SMIL file {} could not be succesfully deleted. Forcing quite deletion...");
}
} else {
deleteElementFile(elementFile);
}
}
logger.info("Finished rectracting element {} of media package {}", elementId, mediapackage);
retractedElements.add(element);
return retractedElements.toArray(new MediaPackageElement[0]);
} catch (Exception e) {
logger.warn("Error retracting element " + elementId + " of mediapackage " + mediapackage, e);
if (e instanceof DistributionException) {
throw (DistributionException) e;
} else {
throw new DistributionException(e);
}
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionService method distributeElements.
/**
* Distribute Mediapackage elements to the download distribution service.
*
* @param channelId The id of the publication channel to be distributed to.
* @param mediapackage The media package that contains the elements to be distributed.
* @param elementIds The ids of the elements that should be distributed
* contained within the media package.
* @return A reference to the MediaPackageElements that have been distributed.
* @throws DistributionException Thrown if the parent directory of the
* MediaPackageElement cannot be created, if the MediaPackageElement cannot be
* copied or another unexpected exception occurs.
*/
public MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException {
notNull(mediapackage, "mediapackage");
notNull(elementIds, "elementIds");
notNull(channelId, "channelId");
final Set<MediaPackageElement> elements = getElements(mediapackage, elementIds);
List<MediaPackageElement> distributedElements = new ArrayList<>();
for (MediaPackageElement element : elements) {
MediaPackageElement[] distributed = distributeElement(channelId, mediapackage, element.getIdentifier());
if (distributed != null) {
for (MediaPackageElement e : distributed) {
if (e != null)
distributedElements.add(e);
}
}
}
return distributedElements.toArray(new MediaPackageElement[distributedElements.size()]);
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class AwsS3DistributionServiceImpl 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);
String channelId = arguments.get(0);
MediaPackage mediaPackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
MediaPackageElement[] distributedElements = distributeElements(channelId, mediaPackage, elementIds, checkAvailability);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediaPackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
/*
* TODO
* Commented out due to changes in the way the element IDs are passed (ie, a list rather than individual ones
* per job). This code is still useful long term, but I don't have time to write the necessary wrapper code
* around it right now.
* case Restore:
* String fileName = arguments.get(3);
* MediaPackageElement restoredElement = null;
* if (StringUtils.isNotBlank(fileName)) {
* restoredElement = restoreElement(channelId, mediaPackage, elementIds, fileName);
* } else {
* restoredElement = restoreElement(channelId, mediaPackage, elementIds, null);
* }
* return (restoredElement != null) ? MediaPackageElementParser.getAsXml(restoredElement) : null;
*/
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);
}
}
Aggregations