if (title.length() > 60) {
title = title.substring(0, 59);
}
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent(title);
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, assignment.getCategory()));
mg.setKeywords(new MediaKeywords());
List<String> tags = new ArrayList<String>();
for (int i = 0; i < tagsArray.length(); i++) {
String tag = tagsArray.getString(i).trim();
mg.getKeywords().addKeyword(tag);
tags.add(tag);
}
// Sort the list of tags and join with "," so that we can easily compare
// what's in the
// datastore with what we get back from the YouTube API.
String sortedTags = util.sortedJoin(tags, ",");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent(description);
String applicationNameTag = Util.CLIENT_ID_PREFIX + SystemProperty.applicationId.get();
if (applicationNameTag.length() > 25) {
applicationNameTag = applicationNameTag.substring(0, 24) + "!";
}
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, applicationNameTag));
// Maximum size of a developer tag is 25 characters, and we prepend 2
// characters.
if (assignmentId.length() <= 23) {
// Minimum size of a developer tag is 3 characters, so always append 2
// characters.
String assignmentIdTag = String.format("A-%s", assignmentId);
// Use a developer tag to make it easy for developers to query for all
// videos uploaded for
// a given assignment.
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, assignmentIdTag));
} else {
log.warning(String.format("Assignment id '%s' is longer than 25 characters, and can't be "
+ "used as a developer tag.", assignmentId));
}