Java Code Examples for cn.hutool.json.JSONArray#add()

The following examples show how to use cn.hutool.json.JSONArray#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegexUtil.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
/**
 * 获取匹配列表--2维数组
 * @param str
 * @param regex
 * @return
 */
public static JSONArray getMatchList(String str, String regex) {
	JSONArray list = new JSONArray();
	if (str == null) {
		return list;
	}
	Pattern pattern = Pattern.compile(regex);
	Matcher m = pattern.matcher(str);
	while (m.find()) {
		JSONArray row = new JSONArray();
		for(int i = 1; i <= m.groupCount(); i++){
			row.add(m.group(i));
		}
		list.add(row);
	}
	return list;
}
 
Example 2
Source File: RegexUtil.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
public static JSONArray getMatchList(String str, String regex, int flags) {
	JSONArray list = new JSONArray();
	if (str == null) {
		return list;
	}
	Pattern pattern = Pattern.compile(regex, flags);
	Matcher m = pattern.matcher(str);
	while (m.find()) {
		JSONArray row = new JSONArray();
		for(int i = 1; i <= m.groupCount(); i++){
			row.add(m.group(i));
		}
		list.add(row);
	}
	return list;
}
 
Example 3
Source File: RegexUtil.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
/**
 * 获取匹配列表--2维数组
 * @param str
 * @param regex
 * @return
 */
public static JSONArray getMatchList(String str, String regex) {
	JSONArray list = new JSONArray();
	if (str == null) {
		return list;
	}
	Pattern pattern = Pattern.compile(regex);
	Matcher m = pattern.matcher(str);
	while (m.find()) {
		JSONArray row = new JSONArray();
		for(int i = 1; i <= m.groupCount(); i++){
			row.add(m.group(i));
		}
		list.add(row);
	}
	return list;
}
 
Example 4
Source File: RegexUtil.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
public static JSONArray getMatchList(String str, String regex, int flags) {
	JSONArray list = new JSONArray();
	if (str == null) {
		return list;
	}
	Pattern pattern = Pattern.compile(regex, flags);
	Matcher m = pattern.matcher(str);
	while (m.find()) {
		JSONArray row = new JSONArray();
		for(int i = 1; i <= m.groupCount(); i++){
			row.add(m.group(i));
		}
		list.add(row);
	}
	return list;
}
 
Example 5
Source File: ExtractApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取初始化数据
 */
public void get_init_data() {
	JSONObject resp = new JSONObject();
	JSONArray list = new JSONArray();
	for (int i = 0; i < ExtractDialog.extractDialog.archiveFiles.size(); i++) {
		File file = ExtractDialog.extractDialog.archiveFiles.get(i);
		String title = file.getName();
		
		if(!ArrayUtil.contains(AppConfig.subExtNames, StringUtil.extName(file).toLowerCase())){
			continue;
		}
		
		String key = title;
		JSONObject row = new JSONObject();
		row.put("key", key);
		row.put("title", title);
		row.put("size", file.length());
		row.put("sizeF", StringUtil.getPrintSize(file.length()));
		
		list.add(row);
	}
	resp.put("list", list);
	resp.put("title", ExtractDialog.extractDialog.title);
	resp.put("archiveExt", ExtractDialog.extractDialog.archiveExt);
	resp.put("archiveSize", ExtractDialog.extractDialog.archiveData.length);
	resp.put("archiveSizeF", StringUtil.getPrintSize(ExtractDialog.extractDialog.archiveData.length));
	
	outJsonpMessage(request,response, 0, "OK", resp);
}
 
Example 6
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取下载网址列表
 * @return
 */
public static JSONArray getDetailList(String url) {
	String result = httpGet(baseUrl+url);
	//System.out.println(result);
	Document doc = Jsoup.parse(result);
	Elements matchList = doc.select("#subtb tbody tr");
	if(matchList.size() == 0)return new JSONArray();
	//System.out.println(matchList.html());
	JSONArray resList = new JSONArray();
	for(int i  = 0 ; i < matchList.size(); i++) {
		Element row = matchList.get(i);
		JSONObject resRow = new JSONObject();
		resRow.put("url", row.selectFirst("a").attr("href"));
		resRow.put("title", row.selectFirst("a").attr("title"));
		resRow.put("ext", row.selectFirst(".label-info").text());
		Elements authorInfos = row.select(".gray");
		StringBuffer authorInfo = new StringBuffer();
		authorInfos.forEach(element ->{
			authorInfo.append(element.text() + ",");
		});
		if(authorInfo.length() > 0) {
			resRow.put("authorInfo", authorInfo.toString().substring(0, authorInfo.length()-1));
		}else {
			resRow.put("authorInfo", "");
		}
		
		resRow.put("lang", row.selectFirst("img").attr("alt"));
		resRow.put("rate", row.selectFirst(".rating-star").attr("title").replace("字幕质量:", ""));
		resRow.put("downCount", row.select("td").get(3).text());
		resList.add(resRow);
	}
	return resList;
}
 
Example 7
Source File: ExtractApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取初始化数据
 */
public void get_init_data() {
	JSONObject resp = new JSONObject();
	JSONArray list = new JSONArray();
	for (int i = 0; i < ExtractDialog.extractDialog.archiveFiles.size(); i++) {
		File file = ExtractDialog.extractDialog.archiveFiles.get(i);
		String title = file.getName();
		
		if(!ArrayUtil.contains(AppConfig.subExtNames, StringUtil.extName(file).toLowerCase())){
			continue;
		}
		
		String key = title;
		JSONObject row = new JSONObject();
		row.put("key", key);
		row.put("title", title);
		row.put("size", file.length());
		row.put("sizeF", StringUtil.getPrintSize(file.length()));
		
		list.add(row);
	}
	resp.put("list", list);
	resp.put("title", ExtractDialog.extractDialog.title);
	resp.put("archiveExt", ExtractDialog.extractDialog.archiveExt);
	resp.put("archiveSize", ExtractDialog.extractDialog.archiveData.length);
	resp.put("archiveSizeF", StringUtil.getPrintSize(ExtractDialog.extractDialog.archiveData.length));
	
	outJsonpMessage(request,response, 0, "OK", resp);
}
 
Example 8
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取下载网址列表
 * @return
 */
public static JSONArray getDetailList(String url) {
	String result = httpGet(baseUrl+url);
	//System.out.println(result);
	Document doc = Jsoup.parse(result);
	Elements matchList = doc.select("#subtb tbody tr");
	if(matchList.size() == 0)return new JSONArray();
	//System.out.println(matchList.html());
	JSONArray resList = new JSONArray();
	for(int i  = 0 ; i < matchList.size(); i++) {
		Element row = matchList.get(i);
		JSONObject resRow = new JSONObject();
		resRow.put("url", row.selectFirst("a").attr("href"));
		resRow.put("title", row.selectFirst("a").attr("title"));
		resRow.put("ext", row.selectFirst(".label-info").text());
		Elements authorInfos = row.select(".gray");
		StringBuffer authorInfo = new StringBuffer();
		authorInfos.forEach(element ->{
			authorInfo.append(element.text() + ",");
		});
		if(authorInfo.length() > 0) {
			resRow.put("authorInfo", authorInfo.toString().substring(0, authorInfo.length()-1));
		}else {
			resRow.put("authorInfo", "");
		}
		
		resRow.put("lang", row.selectFirst("img").attr("alt"));
		resRow.put("rate", row.selectFirst(".rating-star").attr("title").replace("字幕质量:", ""));
		resRow.put("downCount", row.select("td").get(3).text());
		resList.add(resRow);
	}
	return resList;
}
 
Example 9
Source File: SubHDCommon.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
/**
 * 获取下载网址列表
 * @return
 */
public static JSONArray getDetailList(String url) {
	String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url);
	Document doc = Jsoup.parse(result);
	Elements matchList = doc.select(".d_table tr");
	//System.out.println(matchList.html());
	JSONArray detailList = new JSONArray();
	for (Element matchRow : matchList) {
		if(matchRow.select(".dt_edition").size() == 0)continue;
		String html = matchRow.html();
		String htmlLower = html.toLowerCase();
		String downUrl = matchRow.select(".dt_down a").attr("href");
		String title = matchRow.select(".dt_edition a").text().trim();
		int downCount = Integer.valueOf(RegexUtil.getMatchStr(matchRow.select(".dt_count").text(), "([\\d]+)"));
		String ext = "";
		for(String extName : AppConfig.subExtNames) {
			//if(StrUtil.isNotEmpty(RegexUtil.getMatchStr(html, "(>"+extName+"<)", Pattern.CASE_INSENSITIVE))) {
			if(htmlLower.contains(">"+extName+"<")) {
				ext += extName;
				ext += ",";
			}
		}
		if(ext.endsWith(",")) {
			ext=ext.substring(0, ext.length()-1);
		}else {
			ext="其它";
		}
		
		String lang = "";
		String[] langList = new String[] {"双语", "简体", "繁体", "英文"};
		for(String langName : langList) {
			if(htmlLower.contains(">"+langName+"<")) {
				lang += langName;
				lang += ",";
			}
		}
		if(lang.endsWith(",")) {
			lang=lang.substring(0, lang.length()-1);
		}else {
			lang="其它";
		}
		
		Elements labels = matchRow.select(".label");
		StringBuffer labelInfo = new StringBuffer();
		labels.forEach(element ->{
			labelInfo.append(element.text() + ",");
		});
		if(labelInfo.length() > 0) {
			labelInfo.delete(labelInfo.length()-1, labelInfo.length());
		}
		String zimuzu = matchRow.select("a.gray").text();
		
		JSONObject dataRow = new JSONObject();
		dataRow.put("url", downUrl);
		dataRow.put("title", title);
		dataRow.put("ext", ext);
		dataRow.put("lang",lang);
		dataRow.put("rate", "-");
		dataRow.put("downCount", downCount);
		dataRow.put("labelInfo", labelInfo);
		dataRow.put("zimuzu", zimuzu);
		detailList.add(dataRow);
	}
	return detailList;
}
 
Example 10
Source File: SubHDCommon.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
/**
 * 获取下载网址列表
 * @return
 */
public static JSONArray getDetailList(String url) {
	String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url);
	Document doc = Jsoup.parse(result);
	Elements matchList = doc.select(".d_table tr");
	//System.out.println(matchList.html());
	JSONArray detailList = new JSONArray();
	for (Element matchRow : matchList) {
		if(matchRow.select(".dt_edition").size() == 0)continue;
		String html = matchRow.html();
		String htmlLower = html.toLowerCase();
		String downUrl = matchRow.select(".dt_down a").attr("href");
		String title = matchRow.select(".dt_edition a").text().trim();
		int downCount = Integer.valueOf(RegexUtil.getMatchStr(matchRow.select(".dt_count").text(), "([\\d]+)"));
		String ext = "";
		for(String extName : AppConfig.subExtNames) {
			//if(StrUtil.isNotEmpty(RegexUtil.getMatchStr(html, "(>"+extName+"<)", Pattern.CASE_INSENSITIVE))) {
			if(htmlLower.contains(">"+extName+"<")) {
				ext += extName;
				ext += ",";
			}
		}
		if(ext.endsWith(",")) {
			ext=ext.substring(0, ext.length()-1);
		}else {
			ext="其它";
		}
		
		String lang = "";
		String[] langList = new String[] {"双语", "简体", "繁体", "英文"};
		for(String langName : langList) {
			if(htmlLower.contains(">"+langName+"<")) {
				lang += langName;
				lang += ",";
			}
		}
		if(lang.endsWith(",")) {
			lang=lang.substring(0, lang.length()-1);
		}else {
			lang="其它";
		}
		
		Elements labels = matchRow.select(".label");
		StringBuffer labelInfo = new StringBuffer();
		labels.forEach(element ->{
			labelInfo.append(element.text() + ",");
		});
		if(labelInfo.length() > 0) {
			labelInfo.delete(labelInfo.length()-1, labelInfo.length());
		}
		String zimuzu = matchRow.select("a.gray").text();
		
		JSONObject dataRow = new JSONObject();
		dataRow.put("url", downUrl);
		dataRow.put("title", title);
		dataRow.put("ext", ext);
		dataRow.put("lang",lang);
		dataRow.put("rate", "-");
		dataRow.put("downCount", downCount);
		dataRow.put("labelInfo", labelInfo);
		dataRow.put("zimuzu", zimuzu);
		detailList.add(dataRow);
	}
	return detailList;
}