use of org.opencastproject.feed.api.Enclosure in project opencast by opencast.
the class RomeAtomFeed method toRomeAtomEnclosures.
/**
* Converts a list of enclosures to a <code>ROME</code> enclosure list.
*
* @param enclosures
* original enclosures
* @return <code>ROME</code> enclosure list
*/
private List<com.rometools.rome.feed.atom.Link> toRomeAtomEnclosures(List<Enclosure> enclosures) {
if (enclosures == null)
return Collections.emptyList();
List<com.rometools.rome.feed.atom.Link> romeEnclosures = new ArrayList<com.rometools.rome.feed.atom.Link>(enclosures.size());
for (Enclosure enclosure : enclosures) {
com.rometools.rome.feed.atom.Link romeEnclosure = new com.rometools.rome.feed.atom.Link();
romeEnclosure.setLength(enclosure.getLength());
romeEnclosure.setType(enclosure.getType());
romeEnclosure.setHref(enclosure.getUrl());
romeEnclosure.setTitle(enclosure.getFlavor());
romeEnclosure.setRel("enclosure");
romeEnclosures.add(romeEnclosure);
}
return romeEnclosures;
}
use of org.opencastproject.feed.api.Enclosure in project opencast by opencast.
the class AbstractFeedGenerator method populateFeedEntry.
/**
* Populates the feed entry with metadata and the enclosures.
*
* @param entry
* the entry to enrich
* @param metadata
* the metadata
* @param enclosures
* the media enclosures
* @return the enriched item
*/
private FeedEntry populateFeedEntry(FeedEntry entry, SearchResultItem metadata, List<MediaPackageElement> enclosures) {
Date d = metadata.getDcCreated();
Date updatedDate = metadata.getModified();
String title = metadata.getDcTitle();
// Configure the iTunes extension
ITunesFeedEntryExtension iTunesEntry = new ITunesFeedEntryExtension();
iTunesEntry.setDuration(metadata.getDcExtent());
iTunesEntry.setBlocked(false);
iTunesEntry.setExplicit(false);
if (StringUtils.isNotBlank(metadata.getDcCreator()))
iTunesEntry.setAuthor(metadata.getDcCreator());
// TODO: Add iTunes keywords and subtitles
// iTunesEntry.setKeywords(keywords);
// iTunesEntry.setSubtitle(subtitle);
// Configure the DC extension
DublinCoreExtension dcExtension = new DublinCoreExtension();
dcExtension.setTitle(title);
dcExtension.setIdentifier(metadata.getId());
// Set contributor
if (!StringUtils.isEmpty(metadata.getDcContributor())) {
for (String contributor : metadata.getDcContributor().split(";;")) {
entry.addContributor(new PersonImpl(contributor));
dcExtension.addContributor(contributor);
}
}
// Set creator
if (!StringUtils.isEmpty(metadata.getDcCreator())) {
for (String creator : metadata.getDcCreator().split(";;")) {
if (iTunesEntry.getAuthor() == null)
iTunesEntry.setAuthor(creator);
entry.addAuthor(new PersonImpl(creator));
dcExtension.addCreator(creator);
}
}
// Set publisher
if (!StringUtils.isEmpty(metadata.getDcPublisher())) {
dcExtension.addPublisher(metadata.getDcPublisher());
}
// Set rights
if (!StringUtils.isEmpty(metadata.getDcAccessRights())) {
dcExtension.setRights(metadata.getDcAccessRights());
}
// Set description
if (!StringUtils.isEmpty(metadata.getDcDescription())) {
String summary = metadata.getDcDescription();
entry.setDescription(new ContentImpl(summary));
iTunesEntry.setSummary(summary);
dcExtension.setDescription(summary);
}
// Set the language
if (!StringUtils.isEmpty(metadata.getDcLanguage())) {
dcExtension.setLanguage(metadata.getDcLanguage());
}
// Set the publication date
if (d != null) {
entry.setPublishedDate(d);
dcExtension.setDate(d);
} else if (metadata.getModified() != null) {
entry.setPublishedDate(metadata.getModified());
dcExtension.setDate(metadata.getModified());
}
// Set the updated date
if (updatedDate == null)
updatedDate = d;
entry.setUpdatedDate(updatedDate);
// TODO: Finish dc support
// Set format
// if (!StringUtils.isEmpty(resultItem.getMediaType())) {
// dcExtension.setFormat(resultItem.getMediaType());
// }
// dcEntry.setCoverage(arg0);
// dcEntry.setRelation(arg0);
// dcEntry.setSource(arg0);
// dcEntry.setSubject(arg0);
// Set the cover image
String coverUrl = null;
if (!StringUtils.isEmpty(metadata.getCover())) {
coverUrl = metadata.getCover();
setImage(entry, coverUrl);
}
entry.addExtension(iTunesEntry);
entry.addExtension(dcExtension);
// Add the enclosures
for (MediaPackageElement element : enclosures) {
String trackMimeType = element.getMimeType().toString();
long trackLength = element.getSize();
if (trackLength <= 0 && element instanceof Track) {
// filesize unset so estimate from duration and bitrate
trackLength = 0;
if (((TrackImpl) element).hasVideo()) {
List<VideoStream> video = ((TrackImpl) element).getVideo();
if (video.get(0).getBitRate() != null) {
trackLength += metadata.getDcExtent() / 1000 * video.get(0).getBitRate() / 8;
}
}
if (((TrackImpl) element).hasAudio()) {
List<AudioStream> audio = ((TrackImpl) element).getAudio();
if (audio.get(0).getBitRate() != null) {
trackLength += metadata.getDcExtent() / 1000 * audio.get(0).getBitRate() / 8;
}
}
}
// order of magnitude correct
if (trackLength <= 0) {
trackLength = metadata.getDcExtent();
}
String trackFlavor = element.getFlavor().toString();
String trackUrl = null;
try {
trackUrl = element.getURI().toURL().toExternalForm();
} catch (MalformedURLException e) {
// Can't happen
}
Enclosure enclosure = new EnclosureImpl(trackUrl, trackMimeType, trackFlavor, trackLength);
entry.addEnclosure(enclosure);
}
return entry;
}
use of org.opencastproject.feed.api.Enclosure in project opencast by opencast.
the class RomeRssFeed method toRomeEnclosures.
/**
* Converts a list of enclosures to a <code>ROME</code> enclosure list.
*
* @param enclosures
* original enclosures
* @return <code>ROME</code> enclosure list
*/
private List<SyndEnclosure> toRomeEnclosures(List<Enclosure> enclosures) {
if (enclosures == null)
return Collections.emptyList();
List<SyndEnclosure> romeEnclosures = new ArrayList<SyndEnclosure>(enclosures.size());
for (Enclosure enclosure : enclosures) {
SyndEnclosureImpl romeEnclosure = new SyndEnclosureImpl();
romeEnclosure.setLength(enclosure.getLength());
romeEnclosure.setType(enclosure.getType());
romeEnclosure.setUrl(enclosure.getUrl());
romeEnclosures.add(romeEnclosure);
}
return romeEnclosures;
}
Aggregations