BgServiceImpl.java 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  1. package top.lvzhiqiang.service.impl;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.jsoup.Connection;
  4. import org.jsoup.HttpStatusException;
  5. import org.jsoup.Jsoup;
  6. import org.jsoup.nodes.Document;
  7. import org.jsoup.nodes.Element;
  8. import org.jsoup.select.Elements;
  9. import org.springframework.beans.factory.annotation.Value;
  10. import org.springframework.scheduling.annotation.Async;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Propagation;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import top.lvzhiqiang.config.WebAppConfig;
  15. import top.lvzhiqiang.dto.JavAllInfo;
  16. import top.lvzhiqiang.dto.JavAllInfo4Infantry;
  17. import top.lvzhiqiang.dto.JavAllInfo4Uncensored;
  18. import top.lvzhiqiang.entity.*;
  19. import top.lvzhiqiang.enumeration.ResultCodeEnum;
  20. import top.lvzhiqiang.exception.BusinessException;
  21. import top.lvzhiqiang.exception.ParameterException;
  22. import top.lvzhiqiang.mapper.*;
  23. import top.lvzhiqiang.service.BgService;
  24. import top.lvzhiqiang.util.DateUtils;
  25. import top.lvzhiqiang.util.JsoupUtil;
  26. import top.lvzhiqiang.util.StringUtils;
  27. import javax.annotation.Resource;
  28. import java.io.*;
  29. import java.lang.reflect.Field;
  30. import java.math.BigDecimal;
  31. import java.net.Proxy;
  32. import java.nio.charset.StandardCharsets;
  33. import java.time.Instant;
  34. import java.time.LocalDate;
  35. import java.time.LocalDateTime;
  36. import java.time.ZoneOffset;
  37. import java.util.*;
  38. import java.util.stream.Collectors;
  39. /**
  40. * Bg ServiceImpl
  41. *
  42. * @author lvzhiqiang
  43. * 2022/4/16 16:10
  44. */
  45. @Service
  46. @Slf4j
  47. public class BgServiceImpl implements BgService {
  48. @Resource
  49. private VideoGenresMapper videoGenresMapper;
  50. @Resource
  51. private VideoCastMapper videoCastMapper;
  52. @Resource
  53. private VideoInfoCastMapper videoInfoCastMapper;
  54. @Resource
  55. private VideoInfoGenresMapper videoInfoGenresMapper;
  56. @Resource
  57. private VideoInfoMapper videoInfoMapper;
  58. @Resource
  59. private IcodePoolMapper icodePoolMapper;
  60. @Resource
  61. private VideoInfoPoolMapper videoInfoPoolMapper;
  62. @Resource
  63. private VideoSitePoolMapper videoSitePoolMapper;
  64. @Resource
  65. private DicCodeMapper dicCodeMapper;
  66. @Resource
  67. private VideoInfoOtherMapper videoInfoOtherMapper;
  68. @Resource
  69. private VideoInfoUncensoredMapper videoInfoUncensoredMapper;
  70. @Resource
  71. private VideoInfoInfantryMapper videoInfoInfantryMapper;
  72. @Resource
  73. private CrawlerLoveFootMapper crawlerLoveFootMapper;
  74. @Value("${spring.profiles.active}")
  75. private String env;
  76. private String ignoreFileTypeSuffix = "";
  77. /**
  78. * findDicCode
  79. *
  80. * @author lvzhiqiang
  81. * 2022/5/3 17:37
  82. */
  83. @Override
  84. public String findDicCode(String codeDesc, String order) throws IllegalAccessException {
  85. List<DicCode> dicCodeList = dicCodeMapper.findByCodeDesc(codeDesc, order);
  86. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(dicCodeList.size())).concat("<br/>"));
  87. for (DicCode dicCode : dicCodeList) {
  88. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  89. Field[] fields = dicCode.getClass().getDeclaredFields();
  90. for (Field field : fields) {
  91. field.setAccessible(true);
  92. sb.append("<tr>");
  93. sb.append("<td>").append(field.getName()).append("</td>");
  94. sb.append("<td>").append(field.get(dicCode)).append("</td>");
  95. sb.append("</tr>");
  96. }
  97. sb.append("</table>");
  98. }
  99. return sb.toString();
  100. }
  101. /**
  102. * findIcodePool
  103. *
  104. * @author lvzhiqiang
  105. * 2022/5/3 17:37
  106. */
  107. @Override
  108. public String findIcodePool(String identificationCode, Integer status, String order, String crudT) throws IllegalAccessException {
  109. if ("2".equals(crudT)) {
  110. //更新
  111. if (StringUtils.isEmpty(identificationCode) || null == status) {
  112. return "identificationCode和status不能为空";
  113. }
  114. icodePoolMapper.updateStatusByCode(identificationCode, status);
  115. return "success";
  116. }
  117. if ("3".equals(crudT)) {
  118. //删除
  119. if (StringUtils.isEmpty(identificationCode)) {
  120. return "dentificationCode不能为空";
  121. }
  122. icodePoolMapper.delByCode(identificationCode);
  123. return "success";
  124. }
  125. List<IcodePool> icodePoolList = icodePoolMapper.findByCodeAndStatus(identificationCode, status, order);
  126. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(icodePoolList.size())).concat("<br/>"));
  127. for (IcodePool icodePool : icodePoolList) {
  128. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  129. Field[] fields = icodePool.getClass().getDeclaredFields();
  130. for (Field field : fields) {
  131. field.setAccessible(true);
  132. sb.append("<tr>");
  133. sb.append("<td>").append(field.getName()).append("</td>");
  134. sb.append("<td>").append(field.get(icodePool)).append("</td>");
  135. sb.append("</tr>");
  136. }
  137. sb.append("</table>");
  138. }
  139. return sb.toString();
  140. }
  141. /**
  142. * findVideoSitePool
  143. *
  144. * @author lvzhiqiang
  145. * 2022/5/3 17:37
  146. */
  147. @Override
  148. public String findVideoSitePool(String url, String order) throws IllegalAccessException {
  149. List<VideoSitePool> videoSitePoolList = videoSitePoolMapper.findByUrl(url, order);
  150. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoSitePoolList.size())).concat("<br/>"));
  151. for (VideoSitePool videoSitePool : videoSitePoolList) {
  152. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  153. Field[] fields = videoSitePool.getClass().getDeclaredFields();
  154. for (Field field : fields) {
  155. field.setAccessible(true);
  156. sb.append("<tr>");
  157. sb.append("<td>").append(field.getName()).append("</td>");
  158. sb.append("<td>").append(field.get(videoSitePool)).append("</td>");
  159. sb.append("</tr>");
  160. }
  161. sb.append("</table>");
  162. }
  163. return sb.toString();
  164. }
  165. /**
  166. * findVideoInfoPool
  167. *
  168. * @author lvzhiqiang
  169. * 2022/5/3 17:37
  170. */
  171. @Override
  172. public String findVideoInfoPool(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  173. if ("2".equals(crudT)) {
  174. //更新
  175. if (StringUtils.isEmpty(identificationCode) || null == type) {
  176. return "identificationCode和type不能为空";
  177. }
  178. videoInfoPoolMapper.updateTypeByCode(identificationCode, type);
  179. return "success";
  180. }
  181. if ("3".equals(crudT)) {
  182. //删除
  183. if (StringUtils.isEmpty(identificationCode)) {
  184. return "dentificationCode不能为空";
  185. }
  186. videoInfoPoolMapper.delByCode(identificationCode);
  187. return "success";
  188. }
  189. List<VideoInfoPool> videoInfoPoolList = videoInfoPoolMapper.findByCodeAndType(identificationCode, type, order);
  190. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoPoolList.size())).concat("<br/>"));
  191. for (VideoInfoPool videoInfoPool : videoInfoPoolList) {
  192. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  193. Field[] fields = videoInfoPool.getClass().getDeclaredFields();
  194. for (Field field : fields) {
  195. field.setAccessible(true);
  196. sb.append("<tr>");
  197. sb.append("<td>").append(field.getName()).append("</td>");
  198. sb.append("<td>").append(field.get(videoInfoPool)).append("</td>");
  199. sb.append("</tr>");
  200. }
  201. sb.append("</table>");
  202. }
  203. return sb.toString();
  204. }
  205. /**
  206. * findVideoInfoLoveFoot
  207. *
  208. * @author lvzhiqiang
  209. * 2022/12/34 18:08
  210. */
  211. @Override
  212. public String findVideoInfoLoveFoot(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  213. if ("2".equals(crudT)) {
  214. //更新
  215. if (StringUtils.isEmpty(identificationCode) || null == type) {
  216. return "identificationCode和type不能为空";
  217. }
  218. crawlerLoveFootMapper.updateTypeByCode(identificationCode, type);
  219. return "success";
  220. }
  221. if ("3".equals(crudT)) {
  222. //删除
  223. if (StringUtils.isEmpty(identificationCode)) {
  224. return "dentificationCode不能为空";
  225. }
  226. crawlerLoveFootMapper.delByCode(identificationCode);
  227. return "success";
  228. }
  229. List<CrawlerLoveFoot> crawlerLoveFootList = crawlerLoveFootMapper.findByCodeAndType(identificationCode, type, order);
  230. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(crawlerLoveFootList.size())).concat("<br/>"));
  231. for (CrawlerLoveFoot crawlerLoveFoot : crawlerLoveFootList) {
  232. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  233. Field[] fields = crawlerLoveFoot.getClass().getDeclaredFields();
  234. for (Field field : fields) {
  235. field.setAccessible(true);
  236. sb.append("<tr>");
  237. sb.append("<td>").append(field.getName()).append("</td>");
  238. sb.append("<td>").append(field.get(crawlerLoveFoot)).append("</td>");
  239. sb.append("</tr>");
  240. }
  241. sb.append("</table>");
  242. }
  243. return sb.toString();
  244. }
  245. /**
  246. * findVideoInfo
  247. *
  248. * @author lvzhiqiang
  249. * 2022/5/3 17:37
  250. */
  251. @Override
  252. public String findVideoInfo(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  253. if ("3".equals(crudT)) {
  254. //删除
  255. if (StringUtils.isEmpty(identificationCode)) {
  256. return "dentificationCode不能为空";
  257. }
  258. videoInfoMapper.delByCode(identificationCode);
  259. return "success";
  260. }
  261. List<VideoInfo> videoInfoList = videoInfoMapper.findByCodeAndType(identificationCode, type, order);
  262. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoList.size())).concat("<br/>"));
  263. for (VideoInfo videoInfo : videoInfoList) {
  264. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  265. Field[] fields = videoInfo.getClass().getDeclaredFields();
  266. for (Field field : fields) {
  267. field.setAccessible(true);
  268. sb.append("<tr>");
  269. sb.append("<td>").append(field.getName()).append("</td>");
  270. sb.append("<td>").append(field.get(videoInfo)).append("</td>");
  271. sb.append("</tr>");
  272. }
  273. sb.append("</table>");
  274. }
  275. return sb.toString();
  276. }
  277. /**
  278. * updateScoreOrComment
  279. *
  280. * @author lvzhiqiang
  281. * 2022/5/4 9:54
  282. */
  283. @Override
  284. public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) {
  285. BigDecimal scoreBD = null;
  286. if (StringUtils.isNotEmpty(score)) {
  287. scoreBD = new BigDecimal(score);
  288. }
  289. int num = videoInfoOtherMapper.findByCode(identificationCode);
  290. if (num == 0) {
  291. videoInfoOtherMapper.insertScoreOrComment(identificationCode, scoreBD, comment);
  292. return "insert success";
  293. }
  294. videoInfoOtherMapper.updateScoreOrComment(identificationCode, scoreBD, comment);
  295. return "update success";
  296. }
  297. /**
  298. * Jsoup VideoInfoUncensored
  299. *
  300. * @author lvzhiqiang
  301. * 2022/5/4 19:27
  302. */
  303. @Async
  304. @Override
  305. public void jsoupVideoInfoUncensored(Integer status) {
  306. log.warn("jsoupVideoInfoUncensored 开始:status={}", status);
  307. // 获取待抓取码列表
  308. List<String> icodeList = videoInfoUncensoredMapper.findIcodeByStatus(status);
  309. if (icodeList.size() == 0) {
  310. log.warn("status={}的icodeList为空", status);
  311. return;
  312. }
  313. // 获取javbus防屏蔽地址
  314. List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
  315. if (javbusUrlList.size() == 0) {
  316. log.warn("javbusUrlList为空");
  317. return;
  318. }
  319. // 获取码池图片保存路径
  320. String liuchuPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  321. // 遍历
  322. Document document;
  323. VideoInfoUncensored videoInfoUncensored;
  324. String javbusUrl;
  325. int j = 0;
  326. for (int i = 0; i < icodeList.size(); i++) {
  327. long start = System.currentTimeMillis();
  328. String identificationCode = icodeList.get(i);
  329. int retryCount = 0;
  330. while (retryCount <= 3) {
  331. javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
  332. try {
  333. document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
  334. .timeout(50000)
  335. //.proxy()
  336. //.data()
  337. .ignoreContentType(true)
  338. .userAgent(getUserAgent())
  339. .header("referer", "https://www.javbus.com/".concat(identificationCode))
  340. .get();
  341. videoInfoUncensored = new VideoInfoUncensored();
  342. videoInfoUncensored.setIdentificationCode(identificationCode);
  343. parseDocument4Uncensored(document, identificationCode, liuchuPath, videoInfoUncensored);
  344. videoInfoUncensored.setStatus(2);
  345. videoInfoUncensoredMapper.updateJsoupInfoByCode(videoInfoUncensored);
  346. j++;
  347. log.warn("jsoupVideoInfoUncensored success:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode);
  348. break;
  349. } catch (Exception e) {
  350. ++retryCount;
  351. if (retryCount < 4) {
  352. log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, e);
  353. } else if (retryCount == 4) {
  354. videoInfoUncensoredMapper.updateStatus(identificationCode, 3);
  355. log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode, e);
  356. }
  357. }
  358. }
  359. }
  360. log.warn("jsoupVideoInfoUncensored 统计:total={},success={}", icodeList.size(), j);
  361. }
  362. /**
  363. * Jsoup VideoInfo
  364. *
  365. * @author lvzhiqiang
  366. * 2022/5/5 18:21
  367. */
  368. @Async
  369. @Override
  370. public void jsoupVideoInfo(Integer status) {
  371. log.warn("jsoupVideoInfo 开始:status={}", status);
  372. // 获取待抓取码列表
  373. List<String> icodeList = videoInfoMapper.findIcodeByStatus(status);
  374. if (icodeList.size() == 0) {
  375. log.warn("status={}的icodeList为空", status);
  376. return;
  377. }
  378. // 获取javbus防屏蔽地址
  379. List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
  380. if (javbusUrlList.size() == 0) {
  381. log.warn("javbusUrlList为空");
  382. return;
  383. }
  384. // 获取图片保存路径
  385. String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  386. // 遍历
  387. Document document;
  388. VideoInfo videoInfo;
  389. String javbusUrl;
  390. int j = 0;
  391. for (int i = 0; i < icodeList.size(); i++) {
  392. long start = System.currentTimeMillis();
  393. String identificationCode = icodeList.get(i);
  394. int retryCount = 0;
  395. while (retryCount <= 3) {
  396. javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
  397. try {
  398. document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
  399. .timeout(50000)
  400. //.proxy()
  401. //.data()
  402. .ignoreContentType(true)
  403. .userAgent(getUserAgent())
  404. .header("referer", "https://www.javbus.com/".concat(identificationCode))
  405. .get();
  406. videoInfo = new VideoInfo();
  407. videoInfo.setIdentificationCode(identificationCode);
  408. String picTime = parseDocument4QiBing(document, identificationCode, qibingPath, videoInfo);
  409. videoInfo.setStatus(2);
  410. // 获取男优
  411. getMaleCast(videoInfo);
  412. videoInfoMapper.updateJsoupInfoByCode(videoInfo);
  413. videoInfoOtherMapper.insertOrUpdate(identificationCode, 2);
  414. j++;
  415. log.warn("jsoupVideoInfo success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
  416. break;
  417. } catch (Exception e) {
  418. ++retryCount;
  419. if (retryCount < 4) {
  420. log.error("jsoupVideoInfo error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
  421. } else if (retryCount == 4) {
  422. videoInfoMapper.updateStatus(identificationCode, 3);
  423. log.error("jsoupVideoInfo error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
  424. }
  425. }
  426. }
  427. }
  428. log.warn("jsoupVideoInfo 统计:total={},success={}", icodeList.size(), j);
  429. }
  430. @Override
  431. public void getMaleCast(VideoInfo videoInfo) {
  432. Document document;
  433. try {
  434. Map<String,String> headerMap = new HashMap<>();
  435. headerMap.put("referer", "avdanyuwiki.com");
  436. document = JsoupUtil.requestDocument("https://avdanyuwiki.com/?s=".concat(videoInfo.getName()), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
  437. Elements container = document.select("div#header-container-in");
  438. if (container.size() == 0) {
  439. return;
  440. }
  441. Elements alinks1 = container.select("h4").select("a[rel='bookmark']");
  442. if (alinks1 == null || alinks1.size() == 0) {
  443. return;
  444. }
  445. String alinkhref = alinks1.first().attr("abs:href");
  446. document = JsoupUtil.requestDocument(alinkhref, JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
  447. Elements entrycontent = document.select("div.entry-content");
  448. if (entrycontent.size() == 0) {
  449. return;
  450. }
  451. String[] entrycontentArr = entrycontent.html().split("<br>");
  452. for (String s : entrycontentArr) {
  453. if (s.contains("出演男優")) {
  454. String[] split = s.split(":");
  455. if (split.length < 2) {
  456. return;
  457. }
  458. String maleCasts = s.split(":")[1];
  459. List<String> sssss = new ArrayList<>();
  460. String[] split1 = maleCasts.split(",");
  461. for (String s1 : split1) {
  462. String[] split2 = s1.trim().split("\\s+");
  463. for (String s2 : split2) {
  464. sssss.add(s2.replaceAll(" ", "").trim());
  465. }
  466. }
  467. String maleCast = StringUtils.join(sssss, ",");
  468. videoInfo.setMaleCast(maleCast);
  469. break;
  470. }
  471. }
  472. } catch (Exception e) {
  473. log.error("getMaleCast error,icode={},name={}={}", videoInfo.getIdentificationCode(), videoInfo.getName(), e);
  474. }
  475. }
  476. /**
  477. * 删除影片
  478. *
  479. * @param identificationCode
  480. * @param parentTypeName
  481. * @author lvzhiqiang
  482. * 2022/5/29 12:59
  483. */
  484. @Override
  485. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  486. public void delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
  487. if (StringUtils.isNotEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
  488. if (parentTypeName.contains("类别")) {
  489. String videoGenres = parentTypeName.replace("(类别)", "");
  490. VideoInfoGenres videoInfoGenres = videoInfoGenresMapper.findVideoInfoGenresByCodeAndName(identificationCode, videoGenres);
  491. if ("1".equals(videoInfoGenres.getType())) {
  492. // 主体
  493. throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
  494. } else {
  495. // 链接
  496. videoInfoGenresMapper.deleteById(videoInfoGenres.getId());
  497. }
  498. } else if (parentTypeName.contains("优")) {
  499. String videoCast = "";
  500. if (parentTypeName.contains("(男")) {
  501. videoCast = parentTypeName.replace("(男优)", "");
  502. } else if (parentTypeName.contains("(女")) {
  503. videoCast = parentTypeName.replace("(女优)", "");
  504. }
  505. VideoInfoCast videoInfoCast = videoInfoCastMapper.findVideoInfoCastByCodeAndName(identificationCode, videoCast);
  506. if ("1".equals(videoInfoCast.getType())) {
  507. // 主体
  508. throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
  509. } else {
  510. // 链接
  511. videoInfoCastMapper.deleteById(videoInfoCast.getId());
  512. }
  513. } else {
  514. throw new ParameterException("直属类型不存在");
  515. }
  516. } else if (StringUtils.isEmpty(parentTypeName) && StringUtils.isNotEmpty(allFlag)) {
  517. videoInfoMapper.delByIdentificationCode(identificationCode);
  518. videoInfoCastMapper.deleteByCode(identificationCode);
  519. videoInfoGenresMapper.deleteByCode(identificationCode);
  520. } else {
  521. throw new ParameterException("参数有误");
  522. }
  523. }
  524. /**
  525. * findVideoInfoOther
  526. *
  527. * @author lvzhiqiang
  528. * 2022/9/17 19:17
  529. */
  530. @Override
  531. public String findVideoInfoOther(String identificationCode, String resolutionRatio, Integer original, Integer subtitle, Integer recoding, String crudT) {
  532. if ("2".equals(crudT)) {
  533. identificationCode = identificationCode.trim();
  534. // 更新/新增
  535. int num = videoInfoOtherMapper.findByCode(identificationCode);
  536. if (num == 0) {
  537. videoInfoOtherMapper.insertVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
  538. return "insert success";
  539. }
  540. videoInfoOtherMapper.updateVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
  541. return "update success";
  542. }
  543. if ("3".equals(crudT)) {
  544. identificationCode = identificationCode.trim();
  545. //删除
  546. videoInfoOtherMapper.delByCode(identificationCode);
  547. return "delete success";
  548. }
  549. // 查询
  550. List<VideoInfoOther> videoInfoOtherList = videoInfoOtherMapper.findVideoInfoOther4MultipleParams(identificationCode, resolutionRatio, original, subtitle, recoding);
  551. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoOtherList.size())).concat("<br/>"));
  552. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>序号</th><th>识别码</th><th>评分</th><th>评语</th><th>评语first</th><th>分辨率</th><th>原档</th><th>字幕</th><th>重新编码</th><th>创建时间</th><th>最后修改时间</th></tr>");
  553. int i = 0;
  554. for (VideoInfoOther videoInfoOther : videoInfoOtherList) {
  555. i++;
  556. sb.append("<tr>");
  557. sb.append("<td>").append(i).append("</td>");
  558. sb.append("<td>").append(videoInfoOther.getIdentificationCode()).append("</td>");
  559. sb.append("<td>").append(videoInfoOther.getScore()).append("</td>");
  560. sb.append("<td>").append(videoInfoOther.getComment()).append("</td>");
  561. sb.append("<td>").append(videoInfoOther.getCommentFirst()).append("</td>");
  562. sb.append("<td>").append(videoInfoOther.getResolutionRatio()).append("</td>");
  563. sb.append("<td>").append(videoInfoOther.getOriginal() == null ? "?" : (videoInfoOther.getOriginal() == 1 ? "是" : "否")).append("</td>");
  564. sb.append("<td>").append(videoInfoOther.getSubtitle() == null ? "?" : (videoInfoOther.getSubtitle() == 1 ? "是" : "否")).append("</td>");
  565. sb.append("<td>").append(videoInfoOther.getRecoding() == null ? "?" : (videoInfoOther.getRecoding() == 1 ? "是" : "否")).append("</td>");
  566. sb.append("<td>").append(videoInfoOther.getCreateTime()).append("</td>");
  567. sb.append("<td>").append(videoInfoOther.getModifyTime()).append("</td>");
  568. sb.append("</tr>");
  569. }
  570. sb.append("</table>");
  571. return sb.toString();
  572. }
  573. /**
  574. * 增加影片
  575. *
  576. * @param identificationCode
  577. * @param videoName
  578. * @param parentType
  579. * @param parentName
  580. * @param type
  581. * @author lvzhiqiang
  582. * 2022/9/27 20:54
  583. */
  584. @Override
  585. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  586. public void insertVideoInfo(String identificationCode, String videoName, Integer parentType, String parentName, Integer type) {
  587. String parentFullName;
  588. if (parentType == 1) {
  589. parentFullName = "(类别)" + parentName;
  590. VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
  591. videoInfoGenres.setIdentificationCode(identificationCode);
  592. videoInfoGenres.setName(parentName);
  593. videoInfoGenres.setType(type);
  594. videoInfoGenresMapper.insert(videoInfoGenres);
  595. VideoGenres videoGenres = new VideoGenres();
  596. videoGenres.setName(parentName);
  597. videoGenresMapper.insertOrUpdate(videoGenres);
  598. } else if (parentType == 2) {
  599. parentFullName = "(男优)" + parentName;
  600. VideoInfoCast videoInfoCast = new VideoInfoCast();
  601. videoInfoCast.setIdentificationCode(identificationCode);
  602. videoInfoCast.setName(parentName);
  603. videoInfoCast.setType(type);
  604. videoInfoCastMapper.insert(videoInfoCast);
  605. VideoCast videoCast = new VideoCast();
  606. videoCast.setName(parentName);
  607. videoCast.setType(1);
  608. videoCastMapper.insertOrUpdate(videoCast);
  609. } else if (parentType == 3) {
  610. parentFullName = "(女优)" + parentName;
  611. VideoInfoCast videoInfoCast = new VideoInfoCast();
  612. videoInfoCast.setIdentificationCode(identificationCode);
  613. videoInfoCast.setName(parentName);
  614. videoInfoCast.setType(type);
  615. videoInfoCastMapper.insert(videoInfoCast);
  616. VideoCast videoCast = new VideoCast();
  617. videoCast.setName(parentName);
  618. videoCast.setType(2);
  619. videoCastMapper.insertOrUpdate(videoCast);
  620. } else {
  621. throw new RuntimeException("parentType类型错误");
  622. }
  623. // 主体
  624. if (type == 1) {
  625. VideoInfo videoInfo = new VideoInfo();
  626. videoInfo.setIdentificationCode(identificationCode);
  627. videoInfo.setType(1);
  628. // 视频URL
  629. videoInfo.setVideoUrl(parentFullName.concat("/").concat(videoName));
  630. // 修改时间
  631. videoInfo.setCreateTime(LocalDateTime.now());
  632. // 主体是谁
  633. videoInfo.setMainWho(parentFullName);
  634. videoInfoMapper.insertOrUpdate(videoInfo);
  635. }
  636. }
  637. /**
  638. * 初始化骑兵数据
  639. */
  640. @Override
  641. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  642. @Async
  643. public void initVideoInfoData(Integer type, Integer isDel, String infantryType) {
  644. long startTime = System.currentTimeMillis();
  645. DicCode dicCode = null;
  646. if (type == 1) {
  647. dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "qibing_path".equals(x.getCodeKey())).findFirst().get();
  648. } else if (type == 3) {
  649. dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get();
  650. } else if (type == 2) {
  651. dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "bubing_path".equals(x.getCodeKey())).findFirst().get();
  652. }
  653. if (dicCode == null) {
  654. return;
  655. }
  656. String picPath = dicCode.getCodeValue();
  657. if (type == 1) {
  658. JavAllInfo javAllInfo = new JavAllInfo();
  659. // 删除所有
  660. if (isDel == 1) {
  661. videoGenresMapper.deleteAll();
  662. videoInfoMapper.deleteAll();
  663. videoCastMapper.deleteAll();
  664. videoInfoGenresMapper.deleteAll();
  665. videoInfoCastMapper.deleteAll();
  666. }
  667. ignoreFileTypeSuffix = dicCodeMapper.findByCodeKey("ignore_filetype_suffix", null).stream()
  668. .filter(x -> x.getEnv().contains(env)).findFirst().get().getCodeValue();
  669. List<String> allIcode = videoInfoMapper.findAllIcode();
  670. getAllFilePaths(picPath, javAllInfo, allIcode);
  671. saveInfo(javAllInfo, isDel);
  672. } else if (type == 3) {
  673. JavAllInfo4Uncensored javAllInfo4Uncensored = new JavAllInfo4Uncensored();
  674. getAllFilePaths4Uncensored(picPath, javAllInfo4Uncensored);
  675. saveInfo4Uncensored(javAllInfo4Uncensored, isDel);
  676. } else if (type == 2) {
  677. JavAllInfo4Infantry javAllInfo4Infantry = new JavAllInfo4Infantry();
  678. picPath = picPath.concat(infantryType);
  679. getAllFilePaths4Infantry(picPath, javAllInfo4Infantry, infantryType);
  680. saveInfo4Infantry(javAllInfo4Infantry, isDel, infantryType);
  681. }
  682. long endTime = System.currentTimeMillis();
  683. System.err.println((endTime - startTime) / 1000);
  684. }
  685. /**
  686. * 上传识别码文件
  687. *
  688. * @param is
  689. */
  690. @Override
  691. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  692. @Async
  693. public void uploadFile4IdentificationCode(InputStream is, Integer isDel) {
  694. if (isDel == 1) {
  695. icodePoolMapper.deleteAll();
  696. }
  697. List<String> uploadIcodeList = readFromIcodeStream(is);
  698. List<String> icodePoolList = icodePoolMapper.findIcode();
  699. // 过滤库中已存在的
  700. Integer beforeUploadSize = uploadIcodeList.size();
  701. uploadIcodeList.removeAll(icodePoolList);
  702. log.warn("uploadFile4IdentificationCode:beforeUpload={},icodePool={},afterUpload={}", beforeUploadSize, icodePoolList.size(), uploadIcodeList.size());
  703. // 插入
  704. int num = 0;
  705. if (uploadIcodeList.size() > 0) {
  706. num = icodePoolMapper.insertList(uploadIcodeList);
  707. }
  708. log.warn("uploadFile4IdentificationCode:success={}", num);
  709. }
  710. /**
  711. * 单个识别码
  712. *
  713. * @param identificationCode
  714. */
  715. @Override
  716. public void single4IdentificationCode(String identificationCode) {
  717. List<String> icodePoolList = icodePoolMapper.findIcode();
  718. identificationCode = identificationCode.trim().toUpperCase();
  719. if (icodePoolList.contains(identificationCode)) {
  720. throw new BusinessException(ResultCodeEnum.PARAM_DATA_EXIST_ERROR);
  721. }
  722. icodePoolMapper.insert(identificationCode);
  723. }
  724. /**
  725. * Jsoup IcodePool
  726. *
  727. * @param status
  728. */
  729. @Async
  730. @Override
  731. public void jsoupIcodePool(Integer status, Integer isDel, Integer ignoreRetryCount) {
  732. log.warn("jsoupIcodePool 开始:status={},isDel={},ignoreRetryCount={}", status, isDel, ignoreRetryCount);
  733. if (isDel == 1) {
  734. videoInfoPoolMapper.deleteAll();
  735. }
  736. // 获取待抓取码列表
  737. List<String> icodePoolList;
  738. if (1 == ignoreRetryCount) {
  739. icodePoolList = icodePoolMapper.findIcodeByStatus4IgnoreRetryCount(status);
  740. } else {
  741. icodePoolList = icodePoolMapper.findIcodeByStatus(status);
  742. }
  743. if (icodePoolList.size() == 0) {
  744. log.warn("status={}的icodePoolList为空", status);
  745. return;
  746. }
  747. // 获取javbus防屏蔽地址
  748. List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
  749. if (javbusUrlList.size() == 0) {
  750. log.warn("javbusUrlList为空");
  751. return;
  752. }
  753. // 获取主表所有识别码
  754. List<String> allIcode = videoInfoMapper.findAllIcode();
  755. // 获取码池图片保存路径
  756. String machiPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  757. // 遍历
  758. Document document;
  759. VideoInfoPool videoInfoPool;
  760. String javbusUrl;
  761. int j = 0;
  762. for (int i = 0; i < icodePoolList.size(); i++) {
  763. long start = System.currentTimeMillis();
  764. String identificationCode = icodePoolList.get(i);
  765. IcodePool icodePool = new IcodePool();
  766. icodePool.setIdentificationCode(identificationCode);
  767. if (allIcode.contains(identificationCode)) {
  768. icodePool.setStatus(4);
  769. icodePool.setRetryCount(0);
  770. icodePoolMapper.updateStatus(icodePool);
  771. log.warn("jsoupIcodePool exists:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode);
  772. continue;
  773. }
  774. int retryCount = 0;
  775. while (retryCount <= 3) {
  776. javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
  777. try {
  778. document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
  779. .timeout(50000)
  780. //.proxy()
  781. //.data()
  782. .ignoreContentType(true)
  783. .userAgent(getUserAgent())
  784. .header("referer", javbusUrl.concat("/").concat(identificationCode))
  785. .get();
  786. videoInfoPool = new VideoInfoPool();
  787. long picTime = parseDocument(document, identificationCode, machiPath, videoInfoPool);
  788. if (videoInfoPool != null) {
  789. icodePool.setStatus(2);
  790. icodePool.setRetryCount(retryCount);
  791. icodePoolMapper.updateStatus(icodePool);
  792. videoInfoPoolMapper.insert(videoInfoPool);
  793. j++;
  794. }
  795. log.warn("jsoupIcodePool success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
  796. break;
  797. } catch (Exception e) {
  798. ++retryCount;
  799. if (retryCount < 4) {
  800. log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
  801. } else if (retryCount == 4) {
  802. icodePool.setStatus(3);
  803. icodePool.setRetryCount(retryCount - 1);
  804. icodePool.setFailureCause(e.getMessage().length() <= 200 ? e.getMessage() : e.getMessage().substring(0, 200));
  805. icodePoolMapper.updateStatus(icodePool);
  806. log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode, e);
  807. }
  808. }
  809. }
  810. }
  811. log.warn("jsoupIcodePool 统计:total={},success={}", icodePoolList.size(), j);
  812. }
  813. private String getUserAgent() {
  814. Random r = new Random();
  815. String[] ua = {"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
  816. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36 OPR/37.0.2178.32",
  817. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
  818. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
  819. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586",
  820. "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
  821. "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
  822. "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
  823. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)",
  824. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 BIDUBrowser/8.3 Safari/537.36",
  825. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36 Core/1.47.277.400 QQBrowser/9.4.7658.400",
  826. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 UBrowser/5.6.12150.8 Safari/537.36",
  827. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0",
  828. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 TheWorld 7",
  829. "Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/60.0",
  830. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"};
  831. int i = r.nextInt(15);
  832. return ua[i];
  833. }
  834. private long parseDocument(Document document, String identificationCode, String machiPath, VideoInfoPool videoInfoPool) throws Exception {
  835. Elements container = document.select("div.container");
  836. if (container.size() == 0) {
  837. throw new Exception("番号无效!");
  838. }
  839. // 名称
  840. String h3 = container.select("h3").first().text().replace("/", "");
  841. String[] nameArr = h3.split("\\s+");
  842. if (nameArr.length > 1) {
  843. videoInfoPool.setName(h3.substring(nameArr[0].length()).trim());
  844. } else {
  845. videoInfoPool.setName(nameArr[0]);
  846. }
  847. Elements pEles = container.select("div.info > p");
  848. // 识别码
  849. Element pEle = pEles.get(0);
  850. String iCode = pEle.select("span[style]").first().text();
  851. if (!identificationCode.equalsIgnoreCase(iCode)) {
  852. throw new Exception("番号与站点不一致");
  853. }
  854. videoInfoPool.setIdentificationCode(iCode);
  855. // 发行日期
  856. pEle = pEles.get(1);
  857. String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
  858. videoInfoPool.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  859. // 长度
  860. pEle = pEles.get(2);
  861. String length = pEle.text().split(":")[1].replace("\"", "").trim();
  862. videoInfoPool.setLength(length);
  863. // 导演
  864. Elements directorEles = container.select("div.info").select("p:contains(導演)");
  865. if (directorEles.size() > 0) {
  866. pEle = directorEles.first().select("a[href]").first();
  867. videoInfoPool.setDirector(pEle.text());
  868. }
  869. // 制作商
  870. Elements markerEles = container.select("div.info").select("p:contains(製作商)");
  871. if (markerEles.size() > 0) {
  872. pEle = markerEles.first().select("a[href]").first();
  873. videoInfoPool.setMaker(pEle.text());
  874. }
  875. // 发行商
  876. Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
  877. if (issuerEles.size() > 0) {
  878. pEle = issuerEles.first().select("a[href]").first();
  879. videoInfoPool.setIssuer(pEle.text());
  880. }
  881. // 类别
  882. Elements genresEles = container.select("div.info").select("p:contains(類別)");
  883. if (genresEles.size() > 0) {
  884. StringBuffer sb = new StringBuffer();
  885. Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
  886. for (Element ahrefEle : ahrefEles) {
  887. sb.append(ahrefEle.text()).append(",");
  888. }
  889. if (sb.length() > 0) {
  890. sb = sb.deleteCharAt(sb.length() - 1);
  891. }
  892. videoInfoPool.setGenres(sb.toString());
  893. }
  894. // 演员
  895. Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
  896. if (castEles.size() > 0) {
  897. Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
  898. if (castElesTemp.size() == 0) {
  899. StringBuffer sb = new StringBuffer();
  900. Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
  901. for (Element ahrefEle : ahrefEles) {
  902. sb.append(ahrefEle.text()).append(",");
  903. }
  904. if (sb.length() > 0) {
  905. sb = sb.deleteCharAt(sb.length() - 1);
  906. }
  907. videoInfoPool.setCast(sb.toString());
  908. }
  909. }
  910. // 图片URL
  911. String href = container.select("a.bigImage").first().attr("abs:href");
  912. long start = System.currentTimeMillis();
  913. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  914. String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
  915. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  916. if (imgUrlBytes.length > 251) {
  917. byte[] imgUrlDestBytes = new byte[251];
  918. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  919. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  920. }
  921. fileName = fileName.concat(".jpg");
  922. String machiImgUrl = "码池/".concat(fileName);
  923. saveFile(response.bodyStream(), machiPath.concat(machiImgUrl));
  924. long end = System.currentTimeMillis();
  925. videoInfoPool.setImgUrl(machiImgUrl);
  926. videoInfoPool.setCreateTime(LocalDateTime.now());
  927. videoInfoPool.setType(1);
  928. return end - start;
  929. }
  930. private void parseDocument4Uncensored(Document document, String identificationCode, String machiPath, VideoInfoUncensored videoInfoUncensored) throws Exception {
  931. Elements container = document.select("div.container");
  932. if (container.size() == 0) {
  933. throw new Exception("番号无效!");
  934. }
  935. Elements pEles = container.select("div.info > p");
  936. // 识别码
  937. Element pEle = pEles.get(0);
  938. String iCode = pEle.select("span[style]").first().text();
  939. if (!identificationCode.equalsIgnoreCase(iCode)) {
  940. throw new Exception("番号与站点不一致");
  941. }
  942. // 长度
  943. pEle = pEles.get(2);
  944. String length = pEle.text().split(":")[1].replace("\"", "").trim();
  945. videoInfoUncensored.setLength(length);
  946. // 导演
  947. Elements directorEles = container.select("div.info").select("p:contains(導演)");
  948. if (directorEles.size() > 0) {
  949. pEle = directorEles.first().select("a[href]").first();
  950. videoInfoUncensored.setDirector(pEle.text());
  951. }
  952. // 制作商
  953. Elements markerEles = container.select("div.info").select("p:contains(製作商)");
  954. if (markerEles.size() > 0) {
  955. pEle = markerEles.first().select("a[href]").first();
  956. videoInfoUncensored.setMaker(pEle.text());
  957. }
  958. // 发行商
  959. Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
  960. if (issuerEles.size() > 0) {
  961. pEle = issuerEles.first().select("a[href]").first();
  962. videoInfoUncensored.setIssuer(pEle.text());
  963. }
  964. // 类别
  965. Elements genresEles = container.select("div.info").select("p:contains(類別)");
  966. if (genresEles.size() > 0) {
  967. StringBuffer sb = new StringBuffer();
  968. Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
  969. for (Element ahrefEle : ahrefEles) {
  970. sb.append(ahrefEle.text()).append(",");
  971. }
  972. if (sb.length() > 0) {
  973. sb = sb.deleteCharAt(sb.length() - 1);
  974. }
  975. videoInfoUncensored.setGenres(sb.toString());
  976. }
  977. // 演员
  978. Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
  979. if (castEles.size() > 0) {
  980. Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
  981. if (castElesTemp.size() == 0) {
  982. StringBuffer sb = new StringBuffer();
  983. Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
  984. for (Element ahrefEle : ahrefEles) {
  985. sb.append(ahrefEle.text()).append(",");
  986. }
  987. if (sb.length() > 0) {
  988. sb = sb.deleteCharAt(sb.length() - 1);
  989. }
  990. videoInfoUncensored.setCast(sb.toString());
  991. }
  992. }
  993. }
  994. private String parseDocument4QiBing(Document document, String identificationCode, String qibingPath, VideoInfo videoInfo) throws Exception {
  995. Elements container = document.select("div.container");
  996. if (container.size() == 0) {
  997. throw new Exception("番号无效!");
  998. }
  999. // 名称
  1000. String h3 = container.select("h3").first().text();
  1001. String[] nameArr = h3.split("\\s+");
  1002. if (nameArr.length > 1) {
  1003. videoInfo.setName(h3.substring(nameArr[0].length()).trim());
  1004. } else {
  1005. videoInfo.setName(nameArr[0]);
  1006. }
  1007. Elements pEles = container.select("div.info > p");
  1008. // 识别码
  1009. Element pEle = pEles.get(0);
  1010. String iCode = pEle.select("span[style]").first().text();
  1011. if (!identificationCode.equalsIgnoreCase(iCode)) {
  1012. throw new Exception("番号与站点不一致");
  1013. }
  1014. // 发行日期
  1015. pEle = pEles.get(1);
  1016. String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
  1017. videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1018. // 长度
  1019. pEle = pEles.get(2);
  1020. String length = pEle.text().split(":")[1].replace("\"", "").trim();
  1021. videoInfo.setLength(length);
  1022. // 导演
  1023. Elements directorEles = container.select("div.info").select("p:contains(導演)");
  1024. if (directorEles.size() > 0) {
  1025. pEle = directorEles.first().select("a[href]").first();
  1026. videoInfo.setDirector(pEle.text());
  1027. }
  1028. // 制作商
  1029. Elements markerEles = container.select("div.info").select("p:contains(製作商)");
  1030. if (markerEles.size() > 0) {
  1031. pEle = markerEles.first().select("a[href]").first();
  1032. videoInfo.setMaker(pEle.text());
  1033. }
  1034. // 发行商
  1035. Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
  1036. if (issuerEles.size() > 0) {
  1037. pEle = issuerEles.first().select("a[href]").first();
  1038. videoInfo.setIssuer(pEle.text());
  1039. }
  1040. // 类别
  1041. Elements genresEles = container.select("div.info").select("p:contains(類別)");
  1042. if (genresEles.size() > 0) {
  1043. StringBuffer sb = new StringBuffer();
  1044. Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
  1045. for (Element ahrefEle : ahrefEles) {
  1046. sb.append(ahrefEle.text()).append(",");
  1047. }
  1048. if (sb.length() > 0) {
  1049. sb = sb.deleteCharAt(sb.length() - 1);
  1050. }
  1051. videoInfo.setGenres(sb.toString());
  1052. }
  1053. // 演员
  1054. Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
  1055. if (castEles.size() > 0) {
  1056. Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
  1057. if (castElesTemp.size() == 0) {
  1058. StringBuffer sb = new StringBuffer();
  1059. Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
  1060. for (Element ahrefEle : ahrefEles) {
  1061. sb.append(ahrefEle.text()).append(",");
  1062. }
  1063. if (sb.length() > 0) {
  1064. sb = sb.deleteCharAt(sb.length() - 1);
  1065. }
  1066. videoInfo.setCast(sb.toString());
  1067. }
  1068. }
  1069. // 图片 骑兵步兵
  1070. String qibings = "骑兵步兵/".concat(iCode);
  1071. StringBuffer picTime = new StringBuffer("{cover:");
  1072. // 图片URL bigImage
  1073. String qibingCover = qibings.concat("/cover/");
  1074. String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
  1075. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  1076. if (imgUrlBytes.length > 251) {
  1077. byte[] imgUrlDestBytes = new byte[251];
  1078. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  1079. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  1080. }
  1081. fileName = fileName.concat(".jpg");
  1082. if (!new File(qibingPath.concat(qibingCover), fileName).exists()) {
  1083. String href = container.select("a.bigImage").first().attr("abs:href");
  1084. long start = System.currentTimeMillis();
  1085. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1086. saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
  1087. picTime.append(System.currentTimeMillis() - start).append(",");
  1088. }
  1089. videoInfo.setImgUrl(qibingCover.concat(fileName));
  1090. // 图片URL img_gf
  1091. String qibingImgGF = qibings.concat("/img_gf/");
  1092. File qibingImgGFFile = new File(qibingPath.concat(qibingImgGF));
  1093. if (!qibingImgGFFile.exists() || qibingImgGFFile.listFiles().length == 0) {
  1094. Elements sampleBoxEles = container.select("div#sample-waterfall").select("a");
  1095. long start2 = System.currentTimeMillis();
  1096. if (sampleBoxEles.size() > 0) {
  1097. Connection.Response responseImg;
  1098. for (Element sampleBoxEle : sampleBoxEles) {
  1099. String sampleBoxHref = sampleBoxEle.attr("href");
  1100. if (!sampleBoxHref.contains("http")) {
  1101. sampleBoxHref = sampleBoxEle.attr("abs:href");
  1102. }
  1103. try {
  1104. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1105. } catch (HttpStatusException e) {
  1106. sampleBoxHref = sampleBoxEle.select("img").attr("src");
  1107. if (!sampleBoxHref.contains("http")) {
  1108. sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
  1109. }
  1110. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1111. }
  1112. String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
  1113. saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
  1114. }
  1115. } else {
  1116. log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
  1117. }
  1118. picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
  1119. }
  1120. return picTime.toString();
  1121. }
  1122. /**
  1123. * 保存文件到本地2
  1124. *
  1125. * @param bufferedInputStream
  1126. * @param savePathPrex
  1127. * @param fileName
  1128. */
  1129. private void saveFile2(BufferedInputStream bufferedInputStream, String savePathPrex, String fileName) throws IOException {
  1130. File savePathPrexFile = new File(savePathPrex);
  1131. // 判断目录是否存在,如果不存在则新建
  1132. if (!savePathPrexFile.exists()) {
  1133. boolean result = savePathPrexFile.mkdirs();
  1134. if (!result) {
  1135. throw new IOException("创建目录失败!");
  1136. }
  1137. }
  1138. //一次最多读取1k
  1139. byte[] buffer = new byte[1024];
  1140. //实际读取的长度
  1141. int readLenghth;
  1142. //创建的一个写出的缓冲流
  1143. BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePathPrexFile, fileName)));
  1144. //文件逐步写入本地
  1145. while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
  1146. bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
  1147. }
  1148. //关闭缓冲流
  1149. bufferedOutputStream.close();
  1150. bufferedInputStream.close();
  1151. }
  1152. /**
  1153. * 保存文件到本地
  1154. *
  1155. * @param bufferedInputStream
  1156. * @param savePath
  1157. */
  1158. private void saveFile(BufferedInputStream bufferedInputStream, String savePath) throws IOException {
  1159. //一次最多读取1k
  1160. byte[] buffer = new byte[1024];
  1161. //实际读取的长度
  1162. int readLenghth;
  1163. //创建的一个写出的缓冲流
  1164. BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePath)));
  1165. //文件逐步写入本地
  1166. while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
  1167. bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
  1168. }
  1169. //关闭缓冲流
  1170. bufferedOutputStream.close();
  1171. bufferedInputStream.close();
  1172. }
  1173. // 递归获取某目录下的所有子目录以及子文件
  1174. private void getAllFilePaths(String filePath, JavAllInfo javAllInfo, List<String> allIcode) {
  1175. File[] files = new File(filePath).listFiles();
  1176. if (files == null) {
  1177. return;
  1178. }
  1179. int type = 0;
  1180. if (filePath.contains("骑兵")) {
  1181. type = 1;
  1182. } else if (filePath.contains("步兵")) {
  1183. type = 2;
  1184. }
  1185. Set<String> sameNameSet = new HashSet<>();
  1186. for (File file : files) {
  1187. if (file.isDirectory()) {
  1188. // 文件夹
  1189. getAllFilePaths(file.getAbsolutePath(), javAllInfo, allIcode);
  1190. } else {
  1191. String fileName = file.getName();
  1192. String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
  1193. if (!ignoreFileTypeSuffix.contains(fileSuffix)) {
  1194. String parentName = file.getParentFile().getName();
  1195. // 识别码
  1196. String name = fileName.substring(10, fileName.lastIndexOf(".")).trim();
  1197. String[] nameArr = name.split("\\s+");
  1198. try {
  1199. boolean isMain = false;
  1200. if (!fileName.endsWith(".lnk")) {
  1201. if (allIcode.contains(nameArr[0]) || sameNameSet.contains(nameArr[0])) {
  1202. continue;
  1203. }
  1204. isMain = true;
  1205. // 获取正片信息
  1206. VideoInfo videoInfo = new VideoInfo();
  1207. // 发行日期
  1208. //String issueDate = fileName.substring(0, 10);
  1209. //videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1210. // 识别码
  1211. videoInfo.setIdentificationCode(nameArr[0]);
  1212. // 名称
  1213. //if (nameArr.length > 1) {
  1214. // videoInfo.setName(name.substring(nameArr[0].length()).trim());
  1215. //} else {
  1216. // videoInfo.setName(nameArr[0]);
  1217. //}
  1218. // 类型
  1219. videoInfo.setType(type);
  1220. // 图片URL
  1221. //videoInfo.setImgUrl(parentName.concat("/").concat(fileName));
  1222. // 视频URL
  1223. videoInfo.setVideoUrl(parentName.concat("/").concat(fileName));
  1224. // 创建时间 TODO
  1225. // 修改时间
  1226. videoInfo.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
  1227. // 主体是谁
  1228. videoInfo.setMainWho(parentName);
  1229. javAllInfo.getVideoInfoList().add(videoInfo);
  1230. sameNameSet.add(nameArr[0]);
  1231. }
  1232. if (parentName.contains("类别")) {
  1233. // 获取类别
  1234. String videoGenres = parentName.replace("(类别)", "");
  1235. javAllInfo.getVideoGenresSet().add(videoGenres);
  1236. VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
  1237. videoInfoGenres.setIdentificationCode(nameArr[0]);
  1238. videoInfoGenres.setName(videoGenres);
  1239. videoInfoGenres.setType(isMain ? 1 : 2);
  1240. javAllInfo.getVideoInfoGenresSet().add(videoInfoGenres);
  1241. } else if (parentName.contains("优)")) {
  1242. // 获取演员
  1243. String videoCast = "";
  1244. if (parentName.contains("(男")) {
  1245. videoCast = parentName.replace("(男优)", "");
  1246. javAllInfo.getVideoCastMap().put(videoCast, "1");
  1247. } else if (parentName.contains("(女")) {
  1248. videoCast = parentName.replace("(女优)", "");
  1249. javAllInfo.getVideoCastMap().put(videoCast, "2");
  1250. }
  1251. VideoInfoCast videoInfoCast = new VideoInfoCast();
  1252. videoInfoCast.setIdentificationCode(nameArr[0]);
  1253. videoInfoCast.setName(videoCast);
  1254. videoInfoCast.setType(isMain ? 1 : 2);
  1255. javAllInfo.getVideoInfoCastSet().add(videoInfoCast);
  1256. }
  1257. } catch (Exception e) {
  1258. System.err.println("error:" + file.getAbsolutePath());
  1259. System.err.println("error reason:" + e.getMessage());
  1260. }
  1261. } else {
  1262. System.out.println("other type file:" + file.getAbsolutePath());
  1263. }
  1264. }
  1265. }
  1266. }
  1267. private void getAllFilePaths4Uncensored(String filePath, JavAllInfo4Uncensored javAllInfo4Uncensored) {
  1268. File[] files = new File(filePath).listFiles();
  1269. if (files == null) {
  1270. return;
  1271. }
  1272. for (File file : files) {
  1273. if (file.isDirectory()) {
  1274. // 文件夹
  1275. getAllFilePaths4Uncensored(file.getAbsolutePath(), javAllInfo4Uncensored);
  1276. } else {
  1277. String fileName = file.getName();
  1278. if (fileName.endsWith(".jpg")) {
  1279. String parentName = file.getParentFile().getName();
  1280. // 识别码
  1281. String name = fileName.substring(10).replace(".jpg", "").trim();
  1282. String[] nameArr = name.split("\\s+");
  1283. try {
  1284. // 获取正片信息
  1285. VideoInfoUncensored videoInfoUncensored = new VideoInfoUncensored();
  1286. // 发行日期
  1287. String issueDate = fileName.substring(0, 10);
  1288. videoInfoUncensored.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1289. videoInfoUncensored.setIdentificationCode(nameArr[0]);
  1290. // 名称
  1291. if (nameArr.length > 1) {
  1292. videoInfoUncensored.setName(name.substring(nameArr[0].length()).trim());
  1293. } else {
  1294. videoInfoUncensored.setName(nameArr[0]);
  1295. }
  1296. // 类型
  1297. videoInfoUncensored.setStatus(1);
  1298. // 图片URL
  1299. videoInfoUncensored.setImgUrl(parentName.concat("/").concat(fileName));
  1300. // 创建时间 TODO
  1301. // 修改时间
  1302. videoInfoUncensored.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
  1303. // 主体是谁
  1304. videoInfoUncensored.setMainWho(parentName);
  1305. javAllInfo4Uncensored.getVideoInfoUncensoredList().add(videoInfoUncensored);
  1306. System.out.println("success:" + file.getAbsolutePath());
  1307. } catch (Exception e) {
  1308. System.err.println("error:" + file.getAbsolutePath());
  1309. System.err.println("error reason:" + e.getMessage());
  1310. }
  1311. } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt")) {
  1312. String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
  1313. String parentName = file.getParentFile().getName();
  1314. javAllInfo4Uncensored.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
  1315. }
  1316. }
  1317. }
  1318. }
  1319. private void getAllFilePaths4Infantry(String filePath, JavAllInfo4Infantry javAllInfo4Infantry, String infantryType) {
  1320. File[] files = new File(filePath).listFiles();
  1321. if (files == null) {
  1322. return;
  1323. }
  1324. for (File file : files) {
  1325. if (file.isDirectory()) {
  1326. // 文件夹
  1327. getAllFilePaths4Infantry(file.getAbsolutePath(), javAllInfo4Infantry, infantryType);
  1328. } else {
  1329. String fileName = file.getName();
  1330. if (fileName.endsWith(".jpg")) {
  1331. String parentName = file.getParentFile().getName();
  1332. // 识别码
  1333. String name = fileName.substring(10).replace(".jpg", "").trim();
  1334. String[] nameArr = name.split("\\s+");
  1335. try {
  1336. // 获取正片信息
  1337. VideoInfoInfantry videoInfoInfantry = new VideoInfoInfantry();
  1338. // 发行日期
  1339. String issueDate = fileName.substring(0, 10);
  1340. videoInfoInfantry.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1341. videoInfoInfantry.setIdentificationCode(nameArr[0]);
  1342. // 名称
  1343. if (nameArr.length > 1) {
  1344. videoInfoInfantry.setName(name.substring(nameArr[0].length()).trim());
  1345. } else {
  1346. videoInfoInfantry.setName(nameArr[0]);
  1347. }
  1348. // 状态
  1349. videoInfoInfantry.setStatus(1);
  1350. // 类型
  1351. videoInfoInfantry.setType(infantryType);
  1352. // 图片URL
  1353. videoInfoInfantry.setImgUrl(parentName.concat("/").concat(fileName));
  1354. // 创建时间 TODO
  1355. // 修改时间
  1356. videoInfoInfantry.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
  1357. // 主体是谁
  1358. videoInfoInfantry.setMainWho(parentName);
  1359. javAllInfo4Infantry.getVideoInfoInfantryList().add(videoInfoInfantry);
  1360. System.out.println("success:" + file.getAbsolutePath());
  1361. } catch (Exception e) {
  1362. System.err.println("error:" + file.getAbsolutePath());
  1363. System.err.println("error reason:" + e.getMessage());
  1364. }
  1365. } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt") && !fileName.endsWith(".txt")) {
  1366. String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
  1367. String parentName = file.getParentFile().getName();
  1368. javAllInfo4Infantry.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
  1369. }
  1370. }
  1371. }
  1372. }
  1373. // 保存所有文件
  1374. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  1375. public void saveInfo(JavAllInfo javAllInfo, Integer isDel) {
  1376. // 保存分类
  1377. Set<String> videoGenresSet = javAllInfo.getVideoGenresSet();
  1378. //List<VideoGenres> videoGenresList = new ArrayList<>();
  1379. for (String s : videoGenresSet) {
  1380. VideoGenres videoGenres = new VideoGenres();
  1381. videoGenres.setName(s);
  1382. videoGenresMapper.insertOrUpdate(videoGenres);
  1383. System.out.println(videoGenres);
  1384. //videoGenresList.add(videoGenres);
  1385. }
  1386. //Map<String, VideoGenres> stringVideoGenresMap = videoGenresList.stream().collect(Collectors.toMap(VideoGenres::getName, Function.identity(), (k1, k2) -> k2));
  1387. // 保存演员
  1388. Map<String, String> videoCastMap = javAllInfo.getVideoCastMap();
  1389. //List<VideoCast> videoCastList = new ArrayList<>();
  1390. for (Map.Entry<String, String> entry : videoCastMap.entrySet()) {
  1391. VideoCast videoCast = new VideoCast();
  1392. videoCast.setName(entry.getKey());
  1393. videoCast.setType(Integer.parseInt(entry.getValue()));
  1394. videoCastMapper.insertOrUpdate(videoCast);
  1395. System.out.println(videoCast);
  1396. //videoCastList.add(videoCast);
  1397. }
  1398. // Map<String, VideoCast> stringVideoCastMap = videoCastList.stream().collect(Collectors.toMap(VideoCast::getName, Function.identity(), (k1, k2) -> k2));
  1399. // 保存影片信息
  1400. List<VideoInfo> videoInfoList = javAllInfo.getVideoInfoList();
  1401. //Map<String, String> videoUrlMap = javAllInfo.getVideoUrlMap();
  1402. //videoInfoList.parallelStream().forEach(e -> {
  1403. // e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
  1404. //});
  1405. //for (VideoInfo videoInfo : videoInfoList) {
  1406. // try {
  1407. // videoInfoMapper.insert(videoInfo);
  1408. // System.out.println("success:" + videoInfo);
  1409. // } catch (Exception e) {
  1410. // e.printStackTrace();
  1411. // System.out.println("error:" + videoInfo);
  1412. // }
  1413. //}
  1414. int videoInfoCount = videoInfoMapper.insertList(videoInfoList);
  1415. System.out.println("videoInfoCount:" + videoInfoCount);
  1416. // 保存影片类别关联信息
  1417. Set<VideoInfoGenres> videoInfoGenresSet = javAllInfo.getVideoInfoGenresSet();
  1418. videoInfoGenresMapper.insertOrUpdate(videoInfoGenresSet);
  1419. // 保存影片类别关联信息
  1420. Set<VideoInfoCast> videoInfoCastSet = javAllInfo.getVideoInfoCastSet();
  1421. videoInfoCastMapper.insertOrUpdate(videoInfoCastSet);
  1422. }
  1423. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  1424. public void saveInfo4Uncensored(JavAllInfo4Uncensored javAllInfo4Uncensored, Integer isDel) {
  1425. // 删除所有
  1426. if (isDel == 1) {
  1427. videoInfoUncensoredMapper.deleteAll();
  1428. }
  1429. List<String> allIcode = videoInfoUncensoredMapper.findAllIcode();
  1430. // 保存影片信息
  1431. List<VideoInfoUncensored> videoInfoUncensoredList = javAllInfo4Uncensored.getVideoInfoUncensoredList();
  1432. int videoInfoUncensoredListBefore = videoInfoUncensoredList.size();
  1433. Map<String, String> videoUrlMap = javAllInfo4Uncensored.getVideoUrlMap();
  1434. Iterator<VideoInfoUncensored> iterator = videoInfoUncensoredList.iterator();
  1435. while (iterator.hasNext()) {
  1436. if (allIcode.contains(iterator.next().getIdentificationCode())) {
  1437. iterator.remove();
  1438. }
  1439. }
  1440. videoInfoUncensoredList.parallelStream().forEach(e -> {
  1441. e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
  1442. });
  1443. System.out.println("videoInfoUncensoredListBefore:" + videoInfoUncensoredListBefore + ",videoInfoUncensoredListAfter:" + videoInfoUncensoredList.size());
  1444. int videoInfoCount = 0;
  1445. if (videoInfoUncensoredList.size() > 0) {
  1446. videoInfoCount = videoInfoUncensoredMapper.insertList(videoInfoUncensoredList);
  1447. }
  1448. System.out.println("videoInfoCount:" + videoInfoCount);
  1449. }
  1450. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  1451. public void saveInfo4Infantry(JavAllInfo4Infantry javAllInfo4Infantry, Integer isDel, String infantryType) {
  1452. // 删除所有
  1453. if (isDel == 1) {
  1454. videoInfoInfantryMapper.deleteAll();
  1455. }
  1456. List<String> allIcode = videoInfoInfantryMapper.findAllIcode(infantryType);
  1457. // 保存影片信息
  1458. List<VideoInfoInfantry> videoInfoInfantryList = javAllInfo4Infantry.getVideoInfoInfantryList();
  1459. int videoInfoInfantryListBefore = videoInfoInfantryList.size();
  1460. Map<String, String> videoUrlMap = javAllInfo4Infantry.getVideoUrlMap();
  1461. Iterator<VideoInfoInfantry> iterator = videoInfoInfantryList.iterator();
  1462. while (iterator.hasNext()) {
  1463. if (allIcode.contains(iterator.next().getIdentificationCode())) {
  1464. iterator.remove();
  1465. }
  1466. }
  1467. videoInfoInfantryList.parallelStream().forEach(e -> {
  1468. e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
  1469. });
  1470. System.out.println("videoInfoInfantryListBefore:" + videoInfoInfantryListBefore + ",videoInfoInfantryListAfter:" + videoInfoInfantryList.size());
  1471. int videoInfoCount = 0;
  1472. if (videoInfoInfantryList.size() > 0) {
  1473. videoInfoCount = videoInfoInfantryMapper.insertList(videoInfoInfantryList);
  1474. }
  1475. System.out.println("videoInfoCount:" + videoInfoCount);
  1476. }
  1477. private List<String> readFromIcodeStream(InputStream inputStream) {
  1478. List<String> list = new ArrayList<>();
  1479. BufferedReader br = null;
  1480. try {
  1481. br = new BufferedReader(new InputStreamReader(inputStream));
  1482. String line;
  1483. while ((line = br.readLine()) != null) {
  1484. if (StringUtils.isNotEmpty(line)) {
  1485. list.add(line.trim().toUpperCase());
  1486. }
  1487. }
  1488. } catch (FileNotFoundException e) {
  1489. e.printStackTrace();
  1490. } catch (IOException e) {
  1491. e.printStackTrace();
  1492. } finally {
  1493. if (br != null) {
  1494. try {
  1495. br.close();
  1496. } catch (IOException e) {
  1497. e.printStackTrace();
  1498. }
  1499. }
  1500. }
  1501. return list.stream().distinct().collect(Collectors.toList());
  1502. }
  1503. }