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

The following examples show how to use cn.hutool.json.JSONArray#size() . 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: OcrUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 7 votes vote down vote up
private static String extractSogouResult(String html) {
    if (StrUtil.isBlank(html)) {
        return "";
    }
    JSONObject jsonObject = JSONUtil.parseObj(html);
    if (jsonObject.getInt("success", 0) != 1) {
        return "";
    }
    JSONArray jsonArray = jsonObject.getJSONArray("result");
    List<TextBlock> textBlocks = new ArrayList<>();
    boolean isEng;
    for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject jObj = jsonArray.getJSONObject(i);
        TextBlock textBlock = new TextBlock();
        textBlock.setText(jObj.getStr("content").trim());
        //noinspection SuspiciousToArrayCall
        String[] frames = jObj.getJSONArray("frame").toArray(new String[0]);
        textBlock.setTopLeft(CommUtils.frameToPoint(frames[0]));
        textBlock.setTopRight(CommUtils.frameToPoint(frames[1]));
        textBlock.setBottomRight(CommUtils.frameToPoint(frames[2]));
        textBlock.setBottomLeft(CommUtils.frameToPoint(frames[3]));
        textBlocks.add(textBlock);
    }
    isEng = jsonObject.getStr("lang", "zh-Chs").equals("zh-Chs");
    return CommUtils.combineTextBlocks(textBlocks, isEng);
}
 
Example 2
Source File: ExtractDialog.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public boolean saveSelected(JSONArray items) {
	for (int i = 0; i < items.size(); i++) {
		JSONObject item = items.getJSONObject(i);
		DownParm downParm = new DownParm();
		downParm.charset = item.getStr("charset", "");
		downParm.simplified = item.getBool("simplified", false);
		downParm.filenameType = item.getInt("filenameType", 1);
		saveFile(item.getStr("title"), downParm);
	}
	return true;
}
 
Example 3
Source File: ExtractDialog.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public boolean saveSelected(JSONArray items) {
	for (int i = 0; i < items.size(); i++) {
		JSONObject item = items.getJSONObject(i);
		DownParm downParm = new DownParm();
		downParm.charset = item.getStr("charset", "");
		downParm.simplified = item.getBool("simplified", false);
		downParm.filenameType = item.getInt("filenameType", 1);
		saveFile(item.getStr("title"), downParm);
	}
	return true;
}
 
Example 4
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 * @param url
 * @return
 */
public static JSONObject downContent(String url) {
	String result = httpGet(baseUrl+url);
	String downUrl = RegexUtil.getMatchStr(result, 
			"<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\""
			, Pattern.DOTALL);
	if(downUrl == null)return null;
	if(!downUrl.startsWith("http")) {
		downUrl = baseUrl + downUrl;
	}
	
	result = httpGet(downUrl);
	if(result == null)return null;
	//System.out.println(result);
	JSONArray resList = RegexUtil.getMatchList(result, 
			"<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL);
	if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null;
	//HtHttpUtil.http.debug=true;
	HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl);
	int i = 0;
	while(httpResp == null && resList.size() > ++i) {
		httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl);
	}
	//System.out.println(httpResp);
	if(httpResp == null)return null;
	String filename = HtHttpUtil.getFileName(httpResp);
	byte[] data = httpResp.bodyBytes();
	//System.out.println(filename);
	JSONObject resp = new JSONObject();
	resp.put("filename", filename);
	resp.put("ext", StringUtil.extName(filename).toLowerCase());
	resp.put("data", Base64.encode(data));
	
	return resp;
}
 
Example 5
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕列表
 * @param fileName
 * @return
 * @throws Exception
 */
public static JSONArray DownList(String fileName) throws Exception {
	JSONArray mainList = getFuzzyPageList(fileName);
	//System.out.println(mainList);
	
	JSONArray resp = new JSONArray();
	for(int i = 0; i < mainList.size(); i++) {
		JSONArray row = mainList.getJSONArray(i);
		//System.out.println("row="+row);
		JSONArray detailList = getDetailList(row.getStr(0));
		if(detailList ==  null)continue;
		resp.addAll(detailList);
	}
	return resp;
}
 
Example 6
Source File: SubHDCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕列表
 * @param fileName
 * @return
 * @throws Exception
 */
public static JSONArray DownList(String fileName) throws Exception {
	JSONArray mainList = getFuzzyPageList(fileName);
	//System.out.println(mainList);
	
	JSONArray resp = new JSONArray();
	for(int i = 0; i < mainList.size(); i++) {
		JSONArray row = mainList.getJSONArray(i);
		//System.out.println("row="+row);
		JSONArray detailList = getDetailList(row.getStr(0));
		resp.addAll(detailList);
	}
	return resp;
}
 
Example 7
Source File: ExtractApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载压缩文件中的字幕
 * @param data
 * @return
 */
public void down_archive_file() {
	HttpRequest request = getRequest();
	HttpResponse response = getResponse();
	String data = request.getParaToStr("data");
	if(data == null) {
		outJsonpMessage(request,response, 1, "请求数据错误");
		return;
	}
	logger.info("data="+data);
	if(data == null || data.length() < 10) {
		logger.error("data=null");
		outJsonpMessage(request,response, 1, "参数错误");
		return;
	}
	JSONObject dataJson = JSONUtil.parseObj(data);
	JSONArray items = dataJson.getJSONArray("items");
	if(items == null || items.size() == 0) {
		logger.error("items=null");
		outJsonpMessage(request,response, 1, "参数错误");
		return;
	}
	
	JSONObject resp = new JSONObject();
	resp.put("saveSelected", ExtractDialog.extractDialog.saveSelected(items));
	outJsonpMessage(request,response, 0, "OK", resp);
}
 
Example 8
Source File: ApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 */
public void zimu_down() {
	HttpRequest request = getRequest();
	HttpResponse response = getResponse();
	String data = request.getParaToStr("data");
	if(data == null) {
		outJsonpMessage(request,response, 1, "请求数据错误");
		return;
	}
	
	JSONObject dataJson = JSONUtil.parseObj(data);
	JSONArray items = dataJson.getJSONArray("items");
	if(items == null || items.size()==0) {
		outJsonpMessage(request,response, 1, "请选择字幕文件");
		return;
	}
	//System.out.println(data);
	
	DownParm downParm;
	JSONObject row;
	int item_id;
	for(int i = 0; i < items.size(); i++) {
		row = items.getJSONObject(i);
		item_id = row.getInt("id");
		downParm = new DownParm();
		downParm.charset = row.getStr("charset", "");
		downParm.simplified = row.getBool("simplified", false);
		downParm.filenameType = row.getInt("filenameType", 1);

		try {
			DownZIMu.down(item_id, downParm);
		}catch(Exception e) {
			logger.error(e);
		}
		
	}
	outJsonpMessage(request,response, 0, "OK");
}
 
Example 9
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 * @param url
 * @return
 */
public static JSONObject downContent(String url) {
	String result = httpGet(baseUrl+url);
	String downUrl = RegexUtil.getMatchStr(result, 
			"<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\""
			, Pattern.DOTALL);
	if(downUrl == null)return null;
	if(!downUrl.startsWith("http")) {
		downUrl = baseUrl + downUrl;
	}
	
	result = httpGet(downUrl);
	if(result == null)return null;
	//System.out.println(result);
	JSONArray resList = RegexUtil.getMatchList(result, 
			"<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL);
	if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null;
	//HtHttpUtil.http.debug=true;
	HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl);
	int i = 0;
	while(httpResp == null && resList.size() > ++i) {
		httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl);
	}
	//System.out.println(httpResp);
	if(httpResp == null)return null;
	String filename = HtHttpUtil.getFileName(httpResp);
	byte[] data = httpResp.bodyBytes();
	//System.out.println(filename);
	JSONObject resp = new JSONObject();
	resp.put("filename", filename);
	resp.put("ext", StringUtil.extName(filename).toLowerCase());
	resp.put("data", Base64.encode(data));
	
	return resp;
}
 
Example 10
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕列表
 * @param fileName
 * @return
 * @throws Exception
 */
public static JSONArray DownList(String fileName) throws Exception {
	JSONArray mainList = getFuzzyPageList(fileName);
	//System.out.println(mainList);
	
	JSONArray resp = new JSONArray();
	for(int i = 0; i < mainList.size(); i++) {
		JSONArray row = mainList.getJSONArray(i);
		//System.out.println("row="+row);
		JSONArray detailList = getDetailList(row.getStr(0));
		if(detailList ==  null)continue;
		resp.addAll(detailList);
	}
	return resp;
}
 
Example 11
Source File: SubHDCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕列表
 * @param fileName
 * @return
 * @throws Exception
 */
public static JSONArray DownList(String fileName) throws Exception {
	JSONArray mainList = getFuzzyPageList(fileName);
	//System.out.println(mainList);
	
	JSONArray resp = new JSONArray();
	for(int i = 0; i < mainList.size(); i++) {
		JSONArray row = mainList.getJSONArray(i);
		//System.out.println("row="+row);
		JSONArray detailList = getDetailList(row.getStr(0));
		resp.addAll(detailList);
	}
	return resp;
}
 
Example 12
Source File: ExtractApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载压缩文件中的字幕
 * @param data
 * @return
 */
public void down_archive_file() {
	HttpRequest request = getRequest();
	HttpResponse response = getResponse();
	String data = request.getParaToStr("data");
	if(data == null) {
		outJsonpMessage(request,response, 1, "请求数据错误");
		return;
	}
	logger.info("data="+data);
	if(data == null || data.length() < 10) {
		logger.error("data=null");
		outJsonpMessage(request,response, 1, "参数错误");
		return;
	}
	JSONObject dataJson = JSONUtil.parseObj(data);
	JSONArray items = dataJson.getJSONArray("items");
	if(items == null || items.size() == 0) {
		logger.error("items=null");
		outJsonpMessage(request,response, 1, "参数错误");
		return;
	}
	
	JSONObject resp = new JSONObject();
	resp.put("saveSelected", ExtractDialog.extractDialog.saveSelected(items));
	outJsonpMessage(request,response, 0, "OK", resp);
}
 
Example 13
Source File: ApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 */
public void zimu_down() {
	HttpRequest request = getRequest();
	HttpResponse response = getResponse();
	String data = request.getParaToStr("data");
	if(data == null) {
		outJsonpMessage(request,response, 1, "请求数据错误");
		return;
	}
	
	JSONObject dataJson = JSONUtil.parseObj(data);
	JSONArray items = dataJson.getJSONArray("items");
	if(items == null || items.size()==0) {
		outJsonpMessage(request,response, 1, "请选择字幕文件");
		return;
	}
	//System.out.println(data);
	
	DownParm downParm;
	JSONObject row;
	int item_id;
	for(int i = 0; i < items.size(); i++) {
		row = items.getJSONObject(i);
		item_id = row.getInt("id");
		downParm = new DownParm();
		downParm.charset = row.getStr("charset", "");
		downParm.simplified = row.getBool("simplified", false);
		downParm.filenameType = row.getInt("filenameType", 1);

		try {
			DownZIMu.down(item_id, downParm);
		}catch(Exception e) {
			logger.error(e);
		}
		
	}
	outJsonpMessage(request,response, 0, "OK");
}
 
Example 14
Source File: OcrUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String extractBdResult(String html) {
    if (StrUtil.isBlank(html)) {
        return "";
    }
    JSONObject jsonObject = JSONUtil.parseObj(html);
    if (jsonObject.getInt("errno", 0) != 0) {
        return "";
    }
    JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("words_result");
    List<TextBlock> textBlocks = new ArrayList<>();
    boolean isEng = false;
    for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject jObj = jsonArray.getJSONObject(i);
        TextBlock textBlock = new TextBlock();
        textBlock.setText(jObj.getStr("words").trim());
        //noinspection SuspiciousToArrayCall
        JSONObject location = jObj.getJSONObject("location");
        int top = location.getInt("top");
        int left = location.getInt("left");
        int width = location.getInt("width");
        int height = location.getInt("height");
        textBlock.setTopLeft(new Point(top, left));
        textBlock.setTopRight(new Point(top, left + width));
        textBlock.setBottomLeft(new Point(top + height, left));
        textBlock.setBottomRight(new Point(top + height, left + width));
        textBlocks.add(textBlock);
    }
    return CommUtils.combineTextBlocks(textBlocks, isEng);
}
 
Example 15
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
/**
 * 模糊查询页面列表
 * @param title
 * @return
 */
public static JSONArray getFuzzyPageList(String title) {
	int pos = title.lastIndexOf(".");
	title = title.toLowerCase();
	title = pos > 0 ? title.substring(0, pos) : title;
	JSONArray list = getPageList(title);
	if(list.size() == 0 && (pos = title.lastIndexOf("bluray")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".2160p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".1080p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".720p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".480p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".internal")) > 0) {
		title = title.substring(0, pos+9);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	//System.out.println(list);
	return list;
}
 
Example 16
Source File: SubHDCommon.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
/**
 * 模糊查询页面列表
 * @param title
 * @return
 */
public static JSONArray getFuzzyPageList(String title) {
	int pos = title.lastIndexOf(".");
	title = title.toLowerCase();
	title = pos > 0 ? title.substring(0, pos) : title;
	JSONArray list = getPageList(title);
	if(list.size() == 0 && (pos = title.lastIndexOf("bluray")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".2160p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".1080p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".720p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".480p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".internal")) > 0) {
		title = title.substring(0, pos+9);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	//System.out.println(list);
	return list;
}
 
Example 17
Source File: SubHDCommon.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
/**
 * 模糊查询页面列表
 * @param title
 * @return
 */
public static JSONArray getFuzzyPageList(String title) {
	int pos = title.lastIndexOf(".");
	title = title.toLowerCase();
	title = pos > 0 ? title.substring(0, pos) : title;
	JSONArray list = getPageList(title);
	if(list.size() == 0 && (pos = title.lastIndexOf("bluray")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".2160p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".1080p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".720p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".480p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".internal")) > 0) {
		title = title.substring(0, pos+9);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	//System.out.println(list);
	return list;
}
 
Example 18
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 4 votes vote down vote up
/**
 * 模糊查询页面列表
 * @param title
 * @return
 */
public static JSONArray getFuzzyPageList(String title) {
	int pos = title.lastIndexOf(".");
	title = title.toLowerCase();
	title = pos > 0 ? title.substring(0, pos) : title;
	JSONArray list = getPageList(title);
	if(list.size() == 0 && (pos = title.lastIndexOf("bluray")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".2160p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".1080p")) > 0) {
		title = title.substring(0, pos+6);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".720p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".480p")) > 0) {
		title = title.substring(0, pos+5);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	if(list.size() == 0 && (pos = title.lastIndexOf(".internal")) > 0) {
		title = title.substring(0, pos+9);
		list = getPageList(title);
		if(list.size() == 0) {
			title = title.substring(0, pos);
			list = getPageList(title);
		}
	}
	//System.out.println(list);
	return list;
}