String id = (String) req.getParameter("id");
String playlistId = (String) req.getParameter("playlist");
url = (String) req.getParameter("url");
url = URLDecoder.decode(url, "UTF-8");
Tube tube = YoutubeService.searchStaticById(id);
Playlist pl = PlaylistModel.byId(playlistId, false);
TreeMap recentAddTreeId = (TreeMap) session
.getAttribute("recentAddTreeId");
String currentPl = (String) session
.getAttribute("currentPlaylist");
if (currentPl != null && !currentPl.equals(pl.getId())) {
recentAddTreeId = new TreeMap();
} else if (recentAddTreeId == null) {
recentAddTreeId = new TreeMap();
}
if (pl != null
&& TubeValidate.checkForm(req, resp, session, action,
tube)) {
tube = processTubeDetail(playlistId, tube);
// add author to site.
Queue queue = QueueFactory.getDefaultQueue();
queue.add(TaskOptions.Builder.withUrl(
"/task-admin?action=add-author&uri="
+ tube.getAuthorUrl()).method(
TaskOptions.Method.GET));
TubeModel.insert(tube);
recentAddTreeId.put(tube.getId(), tube.getId());
session.setAttribute("recentAddTreeId", recentAddTreeId);
session.setAttribute("currentPlaylist", pl.getId());
session.setAttribute("success",
"Action success ! Video have been added to playlist \""
+ pl.getTitle() + "\"");