|
@@ -25,6 +25,8 @@ import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.InputStream;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
@@ -33,6 +35,7 @@ import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -165,6 +168,49 @@ public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screens
|
|
return new HttpRespMsg();
|
|
return new HttpRespMsg();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //判断文字内容是否是小说
|
|
|
|
+ private boolean isNovel(List<String> textContents) {
|
|
|
|
+ /**先粗糙地比较一下, 小说常规包含的词库,匹配频率高,则认为是小说。
|
|
|
|
+ * 第一步, 90%应该都是中文
|
|
|
|
+ */
|
|
|
|
+ int total = 0;
|
|
|
|
+ int chWNum = 0;
|
|
|
|
+ for (String w : textContents) {
|
|
|
|
+ char[] ch = w.toCharArray();
|
|
|
|
+ for (char c : ch) {
|
|
|
|
+ total++;
|
|
|
|
+ if (c >= 0x4E00 && c <= 0x9FBF) {
|
|
|
|
+ chWNum++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (chWNum*100/total < 90) {
|
|
|
|
+ //英文太多,不是小说; 不考虑英文小说。
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //第二步,匹配小说常见词汇,超过5次,认为是小说
|
|
|
|
+ InputStream ins = ScreenshotServiceImpl.class.getClassLoader().getResourceAsStream("novel_words.data");
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 是否全是汉字<br>
|
|
|
|
+ * 根据汉字编码范围进行判断<br>
|
|
|
|
+ * CJK统一汉字(不包含中文的,。《》()“‘'”、!¥等符号)<br>
|
|
|
|
+ *
|
|
|
|
+ * @param str
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public static boolean isChineseByReg(String str) {
|
|
|
|
+ if (str == null) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ Pattern pattern = Pattern.compile("[\\u4E00-\\u9FBF]+");
|
|
|
|
+ return pattern.matcher(str).matches();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
//每次获取到截屏后计算并处理
|
|
//每次获取到截屏后计算并处理
|
|
private void calculateTime(Screenshot screenshot) {
|
|
private void calculateTime(Screenshot screenshot) {
|
|
try {
|
|
try {
|