} catch (Exception e) {
page = 1;
}
if (type != null && quanlity != null && keyword != null
&& keyword.length() > 0) {
YoutubeService tubeService = new YoutubeService();
if (type.equals("1")) {
tubeService.setPage(page);
if (keyword.contains("http://www.youtube.com/user/")) {
/*
* example : http://www.youtube.com/user/xuanhung2401
*/
String pattern = "(?:\\/user\\/)([\\w-]+)";
Pattern compiledPattern = Pattern.compile(pattern);
Matcher matcher = compiledPattern.matcher(keyword);
if (matcher.find()) {
keyword = matcher.group().replace("/user/", "");
}
} else if (keyword.contains("http://www.youtube.com")) {
/*
* example : http://www.youtube.com/xuanhung2401
*/
String pattern = "(?:youtube.com\\/)([\\w-]+)";
Pattern compiledPattern = Pattern.compile(pattern);
Matcher matcher = compiledPattern.matcher(keyword);
if (matcher.find()) {
keyword = matcher.group().replace("youtube.com/",
"");
}
}
tubeService.searchByChannel(keyword, true);
} else if (type.equals("2")) {
tubeService.setPage(page);
tubeService.searchByKey(keyword, quanlity.equals("2"));
} else if (type.equals("3")) {
String pattern = "(?:videos\\/|v=)([\\w-]+)";
Pattern compiledPattern = Pattern.compile(pattern);
Matcher matcher = compiledPattern.matcher(keyword);
if (matcher.find()) {
String fullStrId = matcher.group();
fullStrId = (fullStrId.substring(
fullStrId.length() - 11, fullStrId.length()));
tubeService.searchById(fullStrId);
}
}
resp.setCharacterEncoding("UTF-8");
req.setAttribute("url", "/admin/youtube/search" + "?type=" + type
+ "&quanlity=" + quanlity + "&keyword=" + keyword