if (jsonAuthor == null) {
jsonAuthor = e.getAuthor();
}
JSONObject media = new JSONObject();
MediaEntryModule mediaModule = (MediaEntryModule) e.getModule(MediaModule.URI);
if (mediaModule != null) {
if (mediaModule.getMediaContents().length > 0) {
JSONArray contents = new JSONArray();
for (MediaContent c : mediaModule.getMediaContents()) {
JSONObject content = new JSONObject();
if (c.getReference() instanceof UrlReference) {
content.put("URL", ((UrlReference) c.getReference()).getUrl().toString());
}
if (c.getType() != null) {
content.put("Type", c.getType());
}
if (c.getWidth() != null) {
content.put("Width", c.getWidth());
}
if (c.getHeight() != null) {
content.put("Height", c.getHeight());
}
contents.put(content);
}
media.put("Contents", contents);
}
if (mediaModule.getMetadata() != null) {
if (mediaModule.getMetadata().getThumbnail().length > 0) {
// "If multiple thumbnails are included, it is assumed that they are in order of importance"
// Only use the first thumbnail for simplicity's
// sake
JSONObject thumbnail = new JSONObject();
Thumbnail t = mediaModule.getMetadata().getThumbnail()[0];
thumbnail.put("URL", t.getUrl().toString());
if (t.getWidth() != null) {
thumbnail.put("Width", t.getWidth());
}