| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684 |
- package top.lvzhiqiang.service.impl;
- import lombok.extern.slf4j.Slf4j;
- import org.jsoup.Connection;
- import org.jsoup.HttpStatusException;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.scheduling.annotation.Async;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import top.lvzhiqiang.config.WebAppConfig;
- import top.lvzhiqiang.dto.JavAllInfo;
- import top.lvzhiqiang.dto.JavAllInfo4Infantry;
- import top.lvzhiqiang.dto.JavAllInfo4Uncensored;
- import top.lvzhiqiang.entity.*;
- import top.lvzhiqiang.enumeration.ResultCodeEnum;
- import top.lvzhiqiang.exception.BusinessException;
- import top.lvzhiqiang.exception.ParameterException;
- import top.lvzhiqiang.mapper.*;
- import top.lvzhiqiang.service.BgService;
- import top.lvzhiqiang.util.DateUtils;
- import top.lvzhiqiang.util.JsoupUtil;
- import top.lvzhiqiang.util.StringUtils;
- import javax.annotation.Resource;
- import java.io.*;
- import java.lang.reflect.Field;
- import java.math.BigDecimal;
- import java.net.Proxy;
- import java.nio.charset.StandardCharsets;
- import java.time.Instant;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.ZoneOffset;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * Bg ServiceImpl
- *
- * @author lvzhiqiang
- * 2022/4/16 16:10
- */
- @Service
- @Slf4j
- public class BgServiceImpl implements BgService {
- @Resource
- private VideoGenresMapper videoGenresMapper;
- @Resource
- private VideoCastMapper videoCastMapper;
- @Resource
- private VideoInfoCastMapper videoInfoCastMapper;
- @Resource
- private VideoInfoGenresMapper videoInfoGenresMapper;
- @Resource
- private VideoInfoMapper videoInfoMapper;
- @Resource
- private IcodePoolMapper icodePoolMapper;
- @Resource
- private VideoInfoPoolMapper videoInfoPoolMapper;
- @Resource
- private VideoSitePoolMapper videoSitePoolMapper;
- @Resource
- private DicCodeMapper dicCodeMapper;
- @Resource
- private VideoInfoOtherMapper videoInfoOtherMapper;
- @Resource
- private VideoInfoUncensoredMapper videoInfoUncensoredMapper;
- @Resource
- private VideoInfoInfantryMapper videoInfoInfantryMapper;
- @Resource
- private CrawlerLoveFootMapper crawlerLoveFootMapper;
- @Value("${spring.profiles.active}")
- private String env;
- private String ignoreFileTypeSuffix = "";
- /**
- * findDicCode
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findDicCode(String codeDesc, String order) throws IllegalAccessException {
- List<DicCode> dicCodeList = dicCodeMapper.findByCodeDesc(codeDesc, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(dicCodeList.size())).concat("<br/>"));
- for (DicCode dicCode : dicCodeList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = dicCode.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(dicCode)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findIcodePool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findIcodePool(String identificationCode, Integer status, String order, String crudT) throws IllegalAccessException {
- if ("2".equals(crudT)) {
- //更新
- if (StringUtils.isEmpty(identificationCode) || null == status) {
- return "identificationCode和status不能为空";
- }
- icodePoolMapper.updateStatusByCode(identificationCode, status);
- return "success";
- }
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- icodePoolMapper.delByCode(identificationCode);
- return "success";
- }
- List<IcodePool> icodePoolList = icodePoolMapper.findByCodeAndStatus(identificationCode, status, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(icodePoolList.size())).concat("<br/>"));
- for (IcodePool icodePool : icodePoolList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = icodePool.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(icodePool)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoSitePool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findVideoSitePool(String url, String order) throws IllegalAccessException {
- List<VideoSitePool> videoSitePoolList = videoSitePoolMapper.findByUrl(url, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoSitePoolList.size())).concat("<br/>"));
- for (VideoSitePool videoSitePool : videoSitePoolList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = videoSitePool.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(videoSitePool)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoInfoPool
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findVideoInfoPool(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if ("2".equals(crudT)) {
- //更新
- if (StringUtils.isEmpty(identificationCode) || null == type) {
- return "identificationCode和type不能为空";
- }
- videoInfoPoolMapper.updateTypeByCode(identificationCode, type);
- return "success";
- }
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- videoInfoPoolMapper.delByCode(identificationCode);
- return "success";
- }
- List<VideoInfoPool> videoInfoPoolList = videoInfoPoolMapper.findByCodeAndType(identificationCode, type, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoPoolList.size())).concat("<br/>"));
- for (VideoInfoPool videoInfoPool : videoInfoPoolList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = videoInfoPool.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(videoInfoPool)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoInfoLoveFoot
- *
- * @author lvzhiqiang
- * 2022/12/34 18:08
- */
- @Override
- public String findVideoInfoLoveFoot(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if ("2".equals(crudT)) {
- //更新
- if (StringUtils.isEmpty(identificationCode) || null == type) {
- return "identificationCode和type不能为空";
- }
- crawlerLoveFootMapper.updateTypeByCode(identificationCode, type);
- return "success";
- }
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- crawlerLoveFootMapper.delByCode(identificationCode);
- return "success";
- }
- List<CrawlerLoveFoot> crawlerLoveFootList = crawlerLoveFootMapper.findByCodeAndType(identificationCode, type, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(crawlerLoveFootList.size())).concat("<br/>"));
- for (CrawlerLoveFoot crawlerLoveFoot : crawlerLoveFootList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = crawlerLoveFoot.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(crawlerLoveFoot)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * findVideoInfo
- *
- * @author lvzhiqiang
- * 2022/5/3 17:37
- */
- @Override
- public String findVideoInfo(String identificationCode, Integer type, String order, String crudT) throws IllegalAccessException {
- if ("3".equals(crudT)) {
- //删除
- if (StringUtils.isEmpty(identificationCode)) {
- return "dentificationCode不能为空";
- }
- videoInfoMapper.delByCode(identificationCode);
- return "success";
- }
- List<VideoInfo> videoInfoList = videoInfoMapper.findByCodeAndType(identificationCode, type, order);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoList.size())).concat("<br/>"));
- for (VideoInfo videoInfo : videoInfoList) {
- sb.append("<table border=\"1\" cellspacing=\"0\"><tr><th>key</th><th>value</th></tr>");
- Field[] fields = videoInfo.getClass().getDeclaredFields();
- for (Field field : fields) {
- field.setAccessible(true);
- sb.append("<tr>");
- sb.append("<td>").append(field.getName()).append("</td>");
- sb.append("<td>").append(field.get(videoInfo)).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- }
- return sb.toString();
- }
- /**
- * updateScoreOrComment
- *
- * @author lvzhiqiang
- * 2022/5/4 9:54
- */
- @Override
- public String insertOrUpdateScoreOrComment(String identificationCode, String score, String comment) {
- BigDecimal scoreBD = null;
- if (StringUtils.isNotEmpty(score)) {
- scoreBD = new BigDecimal(score);
- }
- int num = videoInfoOtherMapper.findByCode(identificationCode);
- if (num == 0) {
- videoInfoOtherMapper.insertScoreOrComment(identificationCode, scoreBD, comment);
- return "insert success";
- }
- videoInfoOtherMapper.updateScoreOrComment(identificationCode, scoreBD, comment);
- return "update success";
- }
- /**
- * Jsoup VideoInfoUncensored
- *
- * @author lvzhiqiang
- * 2022/5/4 19:27
- */
- @Async
- @Override
- public void jsoupVideoInfoUncensored(Integer status) {
- log.warn("jsoupVideoInfoUncensored 开始:status={}", status);
- // 获取待抓取码列表
- List<String> icodeList = videoInfoUncensoredMapper.findIcodeByStatus(status);
- if (icodeList.size() == 0) {
- log.warn("status={}的icodeList为空", status);
- return;
- }
- // 获取javbus防屏蔽地址
- List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
- if (javbusUrlList.size() == 0) {
- log.warn("javbusUrlList为空");
- return;
- }
- // 获取码池图片保存路径
- String liuchuPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- VideoInfoUncensored videoInfoUncensored;
- String javbusUrl;
- int j = 0;
- for (int i = 0; i < icodeList.size(); i++) {
- long start = System.currentTimeMillis();
- String identificationCode = icodeList.get(i);
- int retryCount = 0;
- while (retryCount <= 3) {
- javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
- try {
- document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
- .timeout(50000)
- //.proxy()
- //.data()
- .ignoreContentType(true)
- .userAgent(getUserAgent())
- .header("referer", "https://www.javbus.com/".concat(identificationCode))
- .get();
- videoInfoUncensored = new VideoInfoUncensored();
- videoInfoUncensored.setIdentificationCode(identificationCode);
- parseDocument4Uncensored(document, identificationCode, liuchuPath, videoInfoUncensored);
- videoInfoUncensored.setStatus(2);
- videoInfoUncensoredMapper.updateJsoupInfoByCode(videoInfoUncensored);
- j++;
- log.warn("jsoupVideoInfoUncensored success:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode);
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, e);
- } else if (retryCount == 4) {
- videoInfoUncensoredMapper.updateStatus(identificationCode, 3);
- log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode, e);
- }
- }
- }
- }
- log.warn("jsoupVideoInfoUncensored 统计:total={},success={}", icodeList.size(), j);
- }
- /**
- * Jsoup VideoInfo
- *
- * @author lvzhiqiang
- * 2022/5/5 18:21
- */
- @Async
- @Override
- public void jsoupVideoInfo(Integer status) {
- log.warn("jsoupVideoInfo 开始:status={}", status);
- // 获取待抓取码列表
- List<String> icodeList = videoInfoMapper.findIcodeByStatus(status);
- if (icodeList.size() == 0) {
- log.warn("status={}的icodeList为空", status);
- return;
- }
- // 获取javbus防屏蔽地址
- List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
- if (javbusUrlList.size() == 0) {
- log.warn("javbusUrlList为空");
- return;
- }
- // 获取图片保存路径
- String qibingPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- VideoInfo videoInfo;
- String javbusUrl;
- int j = 0;
- for (int i = 0; i < icodeList.size(); i++) {
- long start = System.currentTimeMillis();
- String identificationCode = icodeList.get(i);
- int retryCount = 0;
- while (retryCount <= 3) {
- javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
- try {
- document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
- .timeout(50000)
- //.proxy()
- //.data()
- .ignoreContentType(true)
- .userAgent(getUserAgent())
- .header("referer", "https://www.javbus.com/".concat(identificationCode))
- .get();
- videoInfo = new VideoInfo();
- videoInfo.setIdentificationCode(identificationCode);
- String picTime = parseDocument4QiBing(document, identificationCode, qibingPath, videoInfo);
- videoInfo.setStatus(2);
- // 获取男优
- getMaleCast(videoInfo);
- videoInfoMapper.updateJsoupInfoByCode(videoInfo);
- videoInfoOtherMapper.insertOrUpdate(identificationCode, 2);
- j++;
- log.warn("jsoupVideoInfo success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupVideoInfo error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
- } else if (retryCount == 4) {
- videoInfoMapper.updateStatus(identificationCode, 3);
- log.error("jsoupVideoInfo error:i={},time={},identificationCode={},javbusUrl={}", i, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
- }
- }
- }
- }
- log.warn("jsoupVideoInfo 统计:total={},success={}", icodeList.size(), j);
- }
- @Override
- public void getMaleCast(VideoInfo videoInfo) {
- Document document;
- try {
- Map<String,String> headerMap = new HashMap<>();
- headerMap.put("referer", "avdanyuwiki.com");
- document = JsoupUtil.requestDocument("https://avdanyuwiki.com/?s=".concat(videoInfo.getName()), JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
- Elements container = document.select("div#header-container-in");
- if (container.size() == 0) {
- return;
- }
- Elements alinks1 = container.select("h4").select("a[rel='bookmark']");
- if (alinks1 == null || alinks1.size() == 0) {
- return;
- }
- String alinkhref = alinks1.first().attr("abs:href");
- document = JsoupUtil.requestDocument(alinkhref, JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
- Elements entrycontent = document.select("div.entry-content");
- if (entrycontent.size() == 0) {
- return;
- }
- String[] entrycontentArr = entrycontent.html().split("<br>");
- for (String s : entrycontentArr) {
- if (s.contains("出演男優")) {
- String[] split = s.split(":");
- if (split.length < 2) {
- return;
- }
- String maleCasts = s.split(":")[1];
- List<String> sssss = new ArrayList<>();
- String[] split1 = maleCasts.split(",");
- for (String s1 : split1) {
- String[] split2 = s1.trim().split("\\s+");
- for (String s2 : split2) {
- sssss.add(s2.replaceAll(" ", "").trim());
- }
- }
- String maleCast = StringUtils.join(sssss, ",");
- videoInfo.setMaleCast(maleCast);
- break;
- }
- }
- } catch (Exception e) {
- log.error("getMaleCast error,icode={},name={}={}", videoInfo.getIdentificationCode(), videoInfo.getName(), e);
- }
- }
- /**
- * 删除影片
- *
- * @param identificationCode
- * @param parentTypeName
- * @author lvzhiqiang
- * 2022/5/29 12:59
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void delVideoInfo(String identificationCode, String parentTypeName, String allFlag) {
- if (StringUtils.isNotEmpty(parentTypeName) && StringUtils.isEmpty(allFlag)) {
- if (parentTypeName.contains("类别")) {
- String videoGenres = parentTypeName.replace("(类别)", "");
- VideoInfoGenres videoInfoGenres = videoInfoGenresMapper.findVideoInfoGenresByCodeAndName(identificationCode, videoGenres);
- if ("1".equals(videoInfoGenres.getType())) {
- // 主体
- throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
- } else {
- // 链接
- videoInfoGenresMapper.deleteById(videoInfoGenres.getId());
- }
- } else if (parentTypeName.contains("优")) {
- String videoCast = "";
- if (parentTypeName.contains("(男")) {
- videoCast = parentTypeName.replace("(男优)", "");
- } else if (parentTypeName.contains("(女")) {
- videoCast = parentTypeName.replace("(女优)", "");
- }
- VideoInfoCast videoInfoCast = videoInfoCastMapper.findVideoInfoCastByCodeAndName(identificationCode, videoCast);
- if ("1".equals(videoInfoCast.getType())) {
- // 主体
- throw new ParameterException("上级类型名称为主体,请选用allFlag参数");
- } else {
- // 链接
- videoInfoCastMapper.deleteById(videoInfoCast.getId());
- }
- } else {
- throw new ParameterException("直属类型不存在");
- }
- } else if (StringUtils.isEmpty(parentTypeName) && StringUtils.isNotEmpty(allFlag)) {
- videoInfoMapper.delByIdentificationCode(identificationCode);
- videoInfoCastMapper.deleteByCode(identificationCode);
- videoInfoGenresMapper.deleteByCode(identificationCode);
- } else {
- throw new ParameterException("参数有误");
- }
- }
- /**
- * findVideoInfoOther
- *
- * @author lvzhiqiang
- * 2022/9/17 19:17
- */
- @Override
- public String findVideoInfoOther(String identificationCode, String resolutionRatio, Integer original, Integer subtitle, Integer recoding, String crudT) {
- if ("2".equals(crudT)) {
- identificationCode = identificationCode.trim();
- // 更新/新增
- int num = videoInfoOtherMapper.findByCode(identificationCode);
- if (num == 0) {
- videoInfoOtherMapper.insertVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
- return "insert success";
- }
- videoInfoOtherMapper.updateVideoInfoOther(identificationCode, resolutionRatio, original, subtitle, recoding);
- return "update success";
- }
- if ("3".equals(crudT)) {
- identificationCode = identificationCode.trim();
- //删除
- videoInfoOtherMapper.delByCode(identificationCode);
- return "delete success";
- }
- // 查询
- List<VideoInfoOther> videoInfoOtherList = videoInfoOtherMapper.findVideoInfoOther4MultipleParams(identificationCode, resolutionRatio, original, subtitle, recoding);
- StringBuffer sb = new StringBuffer("total:".concat(String.valueOf(videoInfoOtherList.size())).concat("<br/>"));
- 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>");
- int i = 0;
- for (VideoInfoOther videoInfoOther : videoInfoOtherList) {
- i++;
- sb.append("<tr>");
- sb.append("<td>").append(i).append("</td>");
- sb.append("<td>").append(videoInfoOther.getIdentificationCode()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getScore()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getComment()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getCommentFirst()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getResolutionRatio()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getOriginal() == null ? "?" : (videoInfoOther.getOriginal() == 1 ? "是" : "否")).append("</td>");
- sb.append("<td>").append(videoInfoOther.getSubtitle() == null ? "?" : (videoInfoOther.getSubtitle() == 1 ? "是" : "否")).append("</td>");
- sb.append("<td>").append(videoInfoOther.getRecoding() == null ? "?" : (videoInfoOther.getRecoding() == 1 ? "是" : "否")).append("</td>");
- sb.append("<td>").append(videoInfoOther.getCreateTime()).append("</td>");
- sb.append("<td>").append(videoInfoOther.getModifyTime()).append("</td>");
- sb.append("</tr>");
- }
- sb.append("</table>");
- return sb.toString();
- }
- /**
- * 增加影片
- *
- * @param identificationCode
- * @param videoName
- * @param parentType
- * @param parentName
- * @param type
- * @author lvzhiqiang
- * 2022/9/27 20:54
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void insertVideoInfo(String identificationCode, String videoName, Integer parentType, String parentName, Integer type) {
- String parentFullName;
- if (parentType == 1) {
- parentFullName = "(类别)" + parentName;
- VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
- videoInfoGenres.setIdentificationCode(identificationCode);
- videoInfoGenres.setName(parentName);
- videoInfoGenres.setType(type);
- videoInfoGenresMapper.insert(videoInfoGenres);
- VideoGenres videoGenres = new VideoGenres();
- videoGenres.setName(parentName);
- videoGenresMapper.insertOrUpdate(videoGenres);
- } else if (parentType == 2) {
- parentFullName = "(男优)" + parentName;
- VideoInfoCast videoInfoCast = new VideoInfoCast();
- videoInfoCast.setIdentificationCode(identificationCode);
- videoInfoCast.setName(parentName);
- videoInfoCast.setType(type);
- videoInfoCastMapper.insert(videoInfoCast);
- VideoCast videoCast = new VideoCast();
- videoCast.setName(parentName);
- videoCast.setType(1);
- videoCastMapper.insertOrUpdate(videoCast);
- } else if (parentType == 3) {
- parentFullName = "(女优)" + parentName;
- VideoInfoCast videoInfoCast = new VideoInfoCast();
- videoInfoCast.setIdentificationCode(identificationCode);
- videoInfoCast.setName(parentName);
- videoInfoCast.setType(type);
- videoInfoCastMapper.insert(videoInfoCast);
- VideoCast videoCast = new VideoCast();
- videoCast.setName(parentName);
- videoCast.setType(2);
- videoCastMapper.insertOrUpdate(videoCast);
- } else {
- throw new RuntimeException("parentType类型错误");
- }
- // 主体
- if (type == 1) {
- VideoInfo videoInfo = new VideoInfo();
- videoInfo.setIdentificationCode(identificationCode);
- videoInfo.setType(1);
- // 视频URL
- videoInfo.setVideoUrl(parentFullName.concat("/").concat(videoName));
- // 修改时间
- videoInfo.setCreateTime(LocalDateTime.now());
- // 主体是谁
- videoInfo.setMainWho(parentFullName);
- videoInfoMapper.insertOrUpdate(videoInfo);
- }
- }
- /**
- * 初始化骑兵数据
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- @Async
- public void initVideoInfoData(Integer type, Integer isDel, String infantryType) {
- long startTime = System.currentTimeMillis();
- DicCode dicCode = null;
- if (type == 1) {
- dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "qibing_path".equals(x.getCodeKey())).findFirst().get();
- } else if (type == 3) {
- dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "liuchu_path".equals(x.getCodeKey())).findFirst().get();
- } else if (type == 2) {
- dicCode = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && "bubing_path".equals(x.getCodeKey())).findFirst().get();
- }
- if (dicCode == null) {
- return;
- }
- String picPath = dicCode.getCodeValue();
- if (type == 1) {
- JavAllInfo javAllInfo = new JavAllInfo();
- // 删除所有
- if (isDel == 1) {
- videoGenresMapper.deleteAll();
- videoInfoMapper.deleteAll();
- videoCastMapper.deleteAll();
- videoInfoGenresMapper.deleteAll();
- videoInfoCastMapper.deleteAll();
- }
- ignoreFileTypeSuffix = dicCodeMapper.findByCodeKey("ignore_filetype_suffix", null).stream()
- .filter(x -> x.getEnv().contains(env)).findFirst().get().getCodeValue();
- List<String> allIcode = videoInfoMapper.findAllIcode();
- getAllFilePaths(picPath, javAllInfo, allIcode);
- saveInfo(javAllInfo, isDel);
- } else if (type == 3) {
- JavAllInfo4Uncensored javAllInfo4Uncensored = new JavAllInfo4Uncensored();
- getAllFilePaths4Uncensored(picPath, javAllInfo4Uncensored);
- saveInfo4Uncensored(javAllInfo4Uncensored, isDel);
- } else if (type == 2) {
- JavAllInfo4Infantry javAllInfo4Infantry = new JavAllInfo4Infantry();
- picPath = picPath.concat(infantryType);
- getAllFilePaths4Infantry(picPath, javAllInfo4Infantry, infantryType);
- saveInfo4Infantry(javAllInfo4Infantry, isDel, infantryType);
- }
- long endTime = System.currentTimeMillis();
- System.err.println((endTime - startTime) / 1000);
- }
- /**
- * 上传识别码文件
- *
- * @param is
- */
- @Override
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- @Async
- public void uploadFile4IdentificationCode(InputStream is, Integer isDel) {
- if (isDel == 1) {
- icodePoolMapper.deleteAll();
- }
- List<String> uploadIcodeList = readFromIcodeStream(is);
- List<String> icodePoolList = icodePoolMapper.findIcode();
- // 过滤库中已存在的
- Integer beforeUploadSize = uploadIcodeList.size();
- uploadIcodeList.removeAll(icodePoolList);
- log.warn("uploadFile4IdentificationCode:beforeUpload={},icodePool={},afterUpload={}", beforeUploadSize, icodePoolList.size(), uploadIcodeList.size());
- // 插入
- int num = 0;
- if (uploadIcodeList.size() > 0) {
- num = icodePoolMapper.insertList(uploadIcodeList);
- }
- log.warn("uploadFile4IdentificationCode:success={}", num);
- }
- /**
- * 单个识别码
- *
- * @param identificationCode
- */
- @Override
- public void single4IdentificationCode(String identificationCode) {
- List<String> icodePoolList = icodePoolMapper.findIcode();
- identificationCode = identificationCode.trim().toUpperCase();
- if (icodePoolList.contains(identificationCode)) {
- throw new BusinessException(ResultCodeEnum.PARAM_DATA_EXIST_ERROR);
- }
- icodePoolMapper.insert(identificationCode);
- }
- /**
- * Jsoup IcodePool
- *
- * @param status
- */
- @Async
- @Override
- public void jsoupIcodePool(Integer status, Integer isDel, Integer ignoreRetryCount) {
- log.warn("jsoupIcodePool 开始:status={},isDel={},ignoreRetryCount={}", status, isDel, ignoreRetryCount);
- if (isDel == 1) {
- videoInfoPoolMapper.deleteAll();
- }
- // 获取待抓取码列表
- List<String> icodePoolList;
- if (1 == ignoreRetryCount) {
- icodePoolList = icodePoolMapper.findIcodeByStatus4IgnoreRetryCount(status);
- } else {
- icodePoolList = icodePoolMapper.findIcodeByStatus(status);
- }
- if (icodePoolList.size() == 0) {
- log.warn("status={}的icodePoolList为空", status);
- return;
- }
- // 获取javbus防屏蔽地址
- List<String> javbusUrlList = videoSitePoolMapper.findUrlByTypeAndDeleteFlag(1, 1);
- if (javbusUrlList.size() == 0) {
- log.warn("javbusUrlList为空");
- return;
- }
- // 获取主表所有识别码
- List<String> allIcode = videoInfoMapper.findAllIcode();
- // 获取码池图片保存路径
- String machiPath = WebAppConfig.dicCodeList.stream().filter(x -> 1 == x.getType() && env.equals(x.getEnv()) && "apics_path".equals(x.getCodeKey())).findFirst().get().getCodeValue();
- // 遍历
- Document document;
- VideoInfoPool videoInfoPool;
- String javbusUrl;
- int j = 0;
- for (int i = 0; i < icodePoolList.size(); i++) {
- long start = System.currentTimeMillis();
- String identificationCode = icodePoolList.get(i);
- IcodePool icodePool = new IcodePool();
- icodePool.setIdentificationCode(identificationCode);
- if (allIcode.contains(identificationCode)) {
- icodePool.setStatus(4);
- icodePool.setRetryCount(0);
- icodePoolMapper.updateStatus(icodePool);
- log.warn("jsoupIcodePool exists:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode);
- continue;
- }
- int retryCount = 0;
- while (retryCount <= 3) {
- javbusUrl = javbusUrlList.get((int) (0 + Math.random() * (javbusUrlList.size())));
- try {
- document = Jsoup.connect(javbusUrl.concat("/").concat(identificationCode))
- .timeout(50000)
- //.proxy()
- //.data()
- .ignoreContentType(true)
- .userAgent(getUserAgent())
- .header("referer", javbusUrl.concat("/").concat(identificationCode))
- .get();
- videoInfoPool = new VideoInfoPool();
- long picTime = parseDocument(document, identificationCode, machiPath, videoInfoPool);
- if (videoInfoPool != null) {
- icodePool.setStatus(2);
- icodePool.setRetryCount(retryCount);
- icodePoolMapper.updateStatus(icodePool);
- videoInfoPoolMapper.insert(videoInfoPool);
- j++;
- }
- log.warn("jsoupIcodePool success:i={},picTime={},time={},identificationCode={}", i, picTime, System.currentTimeMillis() - start, identificationCode);
- break;
- } catch (Exception e) {
- ++retryCount;
- if (retryCount < 4) {
- log.error("jsoupIcodePool error重试:i={},retryCount={},time={},identificationCode={},javbusUrl={}", i, retryCount, System.currentTimeMillis() - start, identificationCode, javbusUrl, e);
- } else if (retryCount == 4) {
- icodePool.setStatus(3);
- icodePool.setRetryCount(retryCount - 1);
- icodePool.setFailureCause(e.getMessage().length() <= 200 ? e.getMessage() : e.getMessage().substring(0, 200));
- icodePoolMapper.updateStatus(icodePool);
- log.error("jsoupIcodePool error:i={},time={},identificationCode={}", i, System.currentTimeMillis() - start, identificationCode, e);
- }
- }
- }
- }
- log.warn("jsoupIcodePool 统计:total={},success={}", icodePoolList.size(), j);
- }
- private String getUserAgent() {
- Random r = new Random();
- String[] ua = {"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0",
- "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",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36",
- "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",
- "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko",
- "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)",
- "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
- "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)",
- "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",
- "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",
- "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",
- "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",
- "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 TheWorld 7",
- "Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/60.0",
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"};
- int i = r.nextInt(15);
- return ua[i];
- }
- private long parseDocument(Document document, String identificationCode, String machiPath, VideoInfoPool videoInfoPool) throws Exception {
- Elements container = document.select("div.container");
- if (container.size() == 0) {
- throw new Exception("番号无效!");
- }
- // 名称
- String h3 = container.select("h3").first().text().replace("/", "");
- String[] nameArr = h3.split("\\s+");
- if (nameArr.length > 1) {
- videoInfoPool.setName(h3.substring(nameArr[0].length()).trim());
- } else {
- videoInfoPool.setName(nameArr[0]);
- }
- Elements pEles = container.select("div.info > p");
- // 识别码
- Element pEle = pEles.get(0);
- String iCode = pEle.select("span[style]").first().text();
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- videoInfoPool.setIdentificationCode(iCode);
- // 发行日期
- pEle = pEles.get(1);
- String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfoPool.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- pEle = pEles.get(2);
- String length = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfoPool.setLength(length);
- // 导演
- Elements directorEles = container.select("div.info").select("p:contains(導演)");
- if (directorEles.size() > 0) {
- pEle = directorEles.first().select("a[href]").first();
- videoInfoPool.setDirector(pEle.text());
- }
- // 制作商
- Elements markerEles = container.select("div.info").select("p:contains(製作商)");
- if (markerEles.size() > 0) {
- pEle = markerEles.first().select("a[href]").first();
- videoInfoPool.setMaker(pEle.text());
- }
- // 发行商
- Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
- if (issuerEles.size() > 0) {
- pEle = issuerEles.first().select("a[href]").first();
- videoInfoPool.setIssuer(pEle.text());
- }
- // 类别
- Elements genresEles = container.select("div.info").select("p:contains(類別)");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoPool.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
- if (castEles.size() > 0) {
- Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
- if (castElesTemp.size() == 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoPool.setCast(sb.toString());
- }
- }
- // 图片URL
- String href = container.select("a.bigImage").first().attr("abs:href");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- String machiImgUrl = "码池/".concat(fileName);
- saveFile(response.bodyStream(), machiPath.concat(machiImgUrl));
- long end = System.currentTimeMillis();
- videoInfoPool.setImgUrl(machiImgUrl);
- videoInfoPool.setCreateTime(LocalDateTime.now());
- videoInfoPool.setType(1);
- return end - start;
- }
- private void parseDocument4Uncensored(Document document, String identificationCode, String machiPath, VideoInfoUncensored videoInfoUncensored) throws Exception {
- Elements container = document.select("div.container");
- if (container.size() == 0) {
- throw new Exception("番号无效!");
- }
- Elements pEles = container.select("div.info > p");
- // 识别码
- Element pEle = pEles.get(0);
- String iCode = pEle.select("span[style]").first().text();
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- // 长度
- pEle = pEles.get(2);
- String length = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfoUncensored.setLength(length);
- // 导演
- Elements directorEles = container.select("div.info").select("p:contains(導演)");
- if (directorEles.size() > 0) {
- pEle = directorEles.first().select("a[href]").first();
- videoInfoUncensored.setDirector(pEle.text());
- }
- // 制作商
- Elements markerEles = container.select("div.info").select("p:contains(製作商)");
- if (markerEles.size() > 0) {
- pEle = markerEles.first().select("a[href]").first();
- videoInfoUncensored.setMaker(pEle.text());
- }
- // 发行商
- Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
- if (issuerEles.size() > 0) {
- pEle = issuerEles.first().select("a[href]").first();
- videoInfoUncensored.setIssuer(pEle.text());
- }
- // 类别
- Elements genresEles = container.select("div.info").select("p:contains(類別)");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoUncensored.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
- if (castEles.size() > 0) {
- Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
- if (castElesTemp.size() == 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfoUncensored.setCast(sb.toString());
- }
- }
- }
- private String parseDocument4QiBing(Document document, String identificationCode, String qibingPath, VideoInfo videoInfo) throws Exception {
- Elements container = document.select("div.container");
- if (container.size() == 0) {
- throw new Exception("番号无效!");
- }
- // 名称
- String h3 = container.select("h3").first().text();
- String[] nameArr = h3.split("\\s+");
- if (nameArr.length > 1) {
- videoInfo.setName(h3.substring(nameArr[0].length()).trim());
- } else {
- videoInfo.setName(nameArr[0]);
- }
- Elements pEles = container.select("div.info > p");
- // 识别码
- Element pEle = pEles.get(0);
- String iCode = pEle.select("span[style]").first().text();
- if (!identificationCode.equalsIgnoreCase(iCode)) {
- throw new Exception("番号与站点不一致");
- }
- // 发行日期
- pEle = pEles.get(1);
- String issueDate = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 长度
- pEle = pEles.get(2);
- String length = pEle.text().split(":")[1].replace("\"", "").trim();
- videoInfo.setLength(length);
- // 导演
- Elements directorEles = container.select("div.info").select("p:contains(導演)");
- if (directorEles.size() > 0) {
- pEle = directorEles.first().select("a[href]").first();
- videoInfo.setDirector(pEle.text());
- }
- // 制作商
- Elements markerEles = container.select("div.info").select("p:contains(製作商)");
- if (markerEles.size() > 0) {
- pEle = markerEles.first().select("a[href]").first();
- videoInfo.setMaker(pEle.text());
- }
- // 发行商
- Elements issuerEles = container.select("div.info").select("p:contains(發行商)");
- if (issuerEles.size() > 0) {
- pEle = issuerEles.first().select("a[href]").first();
- videoInfo.setIssuer(pEle.text());
- }
- // 类别
- Elements genresEles = container.select("div.info").select("p:contains(類別)");
- if (genresEles.size() > 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = genresEles.first().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfo.setGenres(sb.toString());
- }
- // 演员
- Elements castEles = container.select("div.info").select("p.star-show:contains(演員)");
- if (castEles.size() > 0) {
- Elements castElesTemp = container.select("div.info:contains(暫無出演者資訊)");
- if (castElesTemp.size() == 0) {
- StringBuffer sb = new StringBuffer();
- Elements ahrefEles = castEles.first().nextElementSibling().nextElementSibling().select("a[href]");
- for (Element ahrefEle : ahrefEles) {
- sb.append(ahrefEle.text()).append(",");
- }
- if (sb.length() > 0) {
- sb = sb.deleteCharAt(sb.length() - 1);
- }
- videoInfo.setCast(sb.toString());
- }
- }
- // 图片 骑兵步兵
- String qibings = "骑兵步兵/".concat(iCode);
- StringBuffer picTime = new StringBuffer("{cover:");
- // 图片URL bigImage
- String qibingCover = qibings.concat("/cover/");
- String fileName = issueDate.concat(" ").concat(h3).replace("?", "?");
- byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
- if (imgUrlBytes.length > 251) {
- byte[] imgUrlDestBytes = new byte[251];
- System.arraycopy(imgUrlBytes, 0, imgUrlDestBytes, 0, 251);
- fileName = new String(imgUrlDestBytes, StandardCharsets.UTF_8).replace("�", "");
- }
- fileName = fileName.concat(".jpg");
- if (!new File(qibingPath.concat(qibingCover), fileName).exists()) {
- String href = container.select("a.bigImage").first().attr("abs:href");
- long start = System.currentTimeMillis();
- Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
- picTime.append(System.currentTimeMillis() - start).append(",");
- }
- videoInfo.setImgUrl(qibingCover.concat(fileName));
- // 图片URL img_gf
- String qibingImgGF = qibings.concat("/img_gf/");
- File qibingImgGFFile = new File(qibingPath.concat(qibingImgGF));
- if (!qibingImgGFFile.exists() || qibingImgGFFile.listFiles().length == 0) {
- Elements sampleBoxEles = container.select("div#sample-waterfall").select("a");
- long start2 = System.currentTimeMillis();
- if (sampleBoxEles.size() > 0) {
- Connection.Response responseImg;
- for (Element sampleBoxEle : sampleBoxEles) {
- String sampleBoxHref = sampleBoxEle.attr("href");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.attr("abs:href");
- }
- try {
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- } catch (HttpStatusException e) {
- sampleBoxHref = sampleBoxEle.select("img").attr("src");
- if (!sampleBoxHref.contains("http")) {
- sampleBoxHref = sampleBoxEle.select("img").attr("abs:src");
- }
- responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
- }
- String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
- saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
- }
- } else {
- log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
- }
- picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
- }
- return picTime.toString();
- }
- /**
- * 保存文件到本地2
- *
- * @param bufferedInputStream
- * @param savePathPrex
- * @param fileName
- */
- private void saveFile2(BufferedInputStream bufferedInputStream, String savePathPrex, String fileName) throws IOException {
- File savePathPrexFile = new File(savePathPrex);
- // 判断目录是否存在,如果不存在则新建
- if (!savePathPrexFile.exists()) {
- boolean result = savePathPrexFile.mkdirs();
- if (!result) {
- throw new IOException("创建目录失败!");
- }
- }
- //一次最多读取1k
- byte[] buffer = new byte[1024];
- //实际读取的长度
- int readLenghth;
- //创建的一个写出的缓冲流
- BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePathPrexFile, fileName)));
- //文件逐步写入本地
- while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
- bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
- }
- //关闭缓冲流
- bufferedOutputStream.close();
- bufferedInputStream.close();
- }
- /**
- * 保存文件到本地
- *
- * @param bufferedInputStream
- * @param savePath
- */
- private void saveFile(BufferedInputStream bufferedInputStream, String savePath) throws IOException {
- //一次最多读取1k
- byte[] buffer = new byte[1024];
- //实际读取的长度
- int readLenghth;
- //创建的一个写出的缓冲流
- BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savePath)));
- //文件逐步写入本地
- while ((readLenghth = bufferedInputStream.read(buffer, 0, 1024)) != -1) {//先读出来,保存在buffer数组中
- bufferedOutputStream.write(buffer, 0, readLenghth);//再从buffer中取出来保存到本地
- }
- //关闭缓冲流
- bufferedOutputStream.close();
- bufferedInputStream.close();
- }
- // 递归获取某目录下的所有子目录以及子文件
- private void getAllFilePaths(String filePath, JavAllInfo javAllInfo, List<String> allIcode) {
- File[] files = new File(filePath).listFiles();
- if (files == null) {
- return;
- }
- int type = 0;
- if (filePath.contains("骑兵")) {
- type = 1;
- } else if (filePath.contains("步兵")) {
- type = 2;
- }
- Set<String> sameNameSet = new HashSet<>();
- for (File file : files) {
- if (file.isDirectory()) {
- // 文件夹
- getAllFilePaths(file.getAbsolutePath(), javAllInfo, allIcode);
- } else {
- String fileName = file.getName();
- String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
- if (!ignoreFileTypeSuffix.contains(fileSuffix)) {
- String parentName = file.getParentFile().getName();
- // 识别码
- String name = fileName.substring(10, fileName.lastIndexOf(".")).trim();
- String[] nameArr = name.split("\\s+");
- try {
- boolean isMain = false;
- if (!fileName.endsWith(".lnk")) {
- if (allIcode.contains(nameArr[0]) || sameNameSet.contains(nameArr[0])) {
- continue;
- }
- isMain = true;
- // 获取正片信息
- VideoInfo videoInfo = new VideoInfo();
- // 发行日期
- //String issueDate = fileName.substring(0, 10);
- //videoInfo.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- // 识别码
- videoInfo.setIdentificationCode(nameArr[0]);
- // 名称
- //if (nameArr.length > 1) {
- // videoInfo.setName(name.substring(nameArr[0].length()).trim());
- //} else {
- // videoInfo.setName(nameArr[0]);
- //}
- // 类型
- videoInfo.setType(type);
- // 图片URL
- //videoInfo.setImgUrl(parentName.concat("/").concat(fileName));
- // 视频URL
- videoInfo.setVideoUrl(parentName.concat("/").concat(fileName));
- // 创建时间 TODO
- // 修改时间
- videoInfo.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
- // 主体是谁
- videoInfo.setMainWho(parentName);
- javAllInfo.getVideoInfoList().add(videoInfo);
- sameNameSet.add(nameArr[0]);
- }
- if (parentName.contains("类别")) {
- // 获取类别
- String videoGenres = parentName.replace("(类别)", "");
- javAllInfo.getVideoGenresSet().add(videoGenres);
- VideoInfoGenres videoInfoGenres = new VideoInfoGenres();
- videoInfoGenres.setIdentificationCode(nameArr[0]);
- videoInfoGenres.setName(videoGenres);
- videoInfoGenres.setType(isMain ? 1 : 2);
- javAllInfo.getVideoInfoGenresSet().add(videoInfoGenres);
- } else if (parentName.contains("优)")) {
- // 获取演员
- String videoCast = "";
- if (parentName.contains("(男")) {
- videoCast = parentName.replace("(男优)", "");
- javAllInfo.getVideoCastMap().put(videoCast, "1");
- } else if (parentName.contains("(女")) {
- videoCast = parentName.replace("(女优)", "");
- javAllInfo.getVideoCastMap().put(videoCast, "2");
- }
- VideoInfoCast videoInfoCast = new VideoInfoCast();
- videoInfoCast.setIdentificationCode(nameArr[0]);
- videoInfoCast.setName(videoCast);
- videoInfoCast.setType(isMain ? 1 : 2);
- javAllInfo.getVideoInfoCastSet().add(videoInfoCast);
- }
- } catch (Exception e) {
- System.err.println("error:" + file.getAbsolutePath());
- System.err.println("error reason:" + e.getMessage());
- }
- } else {
- System.out.println("other type file:" + file.getAbsolutePath());
- }
- }
- }
- }
- private void getAllFilePaths4Uncensored(String filePath, JavAllInfo4Uncensored javAllInfo4Uncensored) {
- File[] files = new File(filePath).listFiles();
- if (files == null) {
- return;
- }
- for (File file : files) {
- if (file.isDirectory()) {
- // 文件夹
- getAllFilePaths4Uncensored(file.getAbsolutePath(), javAllInfo4Uncensored);
- } else {
- String fileName = file.getName();
- if (fileName.endsWith(".jpg")) {
- String parentName = file.getParentFile().getName();
- // 识别码
- String name = fileName.substring(10).replace(".jpg", "").trim();
- String[] nameArr = name.split("\\s+");
- try {
- // 获取正片信息
- VideoInfoUncensored videoInfoUncensored = new VideoInfoUncensored();
- // 发行日期
- String issueDate = fileName.substring(0, 10);
- videoInfoUncensored.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- videoInfoUncensored.setIdentificationCode(nameArr[0]);
- // 名称
- if (nameArr.length > 1) {
- videoInfoUncensored.setName(name.substring(nameArr[0].length()).trim());
- } else {
- videoInfoUncensored.setName(nameArr[0]);
- }
- // 类型
- videoInfoUncensored.setStatus(1);
- // 图片URL
- videoInfoUncensored.setImgUrl(parentName.concat("/").concat(fileName));
- // 创建时间 TODO
- // 修改时间
- videoInfoUncensored.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
- // 主体是谁
- videoInfoUncensored.setMainWho(parentName);
- javAllInfo4Uncensored.getVideoInfoUncensoredList().add(videoInfoUncensored);
- System.out.println("success:" + file.getAbsolutePath());
- } catch (Exception e) {
- System.err.println("error:" + file.getAbsolutePath());
- System.err.println("error reason:" + e.getMessage());
- }
- } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt")) {
- String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
- String parentName = file.getParentFile().getName();
- javAllInfo4Uncensored.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
- }
- }
- }
- }
- private void getAllFilePaths4Infantry(String filePath, JavAllInfo4Infantry javAllInfo4Infantry, String infantryType) {
- File[] files = new File(filePath).listFiles();
- if (files == null) {
- return;
- }
- for (File file : files) {
- if (file.isDirectory()) {
- // 文件夹
- getAllFilePaths4Infantry(file.getAbsolutePath(), javAllInfo4Infantry, infantryType);
- } else {
- String fileName = file.getName();
- if (fileName.endsWith(".jpg")) {
- String parentName = file.getParentFile().getName();
- // 识别码
- String name = fileName.substring(10).replace(".jpg", "").trim();
- String[] nameArr = name.split("\\s+");
- try {
- // 获取正片信息
- VideoInfoInfantry videoInfoInfantry = new VideoInfoInfantry();
- // 发行日期
- String issueDate = fileName.substring(0, 10);
- videoInfoInfantry.setIssueDate(LocalDate.parse(issueDate, DateUtils.dateFormatter));
- videoInfoInfantry.setIdentificationCode(nameArr[0]);
- // 名称
- if (nameArr.length > 1) {
- videoInfoInfantry.setName(name.substring(nameArr[0].length()).trim());
- } else {
- videoInfoInfantry.setName(nameArr[0]);
- }
- // 状态
- videoInfoInfantry.setStatus(1);
- // 类型
- videoInfoInfantry.setType(infantryType);
- // 图片URL
- videoInfoInfantry.setImgUrl(parentName.concat("/").concat(fileName));
- // 创建时间 TODO
- // 修改时间
- videoInfoInfantry.setCreateTime(Instant.ofEpochMilli(file.lastModified()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime());
- // 主体是谁
- videoInfoInfantry.setMainWho(parentName);
- javAllInfo4Infantry.getVideoInfoInfantryList().add(videoInfoInfantry);
- System.out.println("success:" + file.getAbsolutePath());
- } catch (Exception e) {
- System.err.println("error:" + file.getAbsolutePath());
- System.err.println("error reason:" + e.getMessage());
- }
- } else if (!fileName.endsWith(".jpg") && !fileName.endsWith(".srt") && !fileName.endsWith(".txt")) {
- String[] nameArr = fileName.substring(0, fileName.lastIndexOf(".")).split("\\s+");
- String parentName = file.getParentFile().getName();
- javAllInfo4Infantry.getVideoUrlMap().put(nameArr[1], parentName.concat("/").concat(fileName));
- }
- }
- }
- }
- // 保存所有文件
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void saveInfo(JavAllInfo javAllInfo, Integer isDel) {
- // 保存分类
- Set<String> videoGenresSet = javAllInfo.getVideoGenresSet();
- //List<VideoGenres> videoGenresList = new ArrayList<>();
- for (String s : videoGenresSet) {
- VideoGenres videoGenres = new VideoGenres();
- videoGenres.setName(s);
- videoGenresMapper.insertOrUpdate(videoGenres);
- System.out.println(videoGenres);
- //videoGenresList.add(videoGenres);
- }
- //Map<String, VideoGenres> stringVideoGenresMap = videoGenresList.stream().collect(Collectors.toMap(VideoGenres::getName, Function.identity(), (k1, k2) -> k2));
- // 保存演员
- Map<String, String> videoCastMap = javAllInfo.getVideoCastMap();
- //List<VideoCast> videoCastList = new ArrayList<>();
- for (Map.Entry<String, String> entry : videoCastMap.entrySet()) {
- VideoCast videoCast = new VideoCast();
- videoCast.setName(entry.getKey());
- videoCast.setType(Integer.parseInt(entry.getValue()));
- videoCastMapper.insertOrUpdate(videoCast);
- System.out.println(videoCast);
- //videoCastList.add(videoCast);
- }
- // Map<String, VideoCast> stringVideoCastMap = videoCastList.stream().collect(Collectors.toMap(VideoCast::getName, Function.identity(), (k1, k2) -> k2));
- // 保存影片信息
- List<VideoInfo> videoInfoList = javAllInfo.getVideoInfoList();
- //Map<String, String> videoUrlMap = javAllInfo.getVideoUrlMap();
- //videoInfoList.parallelStream().forEach(e -> {
- // e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
- //});
- //for (VideoInfo videoInfo : videoInfoList) {
- // try {
- // videoInfoMapper.insert(videoInfo);
- // System.out.println("success:" + videoInfo);
- // } catch (Exception e) {
- // e.printStackTrace();
- // System.out.println("error:" + videoInfo);
- // }
- //}
- int videoInfoCount = videoInfoMapper.insertList(videoInfoList);
- System.out.println("videoInfoCount:" + videoInfoCount);
- // 保存影片类别关联信息
- Set<VideoInfoGenres> videoInfoGenresSet = javAllInfo.getVideoInfoGenresSet();
- videoInfoGenresMapper.insertOrUpdate(videoInfoGenresSet);
- // 保存影片类别关联信息
- Set<VideoInfoCast> videoInfoCastSet = javAllInfo.getVideoInfoCastSet();
- videoInfoCastMapper.insertOrUpdate(videoInfoCastSet);
- }
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void saveInfo4Uncensored(JavAllInfo4Uncensored javAllInfo4Uncensored, Integer isDel) {
- // 删除所有
- if (isDel == 1) {
- videoInfoUncensoredMapper.deleteAll();
- }
- List<String> allIcode = videoInfoUncensoredMapper.findAllIcode();
- // 保存影片信息
- List<VideoInfoUncensored> videoInfoUncensoredList = javAllInfo4Uncensored.getVideoInfoUncensoredList();
- int videoInfoUncensoredListBefore = videoInfoUncensoredList.size();
- Map<String, String> videoUrlMap = javAllInfo4Uncensored.getVideoUrlMap();
- Iterator<VideoInfoUncensored> iterator = videoInfoUncensoredList.iterator();
- while (iterator.hasNext()) {
- if (allIcode.contains(iterator.next().getIdentificationCode())) {
- iterator.remove();
- }
- }
- videoInfoUncensoredList.parallelStream().forEach(e -> {
- e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
- });
- System.out.println("videoInfoUncensoredListBefore:" + videoInfoUncensoredListBefore + ",videoInfoUncensoredListAfter:" + videoInfoUncensoredList.size());
- int videoInfoCount = 0;
- if (videoInfoUncensoredList.size() > 0) {
- videoInfoCount = videoInfoUncensoredMapper.insertList(videoInfoUncensoredList);
- }
- System.out.println("videoInfoCount:" + videoInfoCount);
- }
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
- public void saveInfo4Infantry(JavAllInfo4Infantry javAllInfo4Infantry, Integer isDel, String infantryType) {
- // 删除所有
- if (isDel == 1) {
- videoInfoInfantryMapper.deleteAll();
- }
- List<String> allIcode = videoInfoInfantryMapper.findAllIcode(infantryType);
- // 保存影片信息
- List<VideoInfoInfantry> videoInfoInfantryList = javAllInfo4Infantry.getVideoInfoInfantryList();
- int videoInfoInfantryListBefore = videoInfoInfantryList.size();
- Map<String, String> videoUrlMap = javAllInfo4Infantry.getVideoUrlMap();
- Iterator<VideoInfoInfantry> iterator = videoInfoInfantryList.iterator();
- while (iterator.hasNext()) {
- if (allIcode.contains(iterator.next().getIdentificationCode())) {
- iterator.remove();
- }
- }
- videoInfoInfantryList.parallelStream().forEach(e -> {
- e.setVideoUrl(videoUrlMap.get(e.getIdentificationCode()));
- });
- System.out.println("videoInfoInfantryListBefore:" + videoInfoInfantryListBefore + ",videoInfoInfantryListAfter:" + videoInfoInfantryList.size());
- int videoInfoCount = 0;
- if (videoInfoInfantryList.size() > 0) {
- videoInfoCount = videoInfoInfantryMapper.insertList(videoInfoInfantryList);
- }
- System.out.println("videoInfoCount:" + videoInfoCount);
- }
- private List<String> readFromIcodeStream(InputStream inputStream) {
- List<String> list = new ArrayList<>();
- BufferedReader br = null;
- try {
- br = new BufferedReader(new InputStreamReader(inputStream));
- String line;
- while ((line = br.readLine()) != null) {
- if (StringUtils.isNotEmpty(line)) {
- list.add(line.trim().toUpperCase());
- }
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (br != null) {
- try {
- br.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return list.stream().distinct().collect(Collectors.toList());
- }
- }
|