|
@@ -0,0 +1,171 @@
|
|
|
|
|
+package top.lvzhiqiang.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
|
+import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
|
|
|
|
+import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
|
|
|
|
+import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
|
|
|
|
+import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
|
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
|
|
+import org.jsoup.select.Elements;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+import top.lvzhiqiang.entity.VideoMonitorActors;
|
|
|
|
|
+import top.lvzhiqiang.mapper.VideoMonitorActorsMapper;
|
|
|
|
|
+import top.lvzhiqiang.service.Crawler4JavdbService;
|
|
|
|
|
+import top.lvzhiqiang.util.JsoupUtil;
|
|
|
|
|
+import top.lvzhiqiang.util.SpringUtils;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.net.InetSocketAddress;
|
|
|
|
|
+import java.net.Proxy;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Crawler Javdb ServiceImpl
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author lvzhiqiang
|
|
|
|
|
+ * 2022/10/17 14:47
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class Crawler4JavdbServiceImpl implements Crawler4JavdbService {
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private VideoMonitorActorsMapper videoMonitorActorsMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
|
|
+ private String env;
|
|
|
|
|
+ Proxy proxy = null;
|
|
|
|
|
+
|
|
|
|
|
+ //private final ForkJoinPool forkJoinPool = new ForkJoinPool(16);
|
|
|
|
|
+
|
|
|
|
|
+ private static final WxCpServiceImpl wxCpService;
|
|
|
|
|
+ static {
|
|
|
|
|
+ WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl();
|
|
|
|
|
+ wxCpDefaultConfig.setCorpId("ww95a4adba56acb55f");
|
|
|
|
|
+ wxCpDefaultConfig.setAgentId(1000003);
|
|
|
|
|
+ wxCpDefaultConfig.setCorpSecret("JytA0dZYsorEYyHNbfJuxpSUXydGiSc_uH6jhduB94M");
|
|
|
|
|
+ wxCpService = new WxCpServiceImpl();
|
|
|
|
|
+ wxCpService.setWxCpConfigStorage(wxCpDefaultConfig);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void beforeJavbus() {
|
|
|
|
|
+ if (null == proxy) {
|
|
|
|
|
+ if ("dev".equals(env)) {
|
|
|
|
|
+ proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ proxy = Proxy.NO_PROXY;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void monitorActors() {
|
|
|
|
|
+ beforeJavbus();
|
|
|
|
|
+
|
|
|
|
|
+ String website = "javdb";
|
|
|
|
|
+ List<VideoMonitorActors> videoMonitorActorsList = videoMonitorActorsMapper.findAllListByWebsite(website);
|
|
|
|
|
+
|
|
|
|
|
+ /*forkJoinPool.submit(() -> videoMonitorActorsList.parallelStream().forEach(e -> {
|
|
|
|
|
+ })).join();*/
|
|
|
|
|
+
|
|
|
|
|
+ Document document;
|
|
|
|
|
+ Elements itembSelects;
|
|
|
|
|
+ for (VideoMonitorActors videoMonitorActors : videoMonitorActorsList) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<String> insertCodeList = new ArrayList<>();
|
|
|
|
|
+ List<String> codeList = videoMonitorActorsMapper.findAllLogListBySymbol(videoMonitorActors.getSymbol());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
|
|
+ headerMap.put("referer", videoMonitorActors.getHttpUrl());
|
|
|
|
|
+ document = JsoupUtil.requestDocument(videoMonitorActors.getHttpUrl(), JsoupUtil.HTTP_GET, proxy, null, headerMap, null);
|
|
|
|
|
+ itembSelects = document.select("div.movie-list").select("div.item");
|
|
|
|
|
+
|
|
|
|
|
+ for (Element itembSelect : itembSelects) {
|
|
|
|
|
+ String code = itembSelect.select("a.box").get(0).select("div.video-title").select("strong").text().trim().toUpperCase();
|
|
|
|
|
+ if (codeList.contains(code)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ insertCodeList.add(code);
|
|
|
|
|
+
|
|
|
|
|
+ String url = itembSelect.select("a.box").get(0).attr("abs:href");
|
|
|
|
|
+ String title = itembSelect.select("a.box").get(0).attr("title");
|
|
|
|
|
+ String score = itembSelect.select("a.box").get(0).select("div.score").text().replace(" ", "").trim();
|
|
|
|
|
+ String date = itembSelect.select("a.box").get(0).select("div.meta").text().trim();
|
|
|
|
|
+ String tags = itembSelect.select("a.box").get(0).select("div.tags").text().trim();
|
|
|
|
|
+
|
|
|
|
|
+ String content = "<div class=\"highlight\">演员:" + videoMonitorActors.getActorsRemark() + "</div>" +
|
|
|
|
|
+ "<div>识别码:" + code + "</div>" +
|
|
|
|
|
+ "<div>标题:" + title + "</div>" +
|
|
|
|
|
+ "<div>发行日期:" + date + "</div>" +
|
|
|
|
|
+ "<div class=\"gray\">评价:" + score + "</div>" +
|
|
|
|
|
+ "<div class=\"gray\">标签:" + tags + "</div>";
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
|
|
+ params.put("title", "JAVDB演员监控报警");
|
|
|
|
|
+ params.put("logUrl", url);
|
|
|
|
|
+ params.put("btnTxt", "影片详情");
|
|
|
|
|
+ SpringUtils.getBean(Crawler4JavdbServiceImpl.class).monitorAlarm4APP_TEXT_CARD(content, params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ videoMonitorActorsMapper.insertLogList(insertCodeList, videoMonitorActors.getSymbol());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Async
|
|
|
|
|
+ public void monitorAlarm4APP_TEXT_CARD(String content, JSONObject params) {
|
|
|
|
|
+ // 文本卡片模式发消息
|
|
|
|
|
+ String title = "监控告警明细";
|
|
|
|
|
+ if (params.containsKey("title")) {
|
|
|
|
|
+ title = params.getString("title");
|
|
|
|
|
+ }
|
|
|
|
|
+ String logUrl = "https://lvzhiqiang.top";
|
|
|
|
|
+ if (params.containsKey("logUrl")) {
|
|
|
|
|
+ logUrl = params.getString("logUrl");
|
|
|
|
|
+ }
|
|
|
|
|
+ String btnTxt = "日志详情";
|
|
|
|
|
+ if (params.containsKey("btnTxt")) {
|
|
|
|
|
+ btnTxt = params.getString("btnTxt");
|
|
|
|
|
+ }
|
|
|
|
|
+ String user = "LvZhiQiang";
|
|
|
|
|
+ if (params.containsKey("user")) {
|
|
|
|
|
+ user = params.getString("user");
|
|
|
|
|
+ }
|
|
|
|
|
+ String party = "";
|
|
|
|
|
+ if (params.containsKey("party")) {
|
|
|
|
|
+ party = params.getString("party");
|
|
|
|
|
+ }
|
|
|
|
|
+ String tag = "";
|
|
|
|
|
+ if (params.containsKey("tag")) {
|
|
|
|
|
+ tag = params.getString("tag");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ WxCpMessage wxCpMessage = WxCpMessage.TEXTCARD().agentId(1000003)
|
|
|
|
|
+ .toUser(user)
|
|
|
|
|
+ .toParty(party)
|
|
|
|
|
+ .toTag(tag)
|
|
|
|
|
+ .title(title).description(content)
|
|
|
|
|
+ .url(logUrl).btnTxt(btnTxt)
|
|
|
|
|
+ .build();
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("企业微信推送消息,send message: {}", wxCpMessage);
|
|
|
|
|
+ WxCpMessageSendResult sendResult = wxCpService.getMessageService().send(wxCpMessage);
|
|
|
|
|
+ log.info("企业微信推送消息成功,send result: {}", sendResult);
|
|
|
|
|
+ } catch (WxErrorException e) {
|
|
|
|
|
+ log.error("企业微信推送消息失败!Detail: ", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|