BgServiceImpl.java 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529
  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.service.Crawler4JavbusService;
  25. import top.lvzhiqiang.util.DateUtils;
  26. import top.lvzhiqiang.util.JsoupUtil;
  27. import top.lvzhiqiang.util.StringUtils;
  28. import javax.annotation.Resource;
  29. import java.io.*;
  30. import java.lang.reflect.Field;
  31. import java.math.BigDecimal;
  32. import java.net.InetSocketAddress;
  33. import java.net.Proxy;
  34. import java.nio.charset.StandardCharsets;
  35. import java.time.Instant;
  36. import java.time.LocalDate;
  37. import java.time.LocalDateTime;
  38. import java.time.ZoneOffset;
  39. import java.util.*;
  40. import java.util.stream.Collectors;
  41. /**
  42. * Bg ServiceImpl
  43. *
  44. * @author lvzhiqiang
  45. * 2022/4/16 16:10
  46. */
  47. @Service
  48. @Slf4j
  49. public class BgServiceImpl implements BgService {
  50. @Resource
  51. private VideoGenresMapper videoGenresMapper;
  52. @Resource
  53. private VideoCastMapper videoCastMapper;
  54. @Resource
  55. private VideoInfoCastMapper videoInfoCastMapper;
  56. @Resource
  57. private VideoInfoGenresMapper videoInfoGenresMapper;
  58. @Resource
  59. private VideoInfoMapper videoInfoMapper;
  60. @Resource
  61. private IcodePoolMapper icodePoolMapper;
  62. @Resource
  63. private VideoInfoPoolMapper videoInfoPoolMapper;
  64. @Resource
  65. private VideoSitePoolMapper videoSitePoolMapper;
  66. @Resource
  67. private DicCodeMapper dicCodeMapper;
  68. @Resource
  69. private VideoInfoOtherMapper videoInfoOtherMapper;
  70. @Resource
  71. private VideoInfoUncensoredMapper videoInfoUncensoredMapper;
  72. @Resource
  73. private VideoInfoInfantryMapper videoInfoInfantryMapper;
  74. @Resource
  75. private CrawlerLoveFootMapper crawlerLoveFootMapper;
  76. @Resource
  77. private Crawler4JavbusService crawler4JavbusService;
  78. @Value("${spring.profiles.active}")
  79. private String env;
  80. private String ignoreFileTypeSuffix = "";
  81. private Proxy proxy = null;
  82. private Proxy proxy2 = null;
  83. public void beforeProxy() {
  84. if (null == proxy) {
  85. if ("dev".equals(env)) {
  86. proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1080));
  87. proxy2 = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 1080));
  88. } else {
  89. proxy = Proxy.NO_PROXY;
  90. //proxy2 = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 10808));
  91. proxy2 = Proxy.NO_PROXY;
  92. }
  93. }
  94. }
  95. /**
  96. * findDicCode
  97. *
  98. * @author lvzhiqiang
  99. * 2022/5/3 17:37
  100. */
  101. @Override
  102. public String findDicCode(String codeDesc, String order) throws IllegalAccessException {
  103. List<DicCode> dicCodeList = dicCodeMapper.findByCodeDesc(codeDesc, order);
  104. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(dicCodeList.size())).concat("<br/>"));
  105. for (DicCode dicCode : dicCodeList) {
  106. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  107. Field[] fields = dicCode.getClass().getDeclaredFields();
  108. for (Field field : fields) {
  109. field.setAccessible(true);
  110. sb.append("<tr>");
  111. sb.append("<td>").append(field.getName()).append("</td>");
  112. sb.append("<td>").append(field.get(dicCode)).append("</td>");
  113. sb.append("</tr>");
  114. }
  115. sb.append("</table>");
  116. }
  117. return sb.toString();
  118. }
  119. /**
  120. * findIcodePool
  121. *
  122. * @author lvzhiqiang
  123. * 2022/5/3 17:37
  124. */
  125. @Override
  126. public String findIcodePool(String identificationCode, Integer status, String order, String crudT) throws IllegalAccessException {
  127. if ("2".equals(crudT)) {
  128. //更新
  129. if (StringUtils.isEmpty(identificationCode) || null == status) {
  130. return "identificationCode和status不能为空";
  131. }
  132. icodePoolMapper.updateStatusByCode(identificationCode, status);
  133. return "success";
  134. }
  135. if ("3".equals(crudT)) {
  136. //删除
  137. if (StringUtils.isEmpty(identificationCode)) {
  138. return "dentificationCode不能为空";
  139. }
  140. icodePoolMapper.delByCode(identificationCode);
  141. return "success";
  142. }
  143. List<IcodePool> icodePoolList = icodePoolMapper.findByCodeAndStatus(identificationCode, status, order);
  144. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(icodePoolList.size())).concat("<br/>"));
  145. for (IcodePool icodePool : icodePoolList) {
  146. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  147. Field[] fields = icodePool.getClass().getDeclaredFields();
  148. for (Field field : fields) {
  149. field.setAccessible(true);
  150. sb.append("<tr>");
  151. sb.append("<td>").append(field.getName()).append("</td>");
  152. sb.append("<td>").append(field.get(icodePool)).append("</td>");
  153. sb.append("</tr>");
  154. }
  155. sb.append("</table>");
  156. }
  157. return sb.toString();
  158. }
  159. /**
  160. * findVideoSitePool
  161. *
  162. * @author lvzhiqiang
  163. * 2022/5/3 17:37
  164. */
  165. @Override
  166. public String findVideoSitePool(String url, String order) throws IllegalAccessException {
  167. List<VideoSitePool> videoSitePoolList = videoSitePoolMapper.findByUrl(url, order);
  168. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoSitePoolList.size())).concat("<br/>"));
  169. for (VideoSitePool videoSitePool : videoSitePoolList) {
  170. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  171. Field[] fields = videoSitePool.getClass().getDeclaredFields();
  172. for (Field field : fields) {
  173. field.setAccessible(true);
  174. sb.append("<tr>");
  175. sb.append("<td>").append(field.getName()).append("</td>");
  176. sb.append("<td>").append(field.get(videoSitePool)).append("</td>");
  177. sb.append("</tr>");
  178. }
  179. sb.append("</table>");
  180. }
  181. return sb.toString();
  182. }
  183. /**
  184. * findVideoInfoPool
  185. *
  186. * @author lvzhiqiang
  187. * 2022/5/3 17:37
  188. */
  189. @Override
  190. public String findVideoInfoPool(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  191. if ("2".equals(crudT)) {
  192. //更新
  193. if (StringUtils.isEmpty(identificationCode) || null == type) {
  194. return "identificationCode和type不能为空";
  195. }
  196. videoInfoPoolMapper.updateTypeByCode(identificationCode, type);
  197. return "success";
  198. }
  199. if ("3".equals(crudT)) {
  200. //删除
  201. if (StringUtils.isEmpty(identificationCode)) {
  202. return "dentificationCode不能为空";
  203. }
  204. videoInfoPoolMapper.delByCode(identificationCode);
  205. return "success";
  206. }
  207. List<VideoInfoPool> videoInfoPoolList = videoInfoPoolMapper.findByCodeAndType(identificationCode, type, order);
  208. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoPoolList.size())).concat("<br/>"));
  209. for (VideoInfoPool videoInfoPool : videoInfoPoolList) {
  210. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  211. Field[] fields = videoInfoPool.getClass().getDeclaredFields();
  212. for (Field field : fields) {
  213. field.setAccessible(true);
  214. sb.append("<tr>");
  215. sb.append("<td>").append(field.getName()).append("</td>");
  216. sb.append("<td>").append(field.get(videoInfoPool)).append("</td>");
  217. sb.append("</tr>");
  218. }
  219. sb.append("</table>");
  220. }
  221. return sb.toString();
  222. }
  223. /**
  224. * findVideoInfoLoveFoot
  225. *
  226. * @author lvzhiqiang
  227. * 2022/12/34 18:08
  228. */
  229. @Override
  230. public String findVideoInfoLoveFoot(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  231. if ("2".equals(crudT)) {
  232. //更新
  233. if (StringUtils.isEmpty(identificationCode) || null == type) {
  234. return "identificationCode和type不能为空";
  235. }
  236. crawlerLoveFootMapper.updateTypeByCode(identificationCode, type);
  237. return "success";
  238. }
  239. if ("3".equals(crudT)) {
  240. //删除
  241. if (StringUtils.isEmpty(identificationCode)) {
  242. return "dentificationCode不能为空";
  243. }
  244. crawlerLoveFootMapper.delByCode(identificationCode);
  245. return "success";
  246. }
  247. List<CrawlerLoveFoot> crawlerLoveFootList = crawlerLoveFootMapper.findByCodeAndType(identificationCode, type, order);
  248. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(crawlerLoveFootList.size())).concat("<br/>"));
  249. for (CrawlerLoveFoot crawlerLoveFoot : crawlerLoveFootList) {
  250. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  251. Field[] fields = crawlerLoveFoot.getClass().getDeclaredFields();
  252. for (Field field : fields) {
  253. field.setAccessible(true);
  254. sb.append("<tr>");
  255. sb.append("<td>").append(field.getName()).append("</td>");
  256. sb.append("<td>").append(field.get(crawlerLoveFoot)).append("</td>");
  257. sb.append("</tr>");
  258. }
  259. sb.append("</table>");
  260. }
  261. return sb.toString();
  262. }
  263. /**
  264. * findVideoInfo
  265. *
  266. * @author lvzhiqiang
  267. * 2022/5/3 17:37
  268. */
  269. @Override
  270. public String findVideoInfo(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
  271. if ("3".equals(crudT)) {
  272. //删除
  273. if (StringUtils.isEmpty(identificationCode)) {
  274. return "dentificationCode不能为空";
  275. }
  276. videoInfoMapper.delByCode(identificationCode);
  277. return "success";
  278. }
  279. List<VideoInfo> videoInfoList = videoInfoMapper.findByCodeAndType(identificationCode, type, order);
  280. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoList.size())).concat("<br/>"));
  281. for (VideoInfo videoInfo : videoInfoList) {
  282. sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
  283. Field[] fields = videoInfo.getClass().getDeclaredFields();
  284. for (Field field : fields) {
  285. field.setAccessible(true);
  286. sb.append("<tr>");
  287. sb.append("<td>").append(field.getName()).append("</td>");
  288. sb.append("<td>").append(field.get(videoInfo)).append("</td>");
  289. sb.append("</tr>");
  290. }
  291. sb.append("</table>");
  292. }
  293. return sb.toString();
  294. }
  295. /**
  296. * updateScoreOrComment
  297. *
  298. * @author lvzhiqiang
  299. * 2022/5/4 9:54
  300. */
  301. @Override
  302. public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) {
  303. BigDecimal scoreBD = null;
  304. if (StringUtils.isNotEmpty(score)) {
  305. scoreBD = new BigDecimal(score);
  306. }
  307. int num = videoInfoOtherMapper.findByCode(identificationCode);
  308. if (num == 0) {
  309. videoInfoOtherMapper.insertScoreOrComment(identificationCode, scoreBD, comment);
  310. return "insert success";
  311. }
  312. videoInfoOtherMapper.updateScoreOrComment(identificationCode, scoreBD, comment);
  313. return "update success";
  314. }
  315. /**
  316. * Jsoup VideoInfoUncensored
  317. *
  318. * @author lvzhiqiang
  319. * 2022/5/4 19:27
  320. */
  321. @Async
  322. @Override
  323. public void jsoupVideoInfoUncensored(Integer status) {
  324. log.warn("jsoupVideoInfoUncensored 开始:status={}", status);
  325. // 获取待抓取码列表
  326. List<String> icodeList = videoInfoUncensoredMapper.findIcodeByStatus(status);
  327. if (icodeList.size() == 0) {
  328. log.warn("status={}的icodeList为空", status);
  329. return;
  330. }
  331. // 获取javbus防屏蔽地址
  332. List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
  333. if (javbusUrlList.size() == 0) {
  334. log.warn("javbusUrlList为空");
  335. return;
  336. }
  337. // 获取码池图片保存路径
  338. String liuchuPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  339. // 遍历
  340. Document document;
  341. VideoInfoUncensored videoInfoUncensored;
  342. String javbusUrl;
  343. int j = 0;
  344. for (int i = 0; i < icodeList.size(); i++) {
  345. long start = System.currentTimeMillis();
  346. String identificationCode = icodeList.get(i);
  347. int retryCount = 0;
  348. while (retryCount <= 3) {
  349. javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
  350. try {
  351. document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
  352. .timeout(50000)
  353. //.proxy()
  354. //.data()
  355. .ignoreContentType(true)
  356. .userAgent(getUserAgent())
  357. .header("referer", "https://www.javbus.com/".concat(identificationCode))
  358. .get();
  359. videoInfoUncensored = new VideoInfoUncensored();
  360. videoInfoUncensored.setIdentificationCode(identificationCode);
  361. parseDocument4Uncensored(document, identificationCode, liuchuPath, videoInfoUncensored);
  362. videoInfoUncensored.setStatus(2);
  363. videoInfoUncensoredMapper.updateJsoupInfoByCode(videoInfoUncensored);
  364. j++;
  365. log.warn("jsoupVideoInfoUncensored success:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode);
  366. break;
  367. } catch (Exception e) {
  368. ++retryCount;
  369. if (retryCount < 4) {
  370. log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, e);
  371. } else if (retryCount == 4) {
  372. videoInfoUncensoredMapper.updateStatus(identificationCode, 3);
  373. log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode, e);
  374. }
  375. }
  376. }
  377. }
  378. log.warn("jsoupVideoInfoUncensored 统计:total={},success={}", icodeList.size(), j);
  379. }
  380. /**
  381. * Jsoup VideoInfo
  382. *
  383. * @author lvzhiqiang
  384. * 2022/5/5 18:21
  385. */
  386. @Async
  387. @Override
  388. public void jsoupVideoInfo(Integer status, String url, String identificationCodeP) {
  389. log.warn("jsoupVideoInfo 开始:status={}", status);
  390. // 获取待抓取码列表
  391. List<String> icodeList = new ArrayList<>();
  392. if (StringUtils.isEmpty(identificationCodeP)) {
  393. icodeList = videoInfoMapper.findIcodeByStatus(status);
  394. if (icodeList.size() == 0) {
  395. log.warn("status={}的icodeList为空", status);
  396. return;
  397. }
  398. } else {
  399. icodeList.add(identificationCodeP);
  400. }
  401. // 获取javbus防屏蔽地址
  402. List<String> javbusUrlList = new ArrayList<>();
  403. if (StringUtils.isEmpty(url)) {
  404. javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
  405. if (javbusUrlList.size() == 0) {
  406. log.warn("javbusUrlList为空");
  407. return;
  408. }
  409. } else {
  410. javbusUrlList.add(url);
  411. }
  412. beforeProxy();
  413. // 获取图片保存路径
  414. String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  415. // 遍历
  416. Document document;
  417. VideoInfo videoInfo;
  418. String javbusUrl;
  419. int j = 0;
  420. for (int i = 0; i < icodeList.size(); i++) {
  421. long start = System.currentTimeMillis();
  422. String identificationCode = icodeList.get(i);
  423. int retryCount = 0;
  424. while (retryCount <= 3) {
  425. javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
  426. try {
  427. document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
  428. .timeout(50000)
  429. .proxy(proxy)
  430. .userAgent(getUserAgent())
  431. .followRedirects(true)
  432. .ignoreContentType(true)
  433. .ignoreHttpErrors(true)
  434. .header("referer", "https://www.javbus.com/".concat(identificationCode))
  435. .get();
  436. videoInfo = new VideoInfo();
  437. videoInfo.setIdentificationCode(identificationCode);
  438. String picTime = parseDocument4QiBing(document, identificationCode, qibingPath, videoInfo);
  439. videoInfo.setStatus(2);
  440. // 获取男优
  441. getMaleCast(videoInfo);
  442. videoInfoMapper.updateJsoupInfoByCode(videoInfo);
  443. videoInfoOtherMapper.insertOrUpdate(identificationCode, 2);
  444. j++;
  445. log.warn("jsoupVideoInfo success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
  446. break;
  447. } catch (Exception e) {
  448. ++retryCount;
  449. if (retryCount < 4) {
  450. log.error("jsoupVideoInfo error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
  451. } else if (retryCount == 4) {
  452. videoInfoMapper.updateStatus(identificationCode, 3);
  453. log.error("jsoupVideoInfo error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
  454. }
  455. }
  456. }
  457. }
  458. log.warn("jsoupVideoInfo 统计:total={},success={}", icodeList.size(), j);
  459. }
  460. @Async
  461. @Override
  462. public void jsoupVideoInfo4javdb(Integer status, String url, String identificationCodeP) {
  463. log.warn("jsoupVideoInfo4javdb 开始:status={}", status);
  464. // 获取待抓取码列表
  465. List<String> icodeList = new ArrayList<>();
  466. if (StringUtils.isEmpty(identificationCodeP)) {
  467. icodeList = videoInfoMapper.findIcodeByStatus(status);
  468. if (icodeList.size() == 0) {
  469. log.warn("status={}的icodeList为空", status);
  470. return;
  471. }
  472. } else {
  473. icodeList.add(identificationCodeP);
  474. }
  475. beforeProxy();
  476. // 获取图片保存路径
  477. String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  478. // 遍历
  479. Document document;
  480. VideoInfo videoInfo;
  481. int j = 0;
  482. for (int i = 0; i < icodeList.size(); i++) {
  483. long start = System.currentTimeMillis();
  484. String identificationCode = icodeList.get(i);
  485. int retryCount = 0;
  486. while (retryCount <= 3) {
  487. try {
  488. Map<String, String> headerMap = new HashMap<>();
  489. headerMap.put("referer", url);
  490. document = JsoupUtil.requestDocument(url, JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
  491. videoInfo = new VideoInfo();
  492. videoInfo.setIdentificationCode(identificationCode);
  493. String picTime = parseDocument4QiBing4Javdb(document, identificationCode, qibingPath, videoInfo);
  494. videoInfo.setStatus(2);
  495. // 获取男优
  496. getMaleCast(videoInfo);
  497. videoInfoMapper.updateJsoupInfoByCode(videoInfo);
  498. videoInfoOtherMapper.insertOrUpdate(identificationCode, 2);
  499. j++;
  500. log.warn("jsoupVideoInfo4javdb success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
  501. break;
  502. } catch (Exception e) {
  503. ++retryCount;
  504. if (retryCount < 4) {
  505. log.error("jsoupVideoInfo4javdb error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, url, e);
  506. } else if (retryCount == 4) {
  507. videoInfoMapper.updateStatus(identificationCode, 3);
  508. log.error("jsoupVideoInfo4javdb error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, identificationCode, url, e);
  509. }
  510. }
  511. }
  512. }
  513. log.warn("jsoupVideoInfo4javdb 统计:total={},success={}", icodeList.size(), j);
  514. }
  515. @Async
  516. @Override
  517. public void jsoupVideoInfoInfantry4javdb(String type, Integer status, String url, String identificationCodeP) {
  518. log.warn("jsoupVideoInfoInfantry4javdb 开始:status={}", status);
  519. // 获取待抓取码列表
  520. List<VideoInfoInfantry> videoInfoInfantryList;
  521. if (StringUtils.isEmpty(identificationCodeP)) {
  522. videoInfoInfantryList = videoInfoInfantryMapper.findInfoByTypeAndStatus(type, status);
  523. if (videoInfoInfantryList.size() == 0) {
  524. log.warn("status={}的videoInfoInfantryList为空", status);
  525. return;
  526. }
  527. } else {
  528. videoInfoInfantryList = videoInfoInfantryMapper.findByCodeAndType(identificationCodeP, type, status, null);
  529. videoInfoInfantryList.forEach(e -> {
  530. e.setJavdbUrl(url);
  531. });
  532. }
  533. List<DicCode> dicCodeList = dicCodeMapper.findAll();
  534. Map<String, String> javdbConstantMap = dicCodeList.stream()
  535. .filter(x -> x.getType() != null && 2 == x.getType() && x.getEnv().contains(env))
  536. .collect(Collectors.toMap(DicCode::getCodeKey, DicCode::getCodeValue, (key1, key2) -> key1));
  537. beforeProxy();
  538. // 获取图片保存路径
  539. String infantryPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  540. // 遍历
  541. Document document;
  542. Document javdbSearchDocument;
  543. int j = 0;
  544. for (int i = 0; i < videoInfoInfantryList.size(); i++) {
  545. long start = System.currentTimeMillis();
  546. VideoInfoInfantry videoInfoInfantry = videoInfoInfantryList.get(i);
  547. int retryCount = 0;
  548. while (retryCount <= 3) {
  549. try {
  550. Thread.sleep(3000);
  551. String picTime;
  552. Elements itembSelects;
  553. if (StringUtils.isNotEmpty(videoInfoInfantry.getJavdbUrl())) {
  554. Map<String, String> headerMap = new HashMap<>();
  555. headerMap.put("referer", url);
  556. document = JsoupUtil.requestDocument(url, JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
  557. } else {
  558. String searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(videoInfoInfantry.getIdentificationCode()).concat("&f=all");
  559. Map<String, String> header3Map = new HashMap<>();
  560. header3Map.put("referer", searchUrl);
  561. javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
  562. itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
  563. if (itembSelects.size() == 0) {
  564. String newName = videoInfoInfantry.getName();
  565. searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(newName).concat("&f=all");
  566. javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
  567. itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
  568. }
  569. if (itembSelects.size() == 0) {
  570. throw new BusinessException(30000, "javdb search result null");
  571. }
  572. String title;
  573. String code;
  574. String codeUrl = null;
  575. for (Element itembSelect : itembSelects) {
  576. title = itembSelect.select("a.box").get(0).attr("title");
  577. code = itembSelect.select("a.box").get(0).select("div.video-title").select("strong").text();
  578. if (code.equalsIgnoreCase(videoInfoInfantry.getIdentificationCode())) {
  579. codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
  580. break;
  581. }
  582. String newName = videoInfoInfantry.getName().replace("●", "さ");
  583. if (title.contains(newName)) {
  584. codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
  585. videoInfoInfantry.setName(newName);
  586. break;
  587. }
  588. }
  589. if (StringUtils.isEmpty(codeUrl)) {
  590. throw new BusinessException(30000, "javdb search result mismatch");
  591. }
  592. document = JsoupUtil.requestDocument(codeUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
  593. videoInfoInfantry.setJavdbUrl(codeUrl);
  594. }
  595. picTime = parseDocument4Infantry4Javdb(document, infantryPath, videoInfoInfantry);
  596. videoInfoInfantry.setStatus(2);
  597. videoInfoInfantryMapper.updateJsoupInfoById(videoInfoInfantry);
  598. videoInfoOtherMapper.insertOrUpdate(videoInfoInfantry.getIdentificationCode(), 2);
  599. j++;
  600. log.warn("jsoupVideoInfoInfantry4javdb success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, videoInfoInfantry.getIdentificationCode());
  601. break;
  602. } catch (Exception e) {
  603. ++retryCount;
  604. if (retryCount < 4) {
  605. log.error("jsoupVideoInfoInfantry4javdb error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, videoInfoInfantry.getIdentificationCode(), url, e);
  606. } else if (retryCount == 4) {
  607. videoInfoInfantryMapper.updateStatus(videoInfoInfantry.getIdentificationCode(), 3);
  608. log.error("jsoupVideoInfoInfantry4javdb error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, videoInfoInfantry.getIdentificationCode(), url, e);
  609. }
  610. }
  611. }
  612. }
  613. log.warn("jsoupVideoInfoInfantry4javdb 统计:total={},success={}", videoInfoInfantryList.size(), j);
  614. }
  615. @Async
  616. @Override
  617. public void jsoupVideoInfoUncensored4javdb(Integer status, String url, String identificationCodeP) {
  618. log.warn("jsoupVideoInfoUncensored4javdb 开始:status={}", status);
  619. // 获取待抓取码列表
  620. List<VideoInfoUncensored> videoInfoUncensoredList;
  621. if (StringUtils.isEmpty(identificationCodeP)) {
  622. videoInfoUncensoredList = videoInfoUncensoredMapper.findByCodeAndType(null, status, null);
  623. if (videoInfoUncensoredList.size() == 0) {
  624. log.warn("status={}的videoInfoUncensoredList为空", status);
  625. return;
  626. }
  627. } else {
  628. videoInfoUncensoredList = videoInfoUncensoredMapper.findByCodeAndType(identificationCodeP, status, null);
  629. videoInfoUncensoredList.forEach(e -> {
  630. e.setJavdbUrl(url);
  631. });
  632. }
  633. List<DicCode> dicCodeList = dicCodeMapper.findAll();
  634. Map<String, String> javdbConstantMap = dicCodeList.stream()
  635. .filter(x -> x.getType() != null && 2 == x.getType() && x.getEnv().contains(env))
  636. .collect(Collectors.toMap(DicCode::getCodeKey, DicCode::getCodeValue, (key1, key2) -> key1));
  637. beforeProxy();
  638. // 获取图片保存路径
  639. String uncensoredPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  640. // 遍历
  641. Document document;
  642. Document javdbSearchDocument;
  643. int j = 0;
  644. for (int i = 0; i < videoInfoUncensoredList.size(); i++) {
  645. long start = System.currentTimeMillis();
  646. VideoInfoUncensored videoInfoUncensored = videoInfoUncensoredList.get(i);
  647. int retryCount = 0;
  648. while (retryCount <= 3) {
  649. try {
  650. Thread.sleep(3000);
  651. String picTime;
  652. Elements itembSelects;
  653. boolean ignoreCodeFlag = false;
  654. if (StringUtils.isNotEmpty(videoInfoUncensored.getJavdbUrl())) {
  655. Map<String, String> headerMap = new HashMap<>();
  656. headerMap.put("referer", url);
  657. document = JsoupUtil.requestDocument(url, JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
  658. } else {
  659. String searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(videoInfoUncensored.getIdentificationCode()).concat("&f=all");
  660. Map<String, String> header3Map = new HashMap<>();
  661. header3Map.put("referer", searchUrl);
  662. javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
  663. itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
  664. if (itembSelects.size() == 0) {
  665. String newName = videoInfoUncensored.getName();
  666. searchUrl = javdbConstantMap.get("javdb").concat("search?q=").concat(newName).concat("&f=all");
  667. javdbSearchDocument = JsoupUtil.requestDocument(searchUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
  668. itembSelects = javdbSearchDocument.select("div.movie-list").select("div.item");
  669. ignoreCodeFlag = true;
  670. }
  671. if (itembSelects.size() == 0) {
  672. throw new BusinessException(30000, "javdb search result null");
  673. }
  674. String title;
  675. String code;
  676. String codeUrl = null;
  677. for (Element itembSelect : itembSelects) {
  678. title = itembSelect.select("a.box").get(0).attr("title");
  679. code = itembSelect.select("a.box").get(0).select("div.video-title").select("strong").text();
  680. if (code.equalsIgnoreCase(videoInfoUncensored.getIdentificationCode())) {
  681. codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
  682. break;
  683. } else if (title.equalsIgnoreCase(videoInfoUncensored.getName()) && ignoreCodeFlag) {
  684. codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
  685. break;
  686. }
  687. String newName = videoInfoUncensored.getName().replace("●", "さ");
  688. if (title.contains(newName)) {
  689. codeUrl = itembSelect.select("a.box").get(0).attr("abs:href");
  690. videoInfoUncensored.setName(newName);
  691. break;
  692. }
  693. }
  694. if (StringUtils.isEmpty(codeUrl)) {
  695. throw new BusinessException(30000, "javdb search result mismatch");
  696. }
  697. document = JsoupUtil.requestDocument(codeUrl, JsoupUtil.HTTP_GET, proxy2, null, header3Map, null);
  698. videoInfoUncensored.setJavdbUrl(codeUrl);
  699. }
  700. picTime = parseDocument4Uncensored4Javdb(document, uncensoredPath, videoInfoUncensored);
  701. videoInfoUncensored.setStatus(2);
  702. videoInfoUncensoredMapper.updateJsoupInfoById(videoInfoUncensored);
  703. videoInfoOtherMapper.insertOrUpdate(videoInfoUncensored.getIdentificationCode(), 2);
  704. j++;
  705. log.warn("jsoupVideoInfoUncensored4javdb success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, videoInfoUncensored.getIdentificationCode());
  706. break;
  707. } catch (Exception e) {
  708. ++retryCount;
  709. if (retryCount < 4) {
  710. log.error("jsoupVideoInfoUncensored4javdb error重试:i={},retryCount={},time={},identificationCode={},javdbUrl={}", i, retryCount, System.currentTimeMillis() - start, videoInfoUncensored.getIdentificationCode(), videoInfoUncensored.getJavdbUrl(), e);
  711. } else if (retryCount == 4) {
  712. videoInfoUncensoredMapper.updateStatus(videoInfoUncensored.getIdentificationCode(), 3);
  713. log.error("jsoupVideoInfoUncensored4javdb error:i={},time={},identificationCode={},javdbsUrl={}", i, System.currentTimeMillis() - start, videoInfoUncensored.getIdentificationCode(), videoInfoUncensored.getJavdbUrl(), e);
  714. }
  715. }
  716. }
  717. }
  718. log.warn("jsoupVideoInfoUncensored4javdb 统计:total={},success={}", videoInfoUncensoredList.size(), j);
  719. }
  720. private String parseDocument4Uncensored4Javdb(Document document, String uncensoredPath, VideoInfoUncensored videoInfoUncensored) throws Exception {
  721. Elements container = document.select("section.section > div.container");
  722. if (container.size() == 0) {
  723. throw new BusinessException(30000, "番号无效!");
  724. }
  725. Elements videoDetail = container.select("div.video-detail");
  726. // 名称
  727. videoInfoUncensored.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
  728. Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
  729. Element pEle = moviePanelInfos.get(0);
  730. // 识别码
  731. String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  732. if (!videoInfoUncensored.getIdentificationCode().equalsIgnoreCase(iCode)) {
  733. throw new Exception("番号与站点不一致");
  734. }
  735. // 发行日期
  736. String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  737. videoInfoUncensored.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  738. // 长度
  739. String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  740. videoInfoUncensored.setLength(length);
  741. // 导演
  742. Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
  743. if (directorEles.size() > 0) {
  744. videoInfoUncensored.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  745. }
  746. // 制作商
  747. Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
  748. if (markerEles.size() > 0) {
  749. videoInfoUncensored.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  750. }
  751. // 发行商
  752. Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
  753. if (issuerEles.size() > 0) {
  754. videoInfoUncensored.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  755. }
  756. // 类别
  757. Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
  758. if (genresEles.size() > 0) {
  759. StringBuffer sb = new StringBuffer();
  760. Elements ahrefEles = genresEles.first().select("a[href]");
  761. for (Element ahrefEle : ahrefEles) {
  762. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  763. }
  764. if (sb.length() > 0) {
  765. sb = sb.deleteCharAt(sb.length() - 1);
  766. }
  767. videoInfoUncensored.setGenres(sb.toString());
  768. }
  769. // 演员
  770. Elements castEles = pEle.select("div:contains(演員)").select("span.value");
  771. if (castEles.size() > 0) {
  772. StringBuffer sb = new StringBuffer();
  773. Elements ahrefEles = castEles.first().select("a[href]");
  774. for (Element ahrefEle : ahrefEles) {
  775. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  776. }
  777. if (sb.length() > 0) {
  778. sb = sb.deleteCharAt(sb.length() - 1);
  779. }
  780. videoInfoUncensored.setCast(sb.toString());
  781. }
  782. // 图片 流出
  783. String liuchus = "流出/".concat(videoInfoUncensored.getMainWho()).concat("/").concat(iCode);
  784. StringBuffer picTime = new StringBuffer("{cover:");
  785. // 图片URL bigImage
  786. String liuchuCover = liuchus.concat("/cover/");
  787. String fileName = issueDate.concat(" ").concat(videoInfoUncensored.getIdentificationCode()).concat(" ").concat(StringUtils.escapeJavParam(videoInfoUncensored.getName()));
  788. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  789. if (imgUrlBytes.length > 251) {
  790. byte[] imgUrlDestBytes = new byte[251];
  791. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  792. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  793. }
  794. fileName = fileName.concat(".jpg");
  795. if (!new File(uncensoredPath.concat(liuchuCover), fileName).exists()) {
  796. Elements videoMetaPanel = videoDetail.select("div.column-video-cover");
  797. String href = videoMetaPanel.select("a > img").first().attr("src");
  798. long start = System.currentTimeMillis();
  799. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  800. saveFile2(response.bodyStream(), uncensoredPath.concat(liuchuCover), fileName);
  801. picTime.append(System.currentTimeMillis() - start).append(",");
  802. }
  803. videoInfoUncensored.setImgUrl(iCode.concat("/cover/").concat(fileName));
  804. // 图片URL img_gf
  805. String liuchuImgGF = liuchus.concat("/img_gf/");
  806. File liuchuImgGFFile = new File(uncensoredPath.concat(liuchuImgGF));
  807. if (!liuchuImgGFFile.exists() || liuchuImgGFFile.listFiles().length == 0) {
  808. Elements sampleBoxEles = videoDetail.select("div.preview-images").select("a.tile-item");
  809. long start2 = System.currentTimeMillis();
  810. if (sampleBoxEles.size() > 0) {
  811. Connection.Response responseImg;
  812. for (Element sampleBoxEle : sampleBoxEles) {
  813. String sampleBoxHref = sampleBoxEle.attr("href");
  814. if (!sampleBoxHref.contains("http")) {
  815. sampleBoxHref = sampleBoxEle.attr("abs:href");
  816. }
  817. try {
  818. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  819. } catch (HttpStatusException e) {
  820. sampleBoxHref = sampleBoxEle.select("img").attr("src");
  821. if (!sampleBoxHref.contains("http")) {
  822. sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
  823. }
  824. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  825. }
  826. String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
  827. saveFile2(responseImg.bodyStream(), uncensoredPath.concat(liuchuImgGF), sampleBoxFileName);
  828. }
  829. } else {
  830. log.error("jsoupVideoInfoUncensored img_gf null,identificationCode={}", videoInfoUncensored.getIdentificationCode());
  831. }
  832. picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
  833. }
  834. return picTime.toString();
  835. }
  836. private String parseDocument4Infantry4Javdb(Document document, String infantryPath, VideoInfoInfantry videoInfoInfantry) throws Exception {
  837. Elements container = document.select("section.section > div.container");
  838. if (container.size() == 0) {
  839. throw new BusinessException(30000, "番号无效!");
  840. }
  841. Elements videoDetail = container.select("div.video-detail");
  842. // 名称
  843. videoInfoInfantry.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
  844. Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
  845. Element pEle = moviePanelInfos.get(0);
  846. // 识别码
  847. String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  848. if (!videoInfoInfantry.getIdentificationCode().equalsIgnoreCase(iCode)) {
  849. throw new Exception("番号与站点不一致");
  850. }
  851. // 发行日期
  852. String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  853. videoInfoInfantry.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  854. // 长度
  855. String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  856. videoInfoInfantry.setLength(length);
  857. // 导演
  858. Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
  859. if (directorEles.size() > 0) {
  860. videoInfoInfantry.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  861. }
  862. // 制作商
  863. Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
  864. if (markerEles.size() > 0) {
  865. videoInfoInfantry.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  866. }
  867. // 发行商
  868. Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
  869. if (issuerEles.size() > 0) {
  870. videoInfoInfantry.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  871. }
  872. // 类别
  873. Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
  874. if (genresEles.size() > 0) {
  875. StringBuffer sb = new StringBuffer();
  876. Elements ahrefEles = genresEles.first().select("a[href]");
  877. for (Element ahrefEle : ahrefEles) {
  878. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  879. }
  880. if (sb.length() > 0) {
  881. sb = sb.deleteCharAt(sb.length() - 1);
  882. }
  883. videoInfoInfantry.setGenres(sb.toString());
  884. }
  885. // 演员
  886. Elements castEles = pEle.select("div:contains(演員)").select("span.value");
  887. if (castEles.size() > 0) {
  888. StringBuffer sb = new StringBuffer();
  889. Elements ahrefEles = castEles.first().select("a[href]");
  890. for (Element ahrefEle : ahrefEles) {
  891. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  892. }
  893. if (sb.length() > 0) {
  894. sb = sb.deleteCharAt(sb.length() - 1);
  895. }
  896. videoInfoInfantry.setCast(sb.toString());
  897. }
  898. // 图片 步兵
  899. String bubings = "步兵/".concat(videoInfoInfantry.getType()).concat("/").concat(iCode);
  900. StringBuffer picTime = new StringBuffer("{cover:");
  901. // 图片URL bigImage
  902. String bubingCover = bubings.concat("/cover/");
  903. String fileName = issueDate.concat(" ").concat(videoInfoInfantry.getIdentificationCode()).concat(" ").concat(videoInfoInfantry.getName()).replace("?", "?").replace("#","");
  904. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  905. if (imgUrlBytes.length > 251) {
  906. byte[] imgUrlDestBytes = new byte[251];
  907. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  908. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  909. }
  910. fileName = fileName.concat(".jpg");
  911. if (!new File(infantryPath.concat(bubingCover), fileName).exists()) {
  912. Elements videoMetaPanel = videoDetail.select("div.column-video-cover");
  913. String href = videoMetaPanel.select("a > img").first().attr("src");
  914. long start = System.currentTimeMillis();
  915. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  916. saveFile2(response.bodyStream(), infantryPath.concat(bubingCover), fileName);
  917. picTime.append(System.currentTimeMillis() - start).append(",");
  918. }
  919. videoInfoInfantry.setImgUrl(iCode.concat("/cover/").concat(fileName));
  920. // 图片URL img_gf
  921. String bubingImgGF = bubings.concat("/img_gf/");
  922. File bubingImgGFFile = new File(infantryPath.concat(bubingImgGF));
  923. if (!bubingImgGFFile.exists() || bubingImgGFFile.listFiles().length == 0) {
  924. Elements sampleBoxEles = videoDetail.select("div.preview-images").select("a.tile-item");
  925. long start2 = System.currentTimeMillis();
  926. if (sampleBoxEles.size() > 0) {
  927. Connection.Response responseImg;
  928. for (Element sampleBoxEle : sampleBoxEles) {
  929. String sampleBoxHref = sampleBoxEle.attr("href");
  930. if (!sampleBoxHref.contains("http")) {
  931. sampleBoxHref = sampleBoxEle.attr("abs:href");
  932. }
  933. try {
  934. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  935. } catch (HttpStatusException e) {
  936. sampleBoxHref = sampleBoxEle.select("img").attr("src");
  937. if (!sampleBoxHref.contains("http")) {
  938. sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
  939. }
  940. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  941. }
  942. String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
  943. saveFile2(responseImg.bodyStream(), infantryPath.concat(bubingImgGF), sampleBoxFileName);
  944. }
  945. } else {
  946. log.error("jsoupVideoInfoInfantry img_gf null,identificationCode={}", videoInfoInfantry.getIdentificationCode());
  947. }
  948. picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
  949. }
  950. return picTime.toString();
  951. }
  952. @Override
  953. public void getMaleCast(VideoInfo videoInfo) {
  954. Document document;
  955. try {
  956. Map<String, String> headerMap = new HashMap<>();
  957. headerMap.put("referer", "avdanyuwiki.com");
  958. document = JsoupUtil.requestDocument("https://avdanyuwiki.com/?s=".concat(videoInfo.getName()), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
  959. Elements container = document.select("div#header-container-in");
  960. if (container.size() == 0) {
  961. return;
  962. }
  963. Elements alinks1 = container.select("h4").select("a[rel='bookmark']");
  964. if (alinks1 == null || alinks1.size() == 0) {
  965. return;
  966. }
  967. String alinkhref = alinks1.first().attr("abs:href");
  968. document = JsoupUtil.requestDocument(alinkhref, JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
  969. Elements entrycontent = document.select("div.entry-content");
  970. if (entrycontent.size() == 0) {
  971. return;
  972. }
  973. String[] entrycontentArr = entrycontent.html().split("<br>");
  974. for (String s : entrycontentArr) {
  975. if (s.contains("出演男優")) {
  976. String[] split = s.split(":");
  977. if (split.length < 2) {
  978. return;
  979. }
  980. String maleCasts = s.split(":")[1];
  981. List<String> sssss = new ArrayList<>();
  982. String[] split1 = maleCasts.split(",");
  983. for (String s1 : split1) {
  984. String[] split2 = s1.trim().split("\\s+");
  985. for (String s2 : split2) {
  986. sssss.add(s2.replaceAll(" ", "").trim());
  987. }
  988. }
  989. String maleCast = StringUtils.join(sssss, ",");
  990. videoInfo.setMaleCast(maleCast);
  991. break;
  992. }
  993. }
  994. } catch (Exception e) {
  995. log.error("getMaleCast error,icode={},name={}={}", videoInfo.getIdentificationCode(), videoInfo.getName(), e);
  996. }
  997. }
  998. /**
  999. * 删除影片
  1000. *
  1001. * @param identificationCode
  1002. * @param parentTypeName
  1003. * @author lvzhiqiang
  1004. * 2022/5/29 12:59
  1005. */
  1006. @Override
  1007. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  1008. public void delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
  1009. if (StringUtils.isNotEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
  1010. if (parentTypeName.contains("类别")) {
  1011. String videoGenres = parentTypeName.replace("(类别)", "");
  1012. VideoInfoGenres videoInfoGenres = videoInfoGenresMapper.findVideoInfoGenresByCodeAndName(identificationCode, videoGenres);
  1013. if ("1".equals(videoInfoGenres.getType())) {
  1014. // 主体
  1015. throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
  1016. } else {
  1017. // 链接
  1018. videoInfoGenresMapper.deleteById(videoInfoGenres.getId());
  1019. }
  1020. } else if (parentTypeName.contains("优")) {
  1021. String videoCast = "";
  1022. if (parentTypeName.contains("(男")) {
  1023. videoCast = parentTypeName.replace("(男优)", "");
  1024. } else if (parentTypeName.contains("(女")) {
  1025. videoCast = parentTypeName.replace("(女优)", "");
  1026. }
  1027. VideoInfoCast videoInfoCast = videoInfoCastMapper.findVideoInfoCastByCodeAndName(identificationCode, videoCast);
  1028. if ("1".equals(videoInfoCast.getType())) {
  1029. // 主体
  1030. throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
  1031. } else {
  1032. // 链接
  1033. videoInfoCastMapper.deleteById(videoInfoCast.getId());
  1034. }
  1035. } else {
  1036. throw new ParameterException("直属类型不存在");
  1037. }
  1038. } else if (StringUtils.isEmpty(parentTypeName) && StringUtils.isNotEmpty(allFlag)) {
  1039. videoInfoMapper.delByIdentificationCode(identificationCode);
  1040. videoInfoCastMapper.deleteByCode(identificationCode);
  1041. videoInfoGenresMapper.deleteByCode(identificationCode);
  1042. } else {
  1043. throw new ParameterException("参数有误");
  1044. }
  1045. }
  1046. /**
  1047. * findVideoInfoOther
  1048. *
  1049. * @author lvzhiqiang
  1050. * 2022/9/17 19:17
  1051. */
  1052. @Override
  1053. public String findVideoInfoOther(String identificationCode, String resolutionRatio, Integer original, Integer subtitle, Integer recoding, String crudT) {
  1054. if ("2".equals(crudT)) {
  1055. identificationCode = identificationCode.trim();
  1056. // 更新/新增
  1057. int num = videoInfoOtherMapper.findByCode(identificationCode);
  1058. if (num == 0) {
  1059. videoInfoOtherMapper.insertVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
  1060. return "insert success";
  1061. }
  1062. videoInfoOtherMapper.updateVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
  1063. return "update success";
  1064. }
  1065. if ("3".equals(crudT)) {
  1066. identificationCode = identificationCode.trim();
  1067. //删除
  1068. videoInfoOtherMapper.delByCode(identificationCode);
  1069. return "delete success";
  1070. }
  1071. // 查询
  1072. List<VideoInfoOther> videoInfoOtherList = videoInfoOtherMapper.findVideoInfoOther4MultipleParams(identificationCode, resolutionRatio, original, subtitle, recoding);
  1073. StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoOtherList.size())).concat("<br/>"));
  1074. 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>");
  1075. int i = 0;
  1076. for (VideoInfoOther videoInfoOther : videoInfoOtherList) {
  1077. i++;
  1078. sb.append("<tr>");
  1079. sb.append("<td>").append(i).append("</td>");
  1080. sb.append("<td>").append(videoInfoOther.getIdentificationCode()).append("</td>");
  1081. sb.append("<td>").append(videoInfoOther.getScore()).append("</td>");
  1082. sb.append("<td>").append(videoInfoOther.getComment()).append("</td>");
  1083. sb.append("<td>").append(videoInfoOther.getCommentFirst()).append("</td>");
  1084. sb.append("<td>").append(videoInfoOther.getResolutionRatio()).append("</td>");
  1085. sb.append("<td>").append(videoInfoOther.getOriginal() == null ? "?" : (videoInfoOther.getOriginal() == 1 ? "是" : "否")).append("</td>");
  1086. sb.append("<td>").append(videoInfoOther.getSubtitle() == null ? "?" : (videoInfoOther.getSubtitle() == 1 ? "是" : "否")).append("</td>");
  1087. sb.append("<td>").append(videoInfoOther.getRecoding() == null ? "?" : (videoInfoOther.getRecoding() == 1 ? "是" : "否")).append("</td>");
  1088. sb.append("<td>").append(videoInfoOther.getCreateTime()).append("</td>");
  1089. sb.append("<td>").append(videoInfoOther.getModifyTime()).append("</td>");
  1090. sb.append("</tr>");
  1091. }
  1092. sb.append("</table>");
  1093. return sb.toString();
  1094. }
  1095. /**
  1096. * 增加影片
  1097. *
  1098. * @param identificationCode
  1099. * @param videoName
  1100. * @param parentType
  1101. * @param parentName
  1102. * @param type
  1103. * @author lvzhiqiang
  1104. * 2022/9/27 20:54
  1105. */
  1106. @Override
  1107. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  1108. public void insertVideoInfo(String identificationCode, String videoName, Integer parentType, String parentName, Integer type) {
  1109. String parentFullName;
  1110. if (parentType == 1) {
  1111. parentFullName = "(类别)" + parentName;
  1112. VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
  1113. videoInfoGenres.setIdentificationCode(identificationCode);
  1114. videoInfoGenres.setName(parentName);
  1115. videoInfoGenres.setType(type);
  1116. videoInfoGenresMapper.insert(videoInfoGenres);
  1117. VideoGenres videoGenres = new VideoGenres();
  1118. videoGenres.setName(parentName);
  1119. videoGenresMapper.insertOrUpdate(videoGenres);
  1120. } else if (parentType == 2) {
  1121. parentFullName = "(男优)" + parentName;
  1122. VideoInfoCast videoInfoCast = new VideoInfoCast();
  1123. videoInfoCast.setIdentificationCode(identificationCode);
  1124. videoInfoCast.setName(parentName);
  1125. videoInfoCast.setType(type);
  1126. videoInfoCastMapper.insert(videoInfoCast);
  1127. VideoCast videoCast = new VideoCast();
  1128. videoCast.setName(parentName);
  1129. videoCast.setType(1);
  1130. videoCastMapper.insertOrUpdate(videoCast);
  1131. } else if (parentType == 3) {
  1132. parentFullName = "(女优)" + parentName;
  1133. VideoInfoCast videoInfoCast = new VideoInfoCast();
  1134. videoInfoCast.setIdentificationCode(identificationCode);
  1135. videoInfoCast.setName(parentName);
  1136. videoInfoCast.setType(type);
  1137. videoInfoCastMapper.insert(videoInfoCast);
  1138. VideoCast videoCast = new VideoCast();
  1139. videoCast.setName(parentName);
  1140. videoCast.setType(2);
  1141. videoCastMapper.insertOrUpdate(videoCast);
  1142. } else {
  1143. throw new RuntimeException("parentType类型错误");
  1144. }
  1145. // 主体
  1146. if (type == 1) {
  1147. VideoInfo videoInfo = new VideoInfo();
  1148. videoInfo.setIdentificationCode(identificationCode);
  1149. videoInfo.setType(1);
  1150. // 视频URL
  1151. videoInfo.setVideoUrl(parentFullName.concat("/").concat(videoName));
  1152. // 修改时间
  1153. videoInfo.setCreateTime(LocalDateTime.now());
  1154. // 主体是谁
  1155. videoInfo.setMainWho(parentFullName);
  1156. videoInfoMapper.insertOrUpdate(videoInfo);
  1157. }
  1158. }
  1159. /**
  1160. * 初始化骑兵数据
  1161. */
  1162. @Override
  1163. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  1164. @Async
  1165. public void initVideoInfoData(Integer type, Integer isDel, String infantryType) {
  1166. long startTime = System.currentTimeMillis();
  1167. DicCode dicCode = null;
  1168. if (type == 1) {
  1169. dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "qibing_path".equals(x.getCodeKey())).findFirst().get();
  1170. } else if (type == 3) {
  1171. dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get();
  1172. } else if (type == 2) {
  1173. dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "bubing_path".equals(x.getCodeKey())).findFirst().get();
  1174. }
  1175. if (dicCode == null) {
  1176. return;
  1177. }
  1178. String picPath = dicCode.getCodeValue();
  1179. if (type == 1) {
  1180. JavAllInfo javAllInfo = new JavAllInfo();
  1181. // 删除所有
  1182. if (isDel == 1) {
  1183. videoGenresMapper.deleteAll();
  1184. videoInfoMapper.deleteAll();
  1185. videoCastMapper.deleteAll();
  1186. videoInfoGenresMapper.deleteAll();
  1187. videoInfoCastMapper.deleteAll();
  1188. }
  1189. ignoreFileTypeSuffix = dicCodeMapper.findByCodeKey("ignore_filetype_suffix", null).stream()
  1190. .filter(x -> x.getEnv().contains(env)).findFirst().get().getCodeValue();
  1191. List<String> allIcode = videoInfoMapper.findAllIcode();
  1192. getAllFilePaths(picPath, javAllInfo, allIcode);
  1193. saveInfo(javAllInfo, isDel);
  1194. } else if (type == 3) {
  1195. JavAllInfo4Uncensored javAllInfo4Uncensored = new JavAllInfo4Uncensored();
  1196. getAllFilePaths4Uncensored(picPath, javAllInfo4Uncensored);
  1197. saveInfo4Uncensored(javAllInfo4Uncensored, isDel);
  1198. } else if (type == 2) {
  1199. JavAllInfo4Infantry javAllInfo4Infantry = new JavAllInfo4Infantry();
  1200. picPath = picPath.concat(infantryType);
  1201. getAllFilePaths4Infantry(picPath, javAllInfo4Infantry, infantryType);
  1202. saveInfo4Infantry(javAllInfo4Infantry, isDel, infantryType);
  1203. }
  1204. long endTime = System.currentTimeMillis();
  1205. System.err.println((endTime - startTime) / 1000);
  1206. }
  1207. /**
  1208. * 上传识别码文件
  1209. *
  1210. * @param is
  1211. */
  1212. @Override
  1213. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  1214. @Async
  1215. public void uploadFile4IdentificationCode(InputStream is, Integer isDel) {
  1216. if (isDel == 1) {
  1217. icodePoolMapper.deleteAll();
  1218. }
  1219. List<String> uploadIcodeList = readFromIcodeStream(is);
  1220. List<String> icodePoolList = icodePoolMapper.findIcode();
  1221. // 过滤库中已存在的
  1222. Integer beforeUploadSize = uploadIcodeList.size();
  1223. uploadIcodeList.removeAll(icodePoolList);
  1224. log.warn("uploadFile4IdentificationCode:beforeUpload={},icodePool={},afterUpload={}", beforeUploadSize, icodePoolList.size(), uploadIcodeList.size());
  1225. // 插入
  1226. int num = 0;
  1227. if (uploadIcodeList.size() > 0) {
  1228. num = icodePoolMapper.insertList(uploadIcodeList);
  1229. }
  1230. log.warn("uploadFile4IdentificationCode:success={}", num);
  1231. }
  1232. /**
  1233. * 单个识别码
  1234. *
  1235. * @param identificationCode
  1236. */
  1237. @Override
  1238. public void single4IdentificationCode(String identificationCode, String url) {
  1239. identificationCode = identificationCode.trim().toUpperCase();
  1240. List<String> icodePoolList = icodePoolMapper.findIcodeByCode(identificationCode);
  1241. if (icodePoolList.size() > 0) {
  1242. throw new BusinessException(ResultCodeEnum.PARAM_DATA_EXIST_ERROR);
  1243. }
  1244. icodePoolMapper.insert(identificationCode, url);
  1245. }
  1246. /**
  1247. * Jsoup IcodePool
  1248. *
  1249. * @param status
  1250. */
  1251. @Async
  1252. @Override
  1253. public String jsoupIcodePool(String website, Integer status, Integer isDel, Integer ignoreRetryCount) {
  1254. log.warn("jsoupIcodePool 开始:website={},status={},isDel={},ignoreRetryCount={}", website, status, isDel, ignoreRetryCount);
  1255. if (isDel == 1) {
  1256. videoInfoPoolMapper.deleteAll();
  1257. }
  1258. // 获取待抓取码列表
  1259. List<String> icodePoolList;
  1260. if (1 == ignoreRetryCount) {
  1261. icodePoolList = icodePoolMapper.findIcodeByStatus4IgnoreRetryCount(status);
  1262. } else {
  1263. icodePoolList = icodePoolMapper.findIcodeByStatus(status);
  1264. }
  1265. if (icodePoolList.size() == 0) {
  1266. log.warn("status={}的icodePoolList为空", status);
  1267. return "size:0";
  1268. }
  1269. // 获取javbus防屏蔽地址
  1270. List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
  1271. if (javbusUrlList.size() == 0) {
  1272. log.warn("javbusUrlList为空");
  1273. return "javbusUrlList为空";
  1274. }
  1275. // 获取主表所有识别码
  1276. List<String> allIcode = videoInfoMapper.findAllIcode();
  1277. // 获取码池图片保存路径
  1278. String machiPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
  1279. // 遍历
  1280. Document document;
  1281. VideoInfoPool videoInfoPool;
  1282. String javbusUrl;
  1283. int j = 0;
  1284. for (int i = 0; i < icodePoolList.size(); i++) {
  1285. long start = System.currentTimeMillis();
  1286. String[] identificationCodeArr = icodePoolList.get(i).split("\\|");
  1287. IcodePool icodePool = new IcodePool();
  1288. icodePool.setIdentificationCode(identificationCodeArr[0]);
  1289. if (allIcode.contains(identificationCodeArr[0])) {
  1290. icodePool.setStatus(4);
  1291. icodePool.setRetryCount(0);
  1292. icodePoolMapper.updateStatus(icodePool);
  1293. log.warn("jsoupIcodePool exists:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCodeArr[0]);
  1294. continue;
  1295. }
  1296. int retryCount = 0;
  1297. while (retryCount <= 3) {
  1298. javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
  1299. try {
  1300. videoInfoPool = new VideoInfoPool();
  1301. long picTime = 0;
  1302. if ("javbus".equalsIgnoreCase(website)) {
  1303. document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCodeArr[0]))
  1304. .timeout(50000)
  1305. //.proxy()
  1306. //.data()
  1307. .ignoreContentType(true)
  1308. .userAgent(getUserAgent())
  1309. .header("referer", javbusUrl.concat("/").concat(identificationCodeArr[0]))
  1310. .get();
  1311. picTime = parseDocument(document, identificationCodeArr[0], machiPath, videoInfoPool);
  1312. } else if ("javdb".equalsIgnoreCase(website) && StringUtils.isNotEmpty(identificationCodeArr[1])) {
  1313. Map<String, String> headerMap = new HashMap<>();
  1314. headerMap.put("referer", identificationCodeArr[1]);
  1315. beforeProxy();
  1316. document = JsoupUtil.requestDocument(identificationCodeArr[1], JsoupUtil.HTTP_GET, proxy2, null, headerMap, null);
  1317. picTime = parseDocument4Javdb(document, identificationCodeArr[0], machiPath, videoInfoPool);
  1318. }
  1319. if (videoInfoPool != null) {
  1320. icodePool.setStatus(2);
  1321. icodePool.setRetryCount(retryCount);
  1322. icodePoolMapper.updateStatus(icodePool);
  1323. videoInfoPoolMapper.insert(videoInfoPool);
  1324. j++;
  1325. }
  1326. log.warn("jsoupIcodePool success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCodeArr[0]);
  1327. break;
  1328. } catch (Exception e) {
  1329. ++retryCount;
  1330. if (retryCount < 4) {
  1331. log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCodeArr[0], javbusUrl, e);
  1332. } else if (retryCount == 4) {
  1333. icodePool.setStatus(3);
  1334. icodePool.setRetryCount(retryCount - 1);
  1335. icodePool.setFailureCause(e.getMessage().length() <= 200 ? e.getMessage() : e.getMessage().substring(0, 200));
  1336. icodePoolMapper.updateStatus(icodePool);
  1337. log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCodeArr[0], e);
  1338. }
  1339. }
  1340. }
  1341. }
  1342. log.warn("jsoupIcodePool 统计:total={},success={}", icodePoolList.size(), j);
  1343. return "total=".concat(String.valueOf(icodePoolList.size())).concat(",success=").concat(String.valueOf(j));
  1344. }
  1345. private String getUserAgent() {
  1346. Random r = new Random();
  1347. String[] ua = {"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
  1348. "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",
  1349. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
  1350. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
  1351. "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",
  1352. "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
  1353. "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
  1354. "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
  1355. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)",
  1356. "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",
  1357. "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",
  1358. "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",
  1359. "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",
  1360. "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 TheWorld 7",
  1361. "Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/60.0",
  1362. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"};
  1363. int i = r.nextInt(15);
  1364. return ua[i];
  1365. }
  1366. private long parseDocument(Document document, String identificationCode, String machiPath, VideoInfoPool videoInfoPool) throws Exception {
  1367. Elements container = document.select("div.container");
  1368. if (container.size() == 0) {
  1369. throw new Exception("番号无效!");
  1370. }
  1371. // 名称
  1372. String h3 = container.select("h3").first().text().replace("/", "");
  1373. String[] nameArr = h3.split("\\s+");
  1374. if (nameArr.length > 1) {
  1375. videoInfoPool.setName(h3.substring(nameArr[0].length()).trim());
  1376. } else {
  1377. videoInfoPool.setName(nameArr[0]);
  1378. }
  1379. Elements pEles = container.select("div.info > p");
  1380. // 识别码
  1381. Element pEle = pEles.get(0);
  1382. String iCode = pEle.select("span[style]").first().text();
  1383. if (!identificationCode.equalsIgnoreCase(iCode)) {
  1384. throw new Exception("番号与站点不一致");
  1385. }
  1386. videoInfoPool.setIdentificationCode(iCode);
  1387. // 发行日期
  1388. pEle = pEles.get(1);
  1389. String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
  1390. videoInfoPool.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1391. // 长度
  1392. pEle = pEles.get(2);
  1393. String length = pEle.text().split(":")[1].replace("\"", "").trim();
  1394. videoInfoPool.setLength(length);
  1395. // 导演
  1396. Elements directorEles = container.select("div.info").select("p:contains(導演)");
  1397. if (directorEles.size() > 0) {
  1398. pEle = directorEles.first().select("a[href]").first();
  1399. videoInfoPool.setDirector(pEle.text());
  1400. }
  1401. // 制作商
  1402. Elements markerEles = container.select("div.info").select("p:contains(製作商)");
  1403. if (markerEles.size() > 0) {
  1404. pEle = markerEles.first().select("a[href]").first();
  1405. videoInfoPool.setMaker(pEle.text());
  1406. }
  1407. // 发行商
  1408. Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
  1409. if (issuerEles.size() > 0) {
  1410. pEle = issuerEles.first().select("a[href]").first();
  1411. videoInfoPool.setIssuer(pEle.text());
  1412. }
  1413. // 类别
  1414. Elements genresEles = container.select("div.info").select("p:contains(類別)");
  1415. if (genresEles.size() > 0) {
  1416. StringBuffer sb = new StringBuffer();
  1417. Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
  1418. for (Element ahrefEle : ahrefEles) {
  1419. sb.append(ahrefEle.text()).append(",");
  1420. }
  1421. if (sb.length() > 0) {
  1422. sb = sb.deleteCharAt(sb.length() - 1);
  1423. }
  1424. videoInfoPool.setGenres(sb.toString());
  1425. }
  1426. // 演员
  1427. Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
  1428. if (castEles.size() > 0) {
  1429. Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
  1430. if (castElesTemp.size() == 0) {
  1431. StringBuffer sb = new StringBuffer();
  1432. Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
  1433. for (Element ahrefEle : ahrefEles) {
  1434. sb.append(ahrefEle.text()).append(",");
  1435. }
  1436. if (sb.length() > 0) {
  1437. sb = sb.deleteCharAt(sb.length() - 1);
  1438. }
  1439. videoInfoPool.setCast(sb.toString());
  1440. }
  1441. }
  1442. // 图片URL
  1443. String href = container.select("a.bigImage").first().attr("abs:href");
  1444. long start = System.currentTimeMillis();
  1445. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1446. String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
  1447. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  1448. if (imgUrlBytes.length > 251) {
  1449. byte[] imgUrlDestBytes = new byte[251];
  1450. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  1451. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  1452. }
  1453. fileName = fileName.concat(".jpg");
  1454. String machiImgUrl = "码池/".concat(fileName);
  1455. saveFile(response.bodyStream(), machiPath.concat(machiImgUrl));
  1456. long end = System.currentTimeMillis();
  1457. videoInfoPool.setImgUrl(machiImgUrl);
  1458. videoInfoPool.setCreateTime(LocalDateTime.now());
  1459. videoInfoPool.setType(1);
  1460. return end - start;
  1461. }
  1462. private long parseDocument4Javdb(Document javdbCodeDocument, String identificationCode, String machiPath, VideoInfoPool videoInfoPool) throws Exception {
  1463. Elements container = javdbCodeDocument.select("section.section > div.container");
  1464. if (container.size() == 0) {
  1465. throw new BusinessException(30000, "番号无效!");
  1466. }
  1467. Elements videoDetail = container.select("div.video-detail");
  1468. // 名称
  1469. videoInfoPool.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
  1470. Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
  1471. Element pEle = moviePanelInfos.get(0);
  1472. // 识别码
  1473. String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  1474. if (!identificationCode.equalsIgnoreCase(iCode)) {
  1475. throw new Exception("番号与站点不一致");
  1476. }
  1477. videoInfoPool.setIdentificationCode(iCode);
  1478. // 发行日期
  1479. String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  1480. videoInfoPool.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1481. // 长度
  1482. String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  1483. videoInfoPool.setLength(length);
  1484. // 导演
  1485. Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
  1486. if (directorEles.size() > 0) {
  1487. videoInfoPool.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  1488. }
  1489. // 制作商
  1490. Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
  1491. if (markerEles.size() > 0) {
  1492. videoInfoPool.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  1493. }
  1494. // 发行商
  1495. Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
  1496. if (issuerEles.size() > 0) {
  1497. videoInfoPool.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  1498. }
  1499. // 类别
  1500. Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
  1501. if (genresEles.size() > 0) {
  1502. StringBuffer sb = new StringBuffer();
  1503. Elements ahrefEles = genresEles.first().select("a[href]");
  1504. for (Element ahrefEle : ahrefEles) {
  1505. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  1506. }
  1507. if (sb.length() > 0) {
  1508. sb = sb.deleteCharAt(sb.length() - 1);
  1509. }
  1510. videoInfoPool.setGenres(sb.toString());
  1511. }
  1512. // 演员
  1513. Elements castEles = pEle.select("div:contains(演員)").select("span.value");
  1514. if (castEles.size() > 0) {
  1515. StringBuffer sb = new StringBuffer();
  1516. Elements ahrefEles = castEles.first().select("a[href]");
  1517. for (Element ahrefEle : ahrefEles) {
  1518. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  1519. }
  1520. if (sb.length() > 0) {
  1521. sb = sb.deleteCharAt(sb.length() - 1);
  1522. }
  1523. videoInfoPool.setCast(sb.toString());
  1524. }
  1525. // 图片URL
  1526. String href = videoDetail.select("div.column-video-cover").select("a > img").first().attr("src");
  1527. long start = System.currentTimeMillis();
  1528. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1529. String fileName = issueDate.concat(" ").concat(videoInfoPool.getIdentificationCode()).concat(" ").concat(StringUtils.escapeJavParam(videoInfoPool.getName()));
  1530. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  1531. if (imgUrlBytes.length > 251) {
  1532. byte[] imgUrlDestBytes = new byte[251];
  1533. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  1534. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  1535. }
  1536. fileName = fileName.concat(".jpg");
  1537. String machiImgUrl = "码池/".concat(fileName);
  1538. saveFile(response.bodyStream(), machiPath.concat(machiImgUrl));
  1539. long end = System.currentTimeMillis();
  1540. videoInfoPool.setImgUrl(machiImgUrl);
  1541. videoInfoPool.setCreateTime(LocalDateTime.now());
  1542. videoInfoPool.setType(1);
  1543. return end - start;
  1544. }
  1545. private void parseDocument4Uncensored(Document document, String identificationCode, String machiPath, VideoInfoUncensored videoInfoUncensored) throws Exception {
  1546. Elements container = document.select("div.container");
  1547. if (container.size() == 0) {
  1548. throw new Exception("番号无效!");
  1549. }
  1550. Elements pEles = container.select("div.info > p");
  1551. // 识别码
  1552. Element pEle = pEles.get(0);
  1553. String iCode = pEle.select("span[style]").first().text();
  1554. if (!identificationCode.equalsIgnoreCase(iCode)) {
  1555. throw new Exception("番号与站点不一致");
  1556. }
  1557. // 长度
  1558. pEle = pEles.get(2);
  1559. String length = pEle.text().split(":")[1].replace("\"", "").trim();
  1560. videoInfoUncensored.setLength(length);
  1561. // 导演
  1562. Elements directorEles = container.select("div.info").select("p:contains(導演)");
  1563. if (directorEles.size() > 0) {
  1564. pEle = directorEles.first().select("a[href]").first();
  1565. videoInfoUncensored.setDirector(pEle.text());
  1566. }
  1567. // 制作商
  1568. Elements markerEles = container.select("div.info").select("p:contains(製作商)");
  1569. if (markerEles.size() > 0) {
  1570. pEle = markerEles.first().select("a[href]").first();
  1571. videoInfoUncensored.setMaker(pEle.text());
  1572. }
  1573. // 发行商
  1574. Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
  1575. if (issuerEles.size() > 0) {
  1576. pEle = issuerEles.first().select("a[href]").first();
  1577. videoInfoUncensored.setIssuer(pEle.text());
  1578. }
  1579. // 类别
  1580. Elements genresEles = container.select("div.info").select("p:contains(類別)");
  1581. if (genresEles.size() > 0) {
  1582. StringBuffer sb = new StringBuffer();
  1583. Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
  1584. for (Element ahrefEle : ahrefEles) {
  1585. sb.append(ahrefEle.text()).append(",");
  1586. }
  1587. if (sb.length() > 0) {
  1588. sb = sb.deleteCharAt(sb.length() - 1);
  1589. }
  1590. videoInfoUncensored.setGenres(sb.toString());
  1591. }
  1592. // 演员
  1593. Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
  1594. if (castEles.size() > 0) {
  1595. Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
  1596. if (castElesTemp.size() == 0) {
  1597. StringBuffer sb = new StringBuffer();
  1598. Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
  1599. for (Element ahrefEle : ahrefEles) {
  1600. sb.append(ahrefEle.text()).append(",");
  1601. }
  1602. if (sb.length() > 0) {
  1603. sb = sb.deleteCharAt(sb.length() - 1);
  1604. }
  1605. videoInfoUncensored.setCast(sb.toString());
  1606. }
  1607. }
  1608. }
  1609. private String parseDocument4QiBing(Document document, String identificationCode, String qibingPath, VideoInfo videoInfo) throws Exception {
  1610. Elements container = document.select("div.container");
  1611. if (container.size() == 0) {
  1612. throw new Exception("番号无效!");
  1613. }
  1614. // 名称
  1615. String h3 = container.select("h3").first().text();
  1616. String[] nameArr = h3.split("\\s+");
  1617. if (nameArr.length > 1) {
  1618. videoInfo.setName(h3.substring(nameArr[0].length()).trim());
  1619. } else {
  1620. videoInfo.setName(nameArr[0]);
  1621. }
  1622. Elements pEles = container.select("div.info > p");
  1623. // 识别码
  1624. Element pEle = pEles.get(0);
  1625. String iCode = pEle.select("span[style]").first().text();
  1626. if (!identificationCode.equalsIgnoreCase(iCode)) {
  1627. throw new Exception("番号与站点不一致");
  1628. }
  1629. // 发行日期
  1630. pEle = pEles.get(1);
  1631. String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
  1632. videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1633. // 长度
  1634. pEle = pEles.get(2);
  1635. String length = pEle.text().split(":")[1].replace("\"", "").trim();
  1636. videoInfo.setLength(length);
  1637. // 导演
  1638. Elements directorEles = container.select("div.info").select("p:contains(導演)");
  1639. if (directorEles.size() > 0) {
  1640. pEle = directorEles.first().select("a[href]").first();
  1641. videoInfo.setDirector(pEle.text());
  1642. }
  1643. // 制作商
  1644. Elements markerEles = container.select("div.info").select("p:contains(製作商)");
  1645. if (markerEles.size() > 0) {
  1646. pEle = markerEles.first().select("a[href]").first();
  1647. videoInfo.setMaker(pEle.text());
  1648. }
  1649. // 发行商
  1650. Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
  1651. if (issuerEles.size() > 0) {
  1652. pEle = issuerEles.first().select("a[href]").first();
  1653. videoInfo.setIssuer(pEle.text());
  1654. }
  1655. // 类别
  1656. Elements genresEles = container.select("div.info").select("p:contains(類別)");
  1657. if (genresEles.size() > 0) {
  1658. StringBuffer sb = new StringBuffer();
  1659. Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
  1660. for (Element ahrefEle : ahrefEles) {
  1661. sb.append(ahrefEle.text()).append(",");
  1662. }
  1663. if (sb.length() > 0) {
  1664. sb = sb.deleteCharAt(sb.length() - 1);
  1665. }
  1666. videoInfo.setGenres(sb.toString());
  1667. }
  1668. // 演员
  1669. Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
  1670. if (castEles.size() > 0) {
  1671. Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
  1672. if (castElesTemp.size() == 0) {
  1673. StringBuffer sb = new StringBuffer();
  1674. Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
  1675. for (Element ahrefEle : ahrefEles) {
  1676. sb.append(ahrefEle.text()).append(",");
  1677. }
  1678. if (sb.length() > 0) {
  1679. sb = sb.deleteCharAt(sb.length() - 1);
  1680. }
  1681. videoInfo.setCast(sb.toString());
  1682. }
  1683. }
  1684. // 图片 骑兵
  1685. String qibings = "骑兵/".concat(iCode);
  1686. StringBuffer picTime = new StringBuffer("{cover:");
  1687. // 图片URL bigImage
  1688. String qibingCover = qibings.concat("/cover/");
  1689. String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
  1690. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  1691. if (imgUrlBytes.length > 251) {
  1692. byte[] imgUrlDestBytes = new byte[251];
  1693. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  1694. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  1695. }
  1696. fileName = fileName.concat(".jpg");
  1697. if (!new File(qibingPath.concat(qibingCover), fileName).exists()) {
  1698. String href = container.select("a.bigImage").first().attr("abs:href");
  1699. long start = System.currentTimeMillis();
  1700. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1701. saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
  1702. picTime.append(System.currentTimeMillis() - start).append(",");
  1703. }
  1704. videoInfo.setImgUrl(qibingCover.concat(fileName));
  1705. // 图片URL img_gf
  1706. String qibingImgGF = qibings.concat("/img_gf/");
  1707. File qibingImgGFFile = new File(qibingPath.concat(qibingImgGF));
  1708. if (!qibingImgGFFile.exists() || qibingImgGFFile.listFiles().length == 0) {
  1709. Elements sampleBoxEles = container.select("div#sample-waterfall").select("a");
  1710. long start2 = System.currentTimeMillis();
  1711. if (sampleBoxEles.size() > 0) {
  1712. Connection.Response responseImg;
  1713. for (Element sampleBoxEle : sampleBoxEles) {
  1714. String sampleBoxHref = sampleBoxEle.attr("href");
  1715. if (!sampleBoxHref.contains("http")) {
  1716. sampleBoxHref = sampleBoxEle.attr("abs:href");
  1717. }
  1718. try {
  1719. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1720. } catch (HttpStatusException e) {
  1721. sampleBoxHref = sampleBoxEle.select("img").attr("src");
  1722. if (!sampleBoxHref.contains("http")) {
  1723. sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
  1724. }
  1725. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1726. }
  1727. String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
  1728. saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
  1729. }
  1730. } else {
  1731. log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
  1732. }
  1733. picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
  1734. }
  1735. return picTime.toString();
  1736. }
  1737. private String parseDocument4QiBing4Javdb(Document javdbCodeDocument, String identificationCode, String qibingPath, VideoInfo videoInfo) throws Exception {
  1738. Elements container = javdbCodeDocument.select("section.section > div.container");
  1739. if (container.size() == 0) {
  1740. throw new BusinessException(30000, "番号无效!");
  1741. }
  1742. Elements videoDetail = container.select("div.video-detail");
  1743. // 名称
  1744. videoInfo.setName(videoDetail.select("h2.title").select("strong.current-title").text().trim());
  1745. Elements originTitle = videoDetail.select("h2.title").select("span.origin-title");
  1746. if (originTitle.size() > 0) {
  1747. videoInfo.setName(originTitle.text().trim());
  1748. }
  1749. Elements moviePanelInfos = videoDetail.select("nav.movie-panel-info");
  1750. Element pEle = moviePanelInfos.get(0);
  1751. // 识别码
  1752. String iCode = pEle.select("div:contains(番號)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  1753. if (!identificationCode.equalsIgnoreCase(iCode)) {
  1754. throw new Exception("番号与站点不一致");
  1755. }
  1756. // 发行日期
  1757. String issueDate = pEle.select("div:contains(日期)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  1758. videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1759. // 长度
  1760. String length = pEle.select("div:contains(時長)").select("span.value").first().text().replace(" ", "").replaceAll("\\s+", "");
  1761. videoInfo.setLength(length);
  1762. // 导演
  1763. Elements directorEles = pEle.select("div:contains(導演)").select("span.value");
  1764. if (directorEles.size() > 0) {
  1765. videoInfo.setDirector(directorEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  1766. }
  1767. // 制作商
  1768. Elements markerEles = pEle.select("div:contains(片商)").select("span.value");
  1769. if (markerEles.size() > 0) {
  1770. videoInfo.setMaker(markerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  1771. }
  1772. // 发行商
  1773. Elements issuerEles = pEle.select("div:contains(發行)").select("span.value");
  1774. if (issuerEles.size() > 0) {
  1775. videoInfo.setIssuer(issuerEles.first().select("a[href]").first().text().replace(" ", "").replaceAll("\\s+", ""));
  1776. }
  1777. // 类别
  1778. Elements genresEles = pEle.select("div:contains(類別)").select("span.value");
  1779. if (genresEles.size() > 0) {
  1780. StringBuffer sb = new StringBuffer();
  1781. Elements ahrefEles = genresEles.first().select("a[href]");
  1782. for (Element ahrefEle : ahrefEles) {
  1783. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  1784. }
  1785. if (sb.length() > 0) {
  1786. sb = sb.deleteCharAt(sb.length() - 1);
  1787. }
  1788. videoInfo.setGenres(sb.toString());
  1789. }
  1790. // 演员
  1791. Elements castEles = pEle.select("div:contains(演員)").select("span.value");
  1792. if (castEles.size() > 0) {
  1793. StringBuffer sb = new StringBuffer();
  1794. Elements ahrefEles = castEles.first().select("a[href]");
  1795. for (Element ahrefEle : ahrefEles) {
  1796. sb.append(ahrefEle.text().replace(" ", "").replaceAll("\\s+", "")).append(",");
  1797. }
  1798. if (sb.length() > 0) {
  1799. sb = sb.deleteCharAt(sb.length() - 1);
  1800. }
  1801. videoInfo.setCast(sb.toString());
  1802. }
  1803. // 图片 骑兵
  1804. String qibings = "骑兵/".concat(iCode);
  1805. StringBuffer picTime = new StringBuffer("{cover:");
  1806. // 图片URL bigImage
  1807. String qibingCover = qibings.concat("/cover/");
  1808. String fileName = issueDate.concat(" ").concat(videoInfo.getIdentificationCode()).concat(" ").concat(videoInfo.getName()).replace("?", "?");
  1809. byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
  1810. if (imgUrlBytes.length > 251) {
  1811. byte[] imgUrlDestBytes = new byte[251];
  1812. System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
  1813. fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
  1814. }
  1815. fileName = fileName.concat(".jpg");
  1816. if (!new File(qibingPath.concat(qibingCover), fileName).exists()) {
  1817. Elements videoMetaPanel = videoDetail.select("div.column-video-cover");
  1818. String href = videoMetaPanel.select("a > img").first().attr("src");
  1819. long start = System.currentTimeMillis();
  1820. Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1821. saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
  1822. picTime.append(System.currentTimeMillis() - start).append(",");
  1823. }
  1824. videoInfo.setImgUrl(qibingCover.concat(fileName));
  1825. // 图片URL img_gf
  1826. String qibingImgGF = qibings.concat("/img_gf/");
  1827. File qibingImgGFFile = new File(qibingPath.concat(qibingImgGF));
  1828. if (!qibingImgGFFile.exists() || qibingImgGFFile.listFiles().length == 0) {
  1829. Elements sampleBoxEles = videoDetail.select("div.preview-images").select("a.tile-item");
  1830. long start2 = System.currentTimeMillis();
  1831. if (sampleBoxEles.size() > 0) {
  1832. Connection.Response responseImg;
  1833. for (Element sampleBoxEle : sampleBoxEles) {
  1834. String sampleBoxHref = sampleBoxEle.attr("href");
  1835. if (!sampleBoxHref.contains("http")) {
  1836. sampleBoxHref = sampleBoxEle.attr("abs:href");
  1837. }
  1838. try {
  1839. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1840. } catch (HttpStatusException e) {
  1841. sampleBoxHref = sampleBoxEle.select("img").attr("src");
  1842. if (!sampleBoxHref.contains("http")) {
  1843. sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
  1844. }
  1845. responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
  1846. }
  1847. String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
  1848. saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
  1849. }
  1850. } else {
  1851. log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
  1852. }
  1853. picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
  1854. }
  1855. return picTime.toString();
  1856. }
  1857. /**
  1858. * 保存文件到本地2
  1859. *
  1860. * @param bufferedInputStream
  1861. * @param savePathPrex
  1862. * @param fileName
  1863. */
  1864. private void saveFile2(BufferedInputStream bufferedInputStream, String savePathPrex, String fileName) throws IOException {
  1865. File savePathPrexFile = new File(savePathPrex);
  1866. // 判断目录是否存在,如果不存在则新建
  1867. if (!savePathPrexFile.exists()) {
  1868. boolean result = savePathPrexFile.mkdirs();
  1869. if (!result) {
  1870. throw new IOException("创建目录失败!");
  1871. }
  1872. }
  1873. //一次最多读取1k
  1874. byte[] buffer = new byte[1024];
  1875. //实际读取的长度
  1876. int readLenghth;
  1877. //创建的一个写出的缓冲流
  1878. BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePathPrexFile, fileName)));
  1879. //文件逐步写入本地
  1880. while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
  1881. bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
  1882. }
  1883. //关闭缓冲流
  1884. bufferedOutputStream.close();
  1885. bufferedInputStream.close();
  1886. }
  1887. /**
  1888. * 保存文件到本地
  1889. *
  1890. * @param bufferedInputStream
  1891. * @param savePath
  1892. */
  1893. private void saveFile(BufferedInputStream bufferedInputStream, String savePath) throws IOException {
  1894. //一次最多读取1k
  1895. byte[] buffer = new byte[1024];
  1896. //实际读取的长度
  1897. int readLenghth;
  1898. //创建的一个写出的缓冲流
  1899. BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePath)));
  1900. //文件逐步写入本地
  1901. while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
  1902. bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
  1903. }
  1904. //关闭缓冲流
  1905. bufferedOutputStream.close();
  1906. bufferedInputStream.close();
  1907. }
  1908. // 递归获取某目录下的所有子目录以及子文件
  1909. private void getAllFilePaths(String filePath, JavAllInfo javAllInfo, List<String> allIcode) {
  1910. File[] files = new File(filePath).listFiles();
  1911. if (files == null) {
  1912. return;
  1913. }
  1914. int type = 0;
  1915. if (filePath.contains("骑兵")) {
  1916. type = 1;
  1917. } else if (filePath.contains("步兵")) {
  1918. type = 2;
  1919. }
  1920. Set<String> sameNameSet = new HashSet<>();
  1921. for (File file : files) {
  1922. if (file.isDirectory()) {
  1923. // 文件夹
  1924. getAllFilePaths(file.getAbsolutePath(), javAllInfo, allIcode);
  1925. } else {
  1926. String fileName = file.getName();
  1927. String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
  1928. if (!ignoreFileTypeSuffix.contains(fileSuffix)) {
  1929. String parentName = file.getParentFile().getName();
  1930. // 识别码
  1931. String name = fileName.substring(10, fileName.lastIndexOf(".")).trim();
  1932. String[] nameArr = name.split("\\s+");
  1933. try {
  1934. boolean isMain = false;
  1935. if (!fileName.endsWith(".lnk")) {
  1936. if (allIcode.contains(nameArr[0]) || sameNameSet.contains(nameArr[0])) {
  1937. continue;
  1938. }
  1939. isMain = true;
  1940. // 获取正片信息
  1941. VideoInfo videoInfo = new VideoInfo();
  1942. // 发行日期
  1943. //String issueDate = fileName.substring(0, 10);
  1944. //videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  1945. // 识别码
  1946. videoInfo.setIdentificationCode(nameArr[0]);
  1947. // 名称
  1948. //if (nameArr.length > 1) {
  1949. // videoInfo.setName(name.substring(nameArr[0].length()).trim());
  1950. //} else {
  1951. // videoInfo.setName(nameArr[0]);
  1952. //}
  1953. // 类型
  1954. videoInfo.setType(type);
  1955. // 图片URL
  1956. //videoInfo.setImgUrl(parentName.concat("/").concat(fileName));
  1957. // 视频URL
  1958. videoInfo.setVideoUrl(parentName.concat("/").concat(fileName));
  1959. // 创建时间 TODO
  1960. // 修改时间
  1961. videoInfo.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
  1962. // 主体是谁
  1963. videoInfo.setMainWho(parentName);
  1964. javAllInfo.getVideoInfoList().add(videoInfo);
  1965. sameNameSet.add(nameArr[0]);
  1966. }
  1967. if (parentName.contains("类别")) {
  1968. // 获取类别
  1969. String videoGenres = parentName.replace("(类别)", "");
  1970. javAllInfo.getVideoGenresSet().add(videoGenres);
  1971. VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
  1972. videoInfoGenres.setIdentificationCode(nameArr[0]);
  1973. videoInfoGenres.setName(videoGenres);
  1974. videoInfoGenres.setType(isMain ? 1 : 2);
  1975. javAllInfo.getVideoInfoGenresSet().add(videoInfoGenres);
  1976. } else if (parentName.contains("优)")) {
  1977. // 获取演员
  1978. String videoCast = "";
  1979. if (parentName.contains("(男")) {
  1980. videoCast = parentName.replace("(男优)", "");
  1981. javAllInfo.getVideoCastMap().put(videoCast, "1");
  1982. } else if (parentName.contains("(女")) {
  1983. videoCast = parentName.replace("(女优)", "");
  1984. javAllInfo.getVideoCastMap().put(videoCast, "2");
  1985. }
  1986. VideoInfoCast videoInfoCast = new VideoInfoCast();
  1987. videoInfoCast.setIdentificationCode(nameArr[0]);
  1988. videoInfoCast.setName(videoCast);
  1989. videoInfoCast.setType(isMain ? 1 : 2);
  1990. javAllInfo.getVideoInfoCastSet().add(videoInfoCast);
  1991. }
  1992. } catch (Exception e) {
  1993. System.err.println("error:" + file.getAbsolutePath());
  1994. System.err.println("error reason:" + e.getMessage());
  1995. }
  1996. } else {
  1997. System.out.println("other type file:" + file.getAbsolutePath());
  1998. }
  1999. }
  2000. }
  2001. }
  2002. private void getAllFilePaths4Uncensored(String filePath, JavAllInfo4Uncensored javAllInfo4Uncensored) {
  2003. File[] files = new File(filePath).listFiles();
  2004. if (files == null) {
  2005. return;
  2006. }
  2007. for (File file : files) {
  2008. if (file.isDirectory()) {
  2009. // 文件夹
  2010. getAllFilePaths4Uncensored(file.getAbsolutePath(), javAllInfo4Uncensored);
  2011. } else {
  2012. String fileName = file.getName();
  2013. if (fileName.endsWith(".jpg")) {
  2014. String parentName = file.getParentFile().getName();
  2015. // 识别码
  2016. String name = fileName.substring(10).replace(".jpg", "").trim();
  2017. String[] nameArr = name.split("\\s+");
  2018. try {
  2019. // 获取正片信息
  2020. VideoInfoUncensored videoInfoUncensored = new VideoInfoUncensored();
  2021. // 发行日期
  2022. String issueDate = fileName.substring(0, 10);
  2023. videoInfoUncensored.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  2024. videoInfoUncensored.setIdentificationCode(nameArr[0]);
  2025. // 名称
  2026. if (nameArr.length > 1) {
  2027. videoInfoUncensored.setName(name.substring(nameArr[0].length()).trim());
  2028. } else {
  2029. videoInfoUncensored.setName(nameArr[0]);
  2030. }
  2031. // 类型
  2032. videoInfoUncensored.setStatus(1);
  2033. // 图片URL
  2034. videoInfoUncensored.setImgUrl(parentName.concat("/").concat(fileName));
  2035. // 创建时间 TODO
  2036. // 修改时间
  2037. videoInfoUncensored.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
  2038. // 主体是谁
  2039. videoInfoUncensored.setMainWho(parentName);
  2040. javAllInfo4Uncensored.getVideoInfoUncensoredList().add(videoInfoUncensored);
  2041. System.out.println("success:" + file.getAbsolutePath());
  2042. } catch (Exception e) {
  2043. System.err.println("error:" + file.getAbsolutePath());
  2044. System.err.println("error reason:" + e.getMessage());
  2045. }
  2046. } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt")) {
  2047. String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
  2048. String parentName = file.getParentFile().getName();
  2049. javAllInfo4Uncensored.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
  2050. }
  2051. }
  2052. }
  2053. }
  2054. private void getAllFilePaths4Infantry(String filePath, JavAllInfo4Infantry javAllInfo4Infantry, String infantryType) {
  2055. File[] files = new File(filePath).listFiles();
  2056. if (files == null) {
  2057. return;
  2058. }
  2059. for (File file : files) {
  2060. if (file.isDirectory()) {
  2061. // 文件夹
  2062. getAllFilePaths4Infantry(file.getAbsolutePath(), javAllInfo4Infantry, infantryType);
  2063. } else {
  2064. String fileName = file.getName();
  2065. if (fileName.endsWith(".jpg")) {
  2066. String parentName = file.getParentFile().getName();
  2067. // 识别码
  2068. String name = fileName.substring(10).replace(".jpg", "").trim();
  2069. String[] nameArr = name.split("\\s+");
  2070. try {
  2071. // 获取正片信息
  2072. VideoInfoInfantry videoInfoInfantry = new VideoInfoInfantry();
  2073. // 发行日期
  2074. String issueDate = fileName.substring(0, 10);
  2075. videoInfoInfantry.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
  2076. videoInfoInfantry.setIdentificationCode(nameArr[0]);
  2077. // 名称
  2078. if (nameArr.length > 1) {
  2079. videoInfoInfantry.setName(name.substring(nameArr[0].length()).trim());
  2080. } else {
  2081. videoInfoInfantry.setName(nameArr[0]);
  2082. }
  2083. // 状态
  2084. videoInfoInfantry.setStatus(1);
  2085. // 类型
  2086. videoInfoInfantry.setType(infantryType);
  2087. // 图片URL
  2088. videoInfoInfantry.setImgUrl(parentName.concat("/").concat(fileName));
  2089. // 创建时间 TODO
  2090. // 修改时间
  2091. videoInfoInfantry.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
  2092. // 主体是谁
  2093. videoInfoInfantry.setMainWho(parentName);
  2094. javAllInfo4Infantry.getVideoInfoInfantryList().add(videoInfoInfantry);
  2095. System.out.println("success:" + file.getAbsolutePath());
  2096. } catch (Exception e) {
  2097. System.err.println("error:" + file.getAbsolutePath());
  2098. System.err.println("error reason:" + e.getMessage());
  2099. }
  2100. } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt") && !fileName.endsWith(".txt")) {
  2101. String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
  2102. String parentName = file.getParentFile().getName();
  2103. javAllInfo4Infantry.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
  2104. }
  2105. }
  2106. }
  2107. }
  2108. // 保存所有文件
  2109. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  2110. public void saveInfo(JavAllInfo javAllInfo, Integer isDel) {
  2111. // 保存分类
  2112. Set<String> videoGenresSet = javAllInfo.getVideoGenresSet();
  2113. //List<VideoGenres> videoGenresList = new ArrayList<>();
  2114. for (String s : videoGenresSet) {
  2115. VideoGenres videoGenres = new VideoGenres();
  2116. videoGenres.setName(s);
  2117. videoGenresMapper.insertOrUpdate(videoGenres);
  2118. System.out.println(videoGenres);
  2119. //videoGenresList.add(videoGenres);
  2120. }
  2121. //Map<String, VideoGenres> stringVideoGenresMap = videoGenresList.stream().collect(Collectors.toMap(VideoGenres::getName, Function.identity(), (k1, k2) -> k2));
  2122. // 保存演员
  2123. Map<String, String> videoCastMap = javAllInfo.getVideoCastMap();
  2124. //List<VideoCast> videoCastList = new ArrayList<>();
  2125. for (Map.Entry<String, String> entry : videoCastMap.entrySet()) {
  2126. VideoCast videoCast = new VideoCast();
  2127. videoCast.setName(entry.getKey());
  2128. videoCast.setType(Integer.parseInt(entry.getValue()));
  2129. videoCastMapper.insertOrUpdate(videoCast);
  2130. System.out.println(videoCast);
  2131. //videoCastList.add(videoCast);
  2132. }
  2133. // Map<String, VideoCast> stringVideoCastMap = videoCastList.stream().collect(Collectors.toMap(VideoCast::getName, Function.identity(), (k1, k2) -> k2));
  2134. // 保存影片信息
  2135. List<VideoInfo> videoInfoList = javAllInfo.getVideoInfoList();
  2136. //Map<String, String> videoUrlMap = javAllInfo.getVideoUrlMap();
  2137. //videoInfoList.parallelStream().forEach(e -> {
  2138. // e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
  2139. //});
  2140. //for (VideoInfo videoInfo : videoInfoList) {
  2141. // try {
  2142. // videoInfoMapper.insert(videoInfo);
  2143. // System.out.println("success:" + videoInfo);
  2144. // } catch (Exception e) {
  2145. // e.printStackTrace();
  2146. // System.out.println("error:" + videoInfo);
  2147. // }
  2148. //}
  2149. int videoInfoCount = videoInfoMapper.insertList(videoInfoList);
  2150. System.out.println("videoInfoCount:" + videoInfoCount);
  2151. // 保存影片类别关联信息
  2152. Set<VideoInfoGenres> videoInfoGenresSet = javAllInfo.getVideoInfoGenresSet();
  2153. videoInfoGenresMapper.insertOrUpdate(videoInfoGenresSet);
  2154. // 保存影片类别关联信息
  2155. Set<VideoInfoCast> videoInfoCastSet = javAllInfo.getVideoInfoCastSet();
  2156. videoInfoCastMapper.insertOrUpdate(videoInfoCastSet);
  2157. }
  2158. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  2159. public void saveInfo4Uncensored(JavAllInfo4Uncensored javAllInfo4Uncensored, Integer isDel) {
  2160. // 删除所有
  2161. if (isDel == 1) {
  2162. videoInfoUncensoredMapper.deleteAll();
  2163. }
  2164. List<String> allIcode = videoInfoUncensoredMapper.findAllIcode();
  2165. // 保存影片信息
  2166. List<VideoInfoUncensored> videoInfoUncensoredList = javAllInfo4Uncensored.getVideoInfoUncensoredList();
  2167. int videoInfoUncensoredListBefore = videoInfoUncensoredList.size();
  2168. Map<String, String> videoUrlMap = javAllInfo4Uncensored.getVideoUrlMap();
  2169. Iterator<VideoInfoUncensored> iterator = videoInfoUncensoredList.iterator();
  2170. while (iterator.hasNext()) {
  2171. if (allIcode.contains(iterator.next().getIdentificationCode())) {
  2172. iterator.remove();
  2173. }
  2174. }
  2175. videoInfoUncensoredList.parallelStream().forEach(e -> {
  2176. e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
  2177. });
  2178. System.out.println("videoInfoUncensoredListBefore:" + videoInfoUncensoredListBefore + ",videoInfoUncensoredListAfter:" + videoInfoUncensoredList.size());
  2179. int videoInfoCount = 0;
  2180. if (videoInfoUncensoredList.size() > 0) {
  2181. videoInfoCount = videoInfoUncensoredMapper.insertList(videoInfoUncensoredList);
  2182. }
  2183. System.out.println("videoInfoCount:" + videoInfoCount);
  2184. }
  2185. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  2186. public void saveInfo4Infantry(JavAllInfo4Infantry javAllInfo4Infantry, Integer isDel, String infantryType) {
  2187. // 删除所有
  2188. if (isDel == 1) {
  2189. videoInfoInfantryMapper.deleteAll();
  2190. }
  2191. List<String> allIcode = videoInfoInfantryMapper.findAllIcode(infantryType);
  2192. // 保存影片信息
  2193. List<VideoInfoInfantry> videoInfoInfantryList = javAllInfo4Infantry.getVideoInfoInfantryList();
  2194. int videoInfoInfantryListBefore = videoInfoInfantryList.size();
  2195. Map<String, String> videoUrlMap = javAllInfo4Infantry.getVideoUrlMap();
  2196. Iterator<VideoInfoInfantry> iterator = videoInfoInfantryList.iterator();
  2197. while (iterator.hasNext()) {
  2198. if (allIcode.contains(iterator.next().getIdentificationCode())) {
  2199. iterator.remove();
  2200. }
  2201. }
  2202. videoInfoInfantryList.parallelStream().forEach(e -> {
  2203. e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
  2204. });
  2205. System.out.println("videoInfoInfantryListBefore:" + videoInfoInfantryListBefore + ",videoInfoInfantryListAfter:" + videoInfoInfantryList.size());
  2206. int videoInfoCount = 0;
  2207. if (videoInfoInfantryList.size() > 0) {
  2208. videoInfoCount = videoInfoInfantryMapper.insertList(videoInfoInfantryList);
  2209. }
  2210. System.out.println("videoInfoCount:" + videoInfoCount);
  2211. }
  2212. private List<String> readFromIcodeStream(InputStream inputStream) {
  2213. List<String> list = new ArrayList<>();
  2214. BufferedReader br = null;
  2215. try {
  2216. br = new BufferedReader(new InputStreamReader(inputStream));
  2217. String line;
  2218. while ((line = br.readLine()) != null) {
  2219. if (StringUtils.isNotEmpty(line)) {
  2220. list.add(line.trim().toUpperCase());
  2221. }
  2222. }
  2223. } catch (FileNotFoundException e) {
  2224. e.printStackTrace();
  2225. } catch (IOException e) {
  2226. e.printStackTrace();
  2227. } finally {
  2228. if (br != null) {
  2229. try {
  2230. br.close();
  2231. } catch (IOException e) {
  2232. e.printStackTrace();
  2233. }
  2234. }
  2235. }
  2236. return list.stream().distinct().collect(Collectors.toList());
  2237. }
  2238. }